count( $checks ), 'pass' => $pass, 'fail' => $fail, 'warn' => $warn, 'info' => $info, 'score' => $scored > 0 ? (int) round( ( $pass / $scored ) * 100 ) : 100, ); } // Individual check methods private static function check_wp_version() { global $wp_version; $latest = self::get_latest_wp_version(); if ( $latest && version_compare( $wp_version, $latest, '>=' ) ) { return array( 'status' => 'pass', 'label' => __( 'WordPress is up to date', 'ai-cyberguard' ), 'detail' => sprintf( 'Version %s', $wp_version ), ); } elseif ( $latest && version_compare( $wp_version, $latest, '<' ) ) { return array( 'status' => 'warn', 'label' => __( 'WordPress update available', 'ai-cyberguard' ), 'detail' => sprintf( 'Current: %s, Latest: %s', $wp_version, $latest ), 'action' => admin_url( 'update-core.php' ), 'action_label' => __( 'Update', 'ai-cyberguard' ), ); } return array( 'status' => 'pass', 'label' => __( 'WordPress version', 'ai-cyberguard' ), 'detail' => sprintf( 'Version %s', $wp_version ), ); } private static function check_php_version() { $php_version = phpversion(); $min_recommended = '8.0'; if ( version_compare( $php_version, $min_recommended, '>=' ) ) { return array( 'status' => 'pass', 'label' => __( 'PHP version is secure', 'ai-cyberguard' ), 'detail' => sprintf( 'PHP %s', $php_version ), ); } elseif ( version_compare( $php_version, '7.4', '>=' ) ) { return array( 'status' => 'warn', 'label' => __( 'PHP version should be updated', 'ai-cyberguard' ), 'detail' => sprintf( 'PHP %s (recommended: %s+)', $php_version, $min_recommended ), ); } return array( 'status' => 'fail', 'label' => __( 'PHP version is outdated', 'ai-cyberguard' ), 'detail' => sprintf( 'PHP %s is no longer supported', $php_version ), ); } private static function check_file_editor() { if ( defined( 'DISALLOW_FILE_EDIT' ) && DISALLOW_FILE_EDIT ) { return array( 'status' => 'pass', 'label' => __( 'File editor is disabled', 'ai-cyberguard' ), 'detail' => __( 'DISALLOW_FILE_EDIT is set to true', 'ai-cyberguard' ), ); } return array( 'status' => 'fail', 'label' => __( 'File editor is enabled', 'ai-cyberguard' ), 'detail' => __( 'Add DISALLOW_FILE_EDIT to wp-config.php', 'ai-cyberguard' ), 'action' => '#', 'action_label' => __( 'How to fix', 'ai-cyberguard' ), 'fix_code' => "define( 'DISALLOW_FILE_EDIT', true );", ); } private static function check_debug_mode() { if ( ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ) { return array( 'status' => 'pass', 'label' => __( 'Debug mode is disabled', 'ai-cyberguard' ), 'detail' => __( 'WP_DEBUG is off', 'ai-cyberguard' ), ); } if ( defined( 'WP_DEBUG_DISPLAY' ) && ! WP_DEBUG_DISPLAY ) { return array( 'status' => 'warn', 'label' => __( 'Debug mode is on (hidden)', 'ai-cyberguard' ), 'detail' => __( 'WP_DEBUG is on but display is disabled', 'ai-cyberguard' ), ); } return array( 'status' => 'fail', 'label' => __( 'Debug mode is enabled', 'ai-cyberguard' ), 'detail' => __( 'Never enable WP_DEBUG in production', 'ai-cyberguard' ), ); } private static function check_ssl() { if ( is_ssl() ) { return array( 'status' => 'pass', 'label' => __( 'SSL/HTTPS is active', 'ai-cyberguard' ), 'detail' => __( 'Connection is encrypted', 'ai-cyberguard' ), ); } return array( 'status' => 'fail', 'label' => __( 'SSL/HTTPS is not active', 'ai-cyberguard' ), 'detail' => __( 'Install SSL certificate and force HTTPS', 'ai-cyberguard' ), ); } private static function check_db_prefix() { global $wpdb; if ( $wpdb->prefix !== 'wp_' ) { return array( 'status' => 'pass', 'label' => __( 'Custom database prefix', 'ai-cyberguard' ), 'detail' => sprintf( 'Prefix: %s', $wpdb->prefix ), ); } return array( 'status' => 'warn', 'label' => __( 'Default database prefix (wp_)', 'ai-cyberguard' ), 'detail' => __( 'Consider using a custom prefix for new installations', 'ai-cyberguard' ), ); } private static function check_admin_username() { $admin_user = get_user_by( 'login', 'admin' ); if ( ! $admin_user ) { return array( 'status' => 'pass', 'label' => __( 'No "admin" username', 'ai-cyberguard' ), 'detail' => __( 'Default admin username is not used', 'ai-cyberguard' ), ); } return array( 'status' => 'fail', 'label' => __( '"admin" username exists', 'ai-cyberguard' ), 'detail' => __( 'Change the username or create a new admin account', 'ai-cyberguard' ), 'action' => admin_url( 'user-new.php' ), 'action_label' => __( 'Add User', 'ai-cyberguard' ), ); } private static function check_wpconfig_permissions() { $config_file = ABSPATH . 'wp-config.php'; if ( ! file_exists( $config_file ) ) { $config_file = dirname( ABSPATH ) . '/wp-config.php'; } if ( ! file_exists( $config_file ) ) { return array( 'status' => 'warn', 'label' => __( 'wp-config.php not found', 'ai-cyberguard' ), 'detail' => __( 'Could not locate wp-config.php', 'ai-cyberguard' ), ); } $perms = substr( sprintf( '%o', fileperms( $config_file ) ), -3 ); // FIX (audit 2026-06-10): permission safety is NOT a linear numeric // ordering. The previous `octdec($perms) <= octdec('644')` test wrongly // PASSED world-writable modes whose numeric value happens to be small — // e.g. 0606 (owner rw, OTHER rw) = 390 <= 420, reported "safe" while it is // catastrophic. Inspect the actual group/other bits instead: // - group/other WRITE (& 022) -> fail (anyone can modify wp-config) // - other READ (& 004) -> warn (secrets world-readable) // - otherwise -> pass // NOTE: legacy octal literals (022/004), NOT the PHP 8.1+ 0o022 form — // the plugin supports PHP 7.4, where 0o would be a fatal parse error. $perms_octal = octdec( $perms ); $group_other_writable = ( $perms_octal & 022 ) !== 0; $other_readable = ( $perms_octal & 004 ) !== 0; if ( $group_other_writable ) { return array( 'status' => 'fail', 'label' => __( 'wp-config.php is writable by group/other', 'ai-cyberguard' ), 'detail' => sprintf( /* translators: %s: octal permissions */ __( 'Current: %s — other users on the server can MODIFY wp-config.php. Set it to 0640 or 0600.', 'ai-cyberguard' ), $perms ), ); } if ( $other_readable ) { return array( 'status' => 'warn', 'label' => __( 'wp-config.php is world-readable', 'ai-cyberguard' ), 'detail' => sprintf( /* translators: %s: octal permissions */ __( 'Current: %s — other users on the server can READ your secrets. Prefer 0640 or 0600.', 'ai-cyberguard' ), $perms ), ); } return array( 'status' => 'pass', 'label' => __( 'wp-config.php has safe permissions', 'ai-cyberguard' ), 'detail' => sprintf( 'Permissions: %s', $perms ), ); } /** * Detect the current web server type. * * @return string 'apache', 'nginx', 'iis', or 'unknown' */ private static function detect_server_type() { $software = strtolower( isset( $_SERVER['SERVER_SOFTWARE'] ) ? sanitize_text_field( wp_unslash( $_SERVER['SERVER_SOFTWARE'] ) ) : '' ); if ( function_exists( 'apache_get_modules' ) || strpos( $software, 'apache' ) !== false || strpos( $software, 'litespeed' ) !== false ) { return 'apache'; } if ( strpos( $software, 'nginx' ) !== false ) { return 'nginx'; } if ( strpos( $software, 'microsoft-iis' ) !== false || strpos( $software, 'iis' ) !== false ) { return 'iis'; } return 'unknown'; } private static function check_htaccess() { $server_type = self::detect_server_type(); // Nginx: .htaccess is not used — give Nginx-specific guidance if ( $server_type === 'nginx' ) { return array( 'status' => 'warn', 'label' => __( 'Nginx server detected — manual config required', 'ai-cyberguard' ), 'detail' => __( 'Nginx does not use .htaccess. Add "deny all;" rules to your nginx.conf or site block to protect sensitive directories (e.g. guardpress-data, guardpress-quarantine).', 'ai-cyberguard' ), ); } // IIS: uses web.config instead of .htaccess if ( $server_type === 'iis' ) { $web_config = ABSPATH . 'web.config'; if ( file_exists( $web_config ) ) { return array( 'status' => 'pass', 'label' => __( 'IIS server — web.config is present', 'ai-cyberguard' ), 'detail' => __( 'IIS uses web.config instead of .htaccess. Configuration file is present.', 'ai-cyberguard' ), ); } return array( 'status' => 'warn', 'label' => __( 'IIS server — web.config not found', 'ai-cyberguard' ), 'detail' => __( 'IIS uses web.config instead of .htaccess. Ensure your WordPress web.config restricts access to sensitive files.', 'ai-cyberguard' ), ); } // Apache / LiteSpeed / Unknown: check .htaccess $htaccess = ABSPATH . '.htaccess'; if ( file_exists( $htaccess ) ) { return array( 'status' => 'pass', 'label' => __( '.htaccess file exists', 'ai-cyberguard' ), 'detail' => __( 'Apache/LiteSpeed configuration file is present', 'ai-cyberguard' ), ); } return array( 'status' => 'warn', 'label' => __( '.htaccess file missing', 'ai-cyberguard' ), 'detail' => __( 'Visit Settings > Permalinks to regenerate', 'ai-cyberguard' ), 'action' => admin_url( 'options-permalink.php' ), 'action_label' => __( 'Permalinks', 'ai-cyberguard' ), ); } private static function check_xmlrpc() { // FIX H-6 (audit 2026-05-25): $disabled was computed but never read; the // function only checked file existence. Result: sites that disable XML-RPC // via the canonical `add_filter('xmlrpc_enabled', '__return_false')` route // still got a "may be enabled" warning, and sites missing xmlrpc.php got a // false-clear regardless of filter state. Now: filter wins (the right // answer for nearly all hardened sites). File-only check is the fallback. // // Note on the filter check: has_filter('xmlrpc_enabled') returns truthy // when ANY callback is attached. If a third party returns true from that // filter (rare — would be re-enabling), apply_filters() === false will be // false and we fall through to the file check, which is the safe outcome. $disabled_via_filter = has_filter( 'xmlrpc_enabled' ) && apply_filters( 'xmlrpc_enabled', true ) === false; // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- 'xmlrpc_enabled' is a WordPress core hook being read, not a plugin-defined hook $xmlrpc_file = ABSPATH . 'xmlrpc.php'; $file_missing = ! file_exists( $xmlrpc_file ); if ( $disabled_via_filter ) { return array( 'status' => 'pass', 'label' => __( 'XML-RPC is disabled', 'ai-cyberguard' ), 'detail' => __( 'Disabled via xmlrpc_enabled filter', 'ai-cyberguard' ), ); } if ( $file_missing ) { return array( 'status' => 'pass', 'label' => __( 'XML-RPC is disabled', 'ai-cyberguard' ), 'detail' => __( 'xmlrpc.php file not found', 'ai-cyberguard' ), ); } return array( 'status' => 'warn', 'label' => __( 'XML-RPC may be enabled', 'ai-cyberguard' ), 'detail' => __( 'Consider disabling if not needed', 'ai-cyberguard' ), ); } private static function check_auto_updates() { $auto_update_core = defined( 'WP_AUTO_UPDATE_CORE' ) ? WP_AUTO_UPDATE_CORE : 'minor'; if ( $auto_update_core === true || $auto_update_core === 'minor' ) { return array( 'status' => 'pass', 'label' => __( 'Auto-updates enabled', 'ai-cyberguard' ), 'detail' => __( 'WordPress will automatically update', 'ai-cyberguard' ), ); } return array( 'status' => 'warn', 'label' => __( 'Auto-updates disabled', 'ai-cyberguard' ), 'detail' => __( 'Consider enabling for security patches', 'ai-cyberguard' ), ); } private static function check_strong_passwords() { // FIX (audit 2026-06-10): this used to hard-return 'pass' with the claim // "WordPress enforces strong passwords by default" — which is FALSE // (core only shows a strength meter; weak passwords are still accepted // after a confirmation checkbox). A passwordless 'pass' gave false // assurance. We can't read existing password strength (hashes are // one-way), so report it honestly as informational guidance rather than // a guaranteed pass. return array( 'status' => 'info', 'label' => __( 'Use strong, unique passwords', 'ai-cyberguard' ), 'detail' => __( 'WordPress shows a strength meter but does not force strong passwords. Ensure every admin uses a long, unique password and enable two-factor authentication.', 'ai-cyberguard' ), ); } /** * Get latest WordPress version from API (cached) */ private static function get_latest_wp_version() { $transient_key = 'guardpress_latest_wp_version'; $cached = get_transient( $transient_key ); if ( $cached !== false ) { return $cached; } // Get from WordPress core update check $update_data = get_site_transient( 'update_core' ); if ( isset( $update_data->updates[0]->version ) ) { $version = $update_data->updates[0]->version; set_transient( $transient_key, $version, DAY_IN_SECONDS ); return $version; } return false; } /** * Render the checklist HTML */ public static function render() { $checks = self::get_checks(); $summary = self::get_summary(); echo '