lity, $this->slug, array( $this, 'options_page' ) ); // For pages that can deal with run requests, let's make sure they actually do that early enough. if ( is_callable( array( $this, 'process_run_action' ) ) ) { add_action( 'load-' . $this->smartcrawl_page_hook, array( $this, 'process_run_action' ) ); } add_action( "admin_print_styles-{$this->smartcrawl_page_hook}", array( $this, 'admin_styles' ) ); } /** * Get title. * * @return mixed */ abstract public function get_title(); /** * Check if the current tab (settings page) is allowed for access * * @return bool */ protected function is_current_tab_allowed() { return ! empty( $this->slug ) && self::is_tab_allowed( $this->slug ); } /** * Check if a tab (settings page) is allowed for access * * It can be not allowed for access to site admins * * @param string $tab Tab to check. * * @return bool */ public static function is_tab_allowed( $tab ) { // On single installs, everything is good. if ( ! is_multisite() ) { return true; } // SEO health not supported on sub-sites. if ( self::TAB_HEALTH === $tab ) { return is_main_site(); } // Dashboard shown on all sub-sites. if ( self::TAB_DASHBOARD === $tab ) { return true; } // Check whether the tab is blocked on network level. $allowed = \SmartCrawl\Admin\Settings\Settings::get_blog_tabs(); $allowed = empty( $allowed ) ? array() : $allowed; return in_array( $tab, array_keys( $allowed ), true ) && ! empty( $allowed[ $tab ] ); } /** * Enqueue styles. */ public function admin_styles() { wp_enqueue_style( Assets::APP_CSS ); } /** * Display the admin options page. */ public function options_page() { $this->msg = ''; if ( ! empty( $_GET['updated'] ) || ! empty( $_GET['settings-updated'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended $this->msg = __( 'Settings updated', 'wds' ); if ( function_exists( '\w3tc_pgcache_flush' ) ) { \w3tc_pgcache_flush(); $this->msg .= __( ' & W3 Total Cache Page Cache flushed', 'wds' ); } elseif ( function_exists( '\wp_cache_clear_cache' ) ) { \wp_cache_clear_cache(); $this->msg .= __( ' & WP Super Cache flushed', 'wds' ); } } $errors = get_settings_errors( $this->option_name ); if ( $errors ) { set_transient( 'wds-settings-save-errors', $errors, 3 ); } } /** * Sets up contextual help * * @param string $contextual_help Help. * * @return string */ public function contextual_help( $contextual_help ) { $page = \smartcrawl_get_array_value( $_GET, 'page' ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( ! empty( $page ) && $page === $this->slug && ! empty( $this->contextual_help ) ) { $contextual_help = $this->contextual_help; } return $contextual_help; } /** * Adds body class * * @param string $classes Class that's being processed. * * @return string */ public function add_body_class( $classes ) { $sui_class = \smartcrawl_sui_class(); if ( $this->is_current_screen() && strpos( $classes, $sui_class ) === false ) { $classes .= " {$sui_class} "; $service = Service::get( Service::SERVICE_SITE ); if ( $service->is_member() ) { $classes .= ' wds-is-member'; } } return $classes; } /** * Renders the whole page view by calling `_render` * * As a side-effect, also calls `WDEV_Plugin_Ui::output()` * * @param string $view View file to load. * @param array $args Optional array of arguments to pass to view. * * @return bool */ public function render_page( $view, $args = array() ) { $this->render_view( $view, $args ); return true; } /** * Render settings fields. * * @param string $option_group Option group. * * @return void */ protected function settings_fields( $option_group ) { echo ""; echo ''; wp_nonce_field( "$option_group-options", '_wpnonce', false ); } /** * Populates view defaults with view meta information * * @return array Defaults */ protected function get_view_defaults() { $errors = get_transient( 'wds-settings-save-errors' ); $errors = ! empty( $errors ) ? $errors : array(); $service = Service::get( Service::SERVICE_SITE ); return array( '_view' => array( 'slug' => $this->slug, 'name' => $this->name, 'option_name' => $this->option_name, 'options' => $this->options, 'action_url' => $this->action_url, 'msg' => $this->msg, 'errors' => $errors, 'is_member' => $service->is_member(), ), ); } /** * Checks if the last active tab is stored in the transient and returns its value. If nothing is available then it returns the default value. * * @param string $default_tab Fallback value. * * @return string The last active tab. */ protected function get_active_tab( $default_tab = '' ) { return empty( $_GET['tab'] ) ? $default_tab : sanitize_text_field( wp_unslash( $_GET['tab'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended } /** * Get page Title * * @return string */ public function get_page_title() { return str_replace( 'SmartCrawl', \smartcrawl_get_plugin_title(), $this->page_title ); } }