'boolean', 'sanitize_callback' => 'rest_sanitize_boolean', 'default' => true, ) ); register_setting( 'asmith_so_settings', 'asmith_so_lazy_load_exclusions', array( 'type' => 'string', 'sanitize_callback' => 'sanitize_textarea_field', 'default' => '', ) ); register_setting( 'asmith_so_settings', 'asmith_so_minify_html', array( 'type' => 'boolean', 'sanitize_callback' => 'rest_sanitize_boolean', 'default' => false, ) ); register_setting( 'asmith_so_settings', 'asmith_so_defer_js', array( 'type' => 'boolean', 'sanitize_callback' => 'rest_sanitize_boolean', 'default' => false, ) ); register_setting( 'asmith_so_settings', 'asmith_so_defer_js_exclusions', array( 'type' => 'string', 'sanitize_callback' => 'sanitize_text_field', 'default' => '', ) ); // Bloat removal toggles. $bloat_options = array( 'asmith_so_remove_emoji' => true, 'asmith_so_remove_embeds' => true, 'asmith_so_remove_query_strings' => true, 'asmith_so_remove_dashicons' => true, 'asmith_so_remove_xmlrpc' => true, 'asmith_so_remove_rest_links' => true, 'asmith_so_remove_shortlinks' => true, 'asmith_so_remove_wlw' => true, 'asmith_so_remove_rsd' => true, 'asmith_so_remove_rss' => false, ); foreach ( $bloat_options as $option => $default ) { register_setting( 'asmith_so_settings', $option, array( 'type' => 'boolean', 'sanitize_callback' => 'rest_sanitize_boolean', 'default' => $default, ) ); } // Email settings. register_setting( 'asmith_so_settings', 'asmith_so_email_frequency', array( 'type' => 'string', 'sanitize_callback' => 'sanitize_text_field', 'default' => 'weekly', ) ); register_setting( 'asmith_so_settings', 'asmith_so_email_recipients', array( 'type' => 'string', 'sanitize_callback' => 'sanitize_email', 'default' => get_option( 'admin_email' ), ) ); register_setting( 'asmith_so_settings', 'asmith_so_auto_scan', array( 'type' => 'boolean', 'sanitize_callback' => 'rest_sanitize_boolean', 'default' => true, ) ); } /** * Render the main dashboard page. */ public function render_dashboard() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'Unauthorized access.', 'a-smith-speed-optimizer' ) ); } $asmith_so_last_scan = get_option( 'asmith_so_last_scan' ); // First run -- show animated scanning experience. if ( empty( $asmith_so_last_scan ) ) { include ASMITH_SO_PLUGIN_DIR . 'templates/first-scan.php'; return; } $asmith_so_report = Asmith_SO_Performance_Score::instance()->get_score(); if ( empty( $asmith_so_report ) ) { $asmith_so_report = Asmith_SO_Performance_Score::instance()->calculate_score(); } include ASMITH_SO_PLUGIN_DIR . 'templates/dashboard.php'; } /** * Render the settings page. */ public function render_settings() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'Unauthorized access.', 'a-smith-speed-optimizer' ) ); } include ASMITH_SO_PLUGIN_DIR . 'templates/settings.php'; } /** * Register the WP Dashboard widget. */ public function register_dashboard_widget() { wp_add_dashboard_widget( 'asmith_so_speed_widget', __( 'A. Smith Speed Optimizer', 'a-smith-speed-optimizer' ), array( $this, 'render_dashboard_widget' ) ); // Move our widget to the top. global $wp_meta_boxes; if ( isset( $wp_meta_boxes['dashboard']['normal']['core']['asmith_so_speed_widget'] ) ) { $dashboard = $wp_meta_boxes['dashboard']['normal']['core']; $widget = array( 'asmith_so_speed_widget' => $dashboard['asmith_so_speed_widget'] ); unset( $dashboard['asmith_so_speed_widget'] ); $wp_meta_boxes['dashboard']['normal']['core'] = array_merge( $widget, $dashboard ); } } /** * Render the WP Dashboard widget content. */ public function render_dashboard_widget() { $asmith_so_last_scan = get_option( 'asmith_so_last_scan' ); $asmith_so_is_pro = Asmith_SO_Pro_Bridge::is_pro_active(); if ( empty( $asmith_so_last_scan ) ) { ?>

get_score(); if ( empty( $asmith_so_report ) ) { return; } $asmith_so_score = (int) $asmith_so_report['score']; $asmith_so_grade = $asmith_so_report['grade']; $asmith_so_grade_colors = array( 'A' => '#22c55e', 'B' => '#84cc16', 'C' => '#eab308', 'D' => '#f97316', 'F' => '#ef4444', ); $asmith_so_color = $asmith_so_grade_colors[ $asmith_so_grade ] ?? '#64748b'; ?>

PRO →
$asmith_so_option_name, 'value' => (bool) $asmith_so_option_value, ) ); } /** * AJAX: Dismiss an admin notice. */ public function ajax_dismiss_notice() { check_ajax_referer( 'asmith_so_nonce', 'nonce' ); if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error(); } $asmith_so_notice_id = isset( $_POST['notice_id'] ) ? sanitize_text_field( wp_unslash( $_POST['notice_id'] ) ) : ''; if ( $asmith_so_notice_id ) { update_user_meta( get_current_user_id(), 'asmith_so_dismissed_' . $asmith_so_notice_id, true ); } wp_send_json_success(); } /** * AJAX: Clear all cached scan data. */ public function ajax_clear_cache() { check_ajax_referer( 'asmith_so_nonce', 'nonce' ); if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error(); } delete_transient( 'asmith_so_score' ); delete_transient( 'asmith_so_asset_counts' ); delete_option( 'asmith_so_last_scan' ); wp_send_json_success( __( 'Cache cleared. A fresh scan will run on the next dashboard visit.', 'a-smith-speed-optimizer' ) ); } /** * AJAX: Send a test email report. */ public function ajax_test_email() { check_ajax_referer( 'asmith_so_nonce', 'nonce' ); if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error(); } $asmith_so_recipient = get_option( 'asmith_so_email_recipients', get_option( 'admin_email' ) ); $asmith_so_report = Asmith_SO_Performance_Score::instance()->get_score(); if ( empty( $asmith_so_report ) ) { $asmith_so_report = Asmith_SO_Performance_Score::instance()->calculate_score(); } ob_start(); $report = $asmith_so_report; include ASMITH_SO_PLUGIN_DIR . 'templates/email-report.php'; $asmith_so_html = ob_get_clean(); $asmith_so_subject = sprintf( /* translators: %s: site name */ __( '[Speed Optimizer] Speed Report for %s', 'a-smith-speed-optimizer' ), get_bloginfo( 'name' ) ); $asmith_so_headers = array( 'Content-Type: text/html; charset=UTF-8' ); $asmith_so_sent = wp_mail( $asmith_so_recipient, $asmith_so_subject, $asmith_so_html, $asmith_so_headers ); if ( $asmith_so_sent ) { wp_send_json_success( __( 'Test email sent successfully!', 'a-smith-speed-optimizer' ) ); } else { wp_send_json_error( __( 'Failed to send test email. Check your mail configuration.', 'a-smith-speed-optimizer' ) ); } } }