init(); } return self::$instance; } private function __construct() {} private function init(): void { add_action( 'admin_menu', array( $this, 'register_menu' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) ); add_action( 'admin_post_ssc_real_seo_run_baseline', array( $this, 'handle_run_baseline' ) ); add_action( 'admin_post_ssc_real_seo_request_help', array( $this, 'handle_request_help' ) ); } public function register_menu(): void { add_menu_page( __( '7 Sided Cube Real SEO', '7-sided-cube-real-seo' ), __( '7 Sided Cube Real SEO', '7-sided-cube-real-seo' ), 'manage_options', $this->menu_slug, array( $this, 'render_main_page' ), 'dashicons-chart-area', 58 ); } public function enqueue_assets( string $hook ): void { // Enqueue styles on our plugin screen. Be resilient to different hook names. // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only screen routing. $page = isset( $_GET['page'] ) ? sanitize_key( (string) wp_unslash( $_GET['page'] ) ) : ''; $is_our_hook = ( false !== strpos( (string) $hook, $this->menu_slug ) ); $is_our_page = ( $this->menu_slug === $page ); if ( ! $is_our_hook && ! $is_our_page ) { return; } wp_enqueue_style( "ssc-real-seo-admin", SSC_REAL_SEO_PLUGIN_URL . "assets/css/admin.css", array(), SSC_REAL_SEO_VERSION ); } private function get_active_tab(): string { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only tab selection. $tab = isset( $_GET['tab'] ) ? sanitize_key( (string) wp_unslash( $_GET['tab'] ) ) : 'baseline'; $allowed = array( 'baseline', 'overview', 'request_help' ); return in_array( $tab, $allowed, true ) ? $tab : 'baseline'; } public function render_main_page(): void { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'You do not have permission to access this page.', '7-sided-cube-real-seo' ) ); } $tab = $this->get_active_tab(); $baseline_cache = SSC_Real_SEO_Baseline::get_cached_results(); $last_run = isset( $baseline_cache['ran_at'] ) ? (int) $baseline_cache['ran_at'] : 0; ?>
render_baseline_tab( $baseline_cache, $last_run ); } elseif ( 'request_help' === $tab ) { $this->render_request_help_tab(); } else { $this->render_overview_tab(); } ?>

0 ) { echo esc_html( sprintf( /* translators: %s: time */ __( 'Last run: %s', '7-sided-cube-real-seo' ), date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $last_run ) ) ); } ?>

menu_slug . '&tab=baseline&ssc_notice=invalid_target' ) ); exit; } try { SSC_Real_SEO_Baseline::run_and_cache( $target, ( 1 === $force ) ); } catch ( Throwable $e ) { if ( defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG ) { // error_log( 'SSC Real SEO baseline error: ' . $e->getMessage() ); } set_transient( 'ssc_real_seo_baseline_error', '1', 60 ); } wp_safe_redirect( admin_url( 'admin.php?page=' . $this->menu_slug . '&tab=baseline&ssc_notice=baseline_ran' ) ); exit; } private function render_overview_tab(): void { ?>

menu_slug . '&tab=request_help&ssc_notice=help_error' ) ); exit; } // Rate limit. $key = 'ssc_real_seo_help_rl_'; if ( is_user_logged_in() ) { $key .= 'u' . get_current_user_id(); } else { $remote_addr = isset( $_SERVER['REMOTE_ADDR'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) : ''; $ip = (string) $remote_addr; $key .= 'i' . md5( $ip ); } if ( get_transient( $key ) ) { wp_safe_redirect( admin_url( 'admin.php?page=' . $this->menu_slug . '&tab=request_help&ssc_notice=help_rate_limited' ) ); exit; } set_transient( $key, 1, 120 ); // 2 minutes. if ( '' === $name || '' === $email || ! is_email( $email ) || '' === $website || '' === $msg || 1 !== $consent ) { wp_safe_redirect( admin_url( 'admin.php?page=' . $this->menu_slug . '&tab=request_help&ssc_notice=help_error' ) ); exit; } $ok = SSC_Real_SEO_Help::send_request_email( array( 'name' => $name, 'email' => $email, 'website' => $website, 'message' => $msg, 'consent' => $consent, ) ); $notice = $ok ? 'help_sent' : 'help_error'; wp_safe_redirect( admin_url( 'admin.php?page=' . $this->menu_slug . '&tab=request_help&ssc_notice=' . $notice ) ); exit; } }