✔ ' . esc_html( $pass_text ) . '' : '✘ ' . esc_html( $fail_text ) . ''; } /** * Run Diagnostics Suite (Cached briefly to prevent admin load lag) */ private function run_diagnostics() { $diagnostics = get_transient( 'af_system_deep_diagnostics' ); if ( false === $diagnostics ) { global $wpdb; // 1. Loopback Request Check $loopback_response = wp_remote_get( site_url( 'wp-cron.php' ), array( 'timeout' => 5, 'sslverify' => apply_filters( 'https_local_ssl_verify', false ), ) ); $loopup_code = is_wp_error( $loopback_response ) ? 0 : wp_remote_retrieve_response_code( $loopback_response ); $loopback_ok = ( $loopup_code >= 200 && $loopup_code < 400 ); // 2. REST API Check $rest_response = wp_remote_get( rest_url( 'wp/v2/types' ), array( 'timeout' => 5 ) ); $rest_code = is_wp_error( $rest_response ) ? 0 : wp_remote_retrieve_response_code( $rest_response ); $rest_ok = ( $rest_code === 200 ); // 3. PHP Extensions Audit $required_extensions = array( 'curl', 'gd', 'mbstring', 'xml', 'zip', 'openssl' ); $missing_extensions = array(); foreach ( $required_extensions as $ext ) { if ( ! extension_loaded( $ext ) ) { $missing_extensions[] = $ext; } } // 4. Cron Health & Missed Schedules $cron_jobs = _get_cron_array(); $missed_cron = false; $current_time = time(); if ( ! empty( $cron_jobs ) && is_array( $cron_jobs ) ) { foreach ( $cron_jobs as $timestamp => $cronhooks ) { if ( $timestamp < ( $current_time - 900 ) ) { // Overdue by > 15 mins $missed_cron = true; break; } } } // 5. Database Engine & MyISAM Check $myisam_tables = $wpdb->get_col( $wpdb->prepare( "SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA = %s AND ENGINE = 'MyISAM'", DB_NAME ) ); $diagnostics = array( 'loopback_ok' => $loopback_ok, 'loopback_code' => $loopup_code, 'rest_ok' => $rest_ok, 'rest_code' => $rest_code, 'missing_extensions' => $missing_extensions, 'missed_cron' => $missed_cron, 'myisam_tables' => is_array( $myisam_tables ) ? $myisam_tables : array(), ); set_transient( 'af_system_deep_diagnostics', $diagnostics, 1 * HOUR_IN_SECONDS ); } return $diagnostics; } private function get_cached_db_stats() { $stats = get_transient( 'af_system_db_stats' ); if ( false === $stats ) { global $wpdb; $autoload = $wpdb->get_var( "SELECT SUM(LENGTH(option_value)) FROM {$wpdb->options} WHERE autoload = 'yes'" ); $autoload_kb = round( (float) $autoload / 1024, 2 ); $tables = $wpdb->get_results( $wpdb->prepare( "SELECT (data_length + index_length) as size, data_free FROM information_schema.tables WHERE table_schema = %s", DB_NAME ), ARRAY_A ); $total_bytes = 0; $overhead_bytes = 0; if ( ! empty( $tables ) && ! is_wp_error( $tables ) ) { foreach ( $tables as $table ) { $total_bytes += (float) ( $table['size'] ?? 0 ); $overhead_bytes += (float) ( $table['data_free'] ?? 0 ); } } $stats = array( 'autoload_kb' => $autoload_kb, 'total_formatted' => ( $total_bytes < 1048576 ) ? round( $total_bytes / 1024, 2 ) . ' KB' : round( $total_bytes / 1048576, 2 ) . ' MB', 'overhead_formatted' => ( $overhead_bytes < 1048576 ) ? round( $overhead_bytes / 1024, 2 ) . ' KB' : round( $overhead_bytes / 1048576, 2 ) . ' MB', 'overhead_raw' => round( $overhead_bytes / 1048576, 2 ), 'db_version' => $wpdb->db_version(), ); set_transient( 'af_system_db_stats', $stats, 12 * HOUR_IN_SECONDS ); } return $stats; } public function handle_myisam_conversion() { if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wpnonce'] ) ), 'af_convert_myisam_nonce' ) ) { wp_die( esc_html__( 'Security check failed.', 'af-companion' ) ); } if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'Permission denied.', 'af-companion' ) ); } global $wpdb; $myisam_tables = $wpdb->get_col( $wpdb->prepare( "SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA = %s AND ENGINE = 'MyISAM'", DB_NAME ) ); if ( ! empty( $myisam_tables ) ) { foreach ( $myisam_tables as $table ) { // Sanitize table name since table names cannot be prepared as parameters in SQL $safe_table = preg_replace( '/[^a-zA-Z0-9_$]/', '', $table ); $wpdb->query( "ALTER TABLE `{$safe_table}` ENGINE=InnoDB" ); } delete_transient( 'af_system_deep_diagnostics' ); } wp_safe_redirect( admin_url( 'admin.php?page=af-status&converted=true' ) ); exit; } public function render_page() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'af-companion' ) ); } $db_stats = $this->get_cached_db_stats(); $diagnostics = $this->run_diagnostics(); $db_stats = wp_parse_args( $db_stats, array( 'autoload_kb' => 0, 'total_formatted' => '0 MB', 'overhead_formatted' => '0 MB', 'overhead_raw' => 0, 'db_version' => 'Unknown' ) ); $mem_limit = ini_get( 'memory_limit' ); $execution_time = ini_get( 'max_execution_time' ); $opcache_enabled = function_exists( 'opcache_get_status' ) && @opcache_get_status(); $object_cache = wp_using_ext_object_cache(); $upload_max = ini_get( 'upload_max_filesize' ); $post_max = ini_get( 'post_max_size' ); ?>

  • get_status_label( $object_cache ); ?>
  • get_status_label( $opcache_enabled ); ?>
  • get_status_label( wp_convert_hr_to_bytes( $mem_limit ) >= 268435456 ); ?>
  • s get_status_label( (int) $execution_time >= 60 ); ?>

  • get_status_label( $diagnostics['loopback_ok'] ); ?>
  • get_status_label( $diagnostics['rest_ok'] ); ?>
  • ' . esc_html__( 'Delayed Jobs', 'af-companion' ) . '' : esc_html__( 'Healthy', 'af-companion' ); ?> get_status_label( ! $diagnostics['missed_cron'] ); ?>
  • get_status_label( is_ssl() ); ?>

  • ✔ ✘

  • KB get_status_label( ( $db_stats['autoload_kb'] < 800 ) ); ?>
  • get_status_label( ( $db_stats['overhead_raw'] < 5 ) ); ?>
  • ✔ InnoDB