|null */ private static ?array $stats = null; public static function on_load(): void { if ( ! current_user_can( 'manage_options' ) ) { return; } ReportPeriod::maybe_save_from_request(); wp_enqueue_script( 'dashboard' ); wp_enqueue_style( 'dashboard' ); if ( wp_is_mobile() ) { wp_enqueue_script( 'jquery-touch-punch' ); } wp_enqueue_style( 'forwp-seo-admin-settings', FORWP_SEO_HELPER_URL . 'assets/css/admin-settings.css', [], FORWP_SEO_HELPER_VERSION ); wp_enqueue_style( 'forwp-seo-admin-dashboard', FORWP_SEO_HELPER_URL . 'assets/css/admin-dashboard.css', [ 'dashboard', 'forwp-seo-admin-settings' ], FORWP_SEO_HELPER_VERSION ); wp_enqueue_script( 'forwp-seo-admin-tabs', FORWP_SEO_HELPER_URL . 'assets/js/admin-tabs.js', [], FORWP_SEO_HELPER_VERSION, true ); add_filter( 'admin_body_class', [ self::class, 'body_class' ] ); add_filter( 'screen_settings', [ self::class, 'filter_screen_settings' ], 10, 2 ); $screen = get_current_screen(); if ( ! $screen ) { return; } add_meta_box( 'forwp_seo_dash_metrics', __( 'Key metrics', '4wp-seo-helper' ), [ self::class, 'render_metrics_box' ], $screen->id, 'normal', 'high' ); add_meta_box( 'forwp_seo_dash_weakest', __( 'Weakest pages', '4wp-seo-helper' ), [ self::class, 'render_weakest_box' ], $screen->id, 'normal', 'default' ); add_meta_box( 'forwp_seo_dash_queries', __( 'Top queries', '4wp-seo-helper' ), [ self::class, 'render_queries_box' ], $screen->id, 'side', 'high' ); add_meta_box( 'forwp_seo_dash_search', __( 'Search & growth', '4wp-seo-helper' ), [ self::class, 'render_search_box' ], $screen->id, 'side', 'default' ); add_meta_box( 'forwp_seo_dash_gaps', __( 'SEO gaps by field', '4wp-seo-helper' ), [ self::class, 'render_gaps_box' ], $screen->id, 'column3', 'default' ); } /** * @param string $classes Body classes. */ public static function body_class( string $classes ): string { return $classes . ' forwp-seo-dashboard-page'; } /** * @param string $settings Existing extra settings HTML. * @param \WP_Screen $screen Current screen. */ public static function filter_screen_settings( $settings, $screen ): string { if ( ! $screen instanceof \WP_Screen || 'toplevel_page_' . Menu::PAGE_SLUG !== $screen->id ) { return (string) $settings; } $columns = self::layout_columns( $screen ); ob_start(); ?>
' . esc_html__( 'No inventory URLs yet.', '4wp-seo-helper' ) . '
'; return; } ?> $gsc GSC payload from DashboardStats. */ private static function render_queries_pane( array $gsc, string $gsc_url, string $settings_url ): void { $queries = is_array( $gsc['top_queries'] ?? null ) ? $gsc['top_queries'] : []; if ( empty( $gsc['enabled'] ) ) { echo ''; esc_html_e( 'Search Console is turned off.', '4wp-seo-helper' ); echo ' ' . esc_html__( 'Settings', '4wp-seo-helper' ) . ''; echo '
'; return; } if ( empty( $gsc['connected'] ) ) { echo ''; esc_html_e( 'Connect Google and pick a property to load queries.', '4wp-seo-helper' ); echo ' ' . esc_html__( 'GSC settings', '4wp-seo-helper' ) . ''; echo '
'; return; } if ( ! empty( $gsc['needs_sync'] ) || [] === $queries ) { echo ''; esc_html_e( 'No synced query data for this period yet.', '4wp-seo-helper' ); echo ' ' . esc_html__( 'Open Search Console', '4wp-seo-helper' ) . ''; echo '
'; return; } ?>'; esc_html_e( 'Run a Search Console sync to load period totals.', '4wp-seo-helper' ); echo ' ' . esc_html__( 'Open Search Console', '4wp-seo-helper' ) . ''; echo '
'; } ?>