namespace WPForms\Admin\Tools;
const SLUG = 'wpforms-tools';
* @var null|\WPForms\Admin\Tools\Views\View
private $active_view_slug;
if ( ! $this->is_tools_page() ) {
* Check if we're on tools page.
private function is_tools_page() {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$page = isset( $_GET['page'] ) ? sanitize_key( $_GET['page'] ) : '';
// Only load if we are actually on the settings page.
return $page === self::SLUG;
private function init_view() {
$view_ids = array_keys( $this->get_views() );
// Determine the current active settings tab.
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$this->active_view_slug = ! empty( $_GET['view'] ) ? sanitize_key( $_GET['view'] ) : 'import';
// If the user tries to load an invalid view - fallback to the first available.
! in_array( $this->active_view_slug, $view_ids, true ) &&
! has_action( 'wpforms_tools_display_tab_' . $this->active_view_slug )
$this->active_view_slug = reset( $view_ids );
if ( isset( $this->views[ $this->active_view_slug ] ) ) {
$this->view = $this->views[ $this->active_view_slug ];
public function get_views() {
if ( empty( $this->views ) ) {
'import' => new Views\Import(),
'importer' => new Views\Importer(),
'export' => new Views\Export(),
'entry-automation' => new Views\EntryAutomation(),
'system' => new Views\System(),
'action-scheduler' => new Views\ActionScheduler(),
'logs' => new Views\Logs(),
'wpcode' => new Views\CodeSnippets(),
$this->views = apply_filters( 'wpforms_tools_views', $this->views );
static function ( $view ) {
return $view->check_capability();
public function hooks() {
add_action( 'wpforms_admin_page', [ $this, 'output' ] );
do_action( 'wpforms_tools_init' );
* Build the output for the Tools admin page.
public function output() {
<div id="wpforms-tools" class="wrap wpforms-admin-wrap wpforms-tools-tab-<?php echo esc_attr( $this->active_view_slug ); ?>">
if ( $this->view && $this->view->show_nav() ) {
echo '<ul class="wpforms-admin-tabs">';
foreach ( $this->views as $slug => $view ) {
if ( $view->hide_from_nav() || ! $view->check_capability() ) {
'<a href="%1$s" class="%2$s">%3$s</a>',
esc_url( $view->get_link() ),
sanitize_html_class( $this->active_view_slug === $slug ? 'active' : '' ),
esc_html( $view->get_label() )
<h1 class="wpforms-h1-placeholder"></h1>
<div class="wpforms-admin-content wpforms-admin-settings">
do_action( 'wpforms_tools_display_tab_' . $this->active_view_slug );