$current_version, 'latest_version' => $latest_version, ); if ( ! $latest_version ) { return static::info( sprintf( /* translators: %s: WordPress version */ __( 'Your site is running WordPress %s. We couldn\'t check for the latest version right now.', '0-day-analytics' ), $current_version ), $details ); } // Compare versions. $comparison = version_compare( $current_version, $latest_version ); if ( $comparison >= 0 ) { return static::pass( sprintf( /* translators: %s: WordPress version */ __( 'Your WordPress installation is up to date (version %s).', '0-day-analytics' ), $current_version ), $details ); } // Check how far behind we are. $current_parts = explode( '.', $current_version ); $latest_parts = explode( '.', $latest_version ); $major_behind = ( $current_parts[0] ?? 0 ) < ( $latest_parts[0] ?? 0 ); $minor_behind = ! $major_behind && ( ( $current_parts[1] ?? 0 ) < ( $latest_parts[1] ?? 0 ) ); if ( $major_behind ) { return static::fail( 'critical', sprintf( /* translators: 1: current version, 2: latest version */ __( 'Your WordPress installation (version %1$s) is significantly outdated. The latest version is %2$s. Outdated WordPress versions are a common target for hackers.', '0-day-analytics' ), $current_version, $latest_version ), __( 'Go to Dashboard → Updates and click "Update Now" to get the latest WordPress version. Always backup your site before updating.', '0-day-analytics' ), $details ); } if ( $minor_behind ) { return static::fail( 'high', sprintf( /* translators: 1: current version, 2: latest version */ __( 'Your WordPress version (%1$s) is behind the latest release (%2$s). Minor updates often include important security fixes.', '0-day-analytics' ), $current_version, $latest_version ), __( 'Go to Dashboard → Updates and update to the latest WordPress version. Minor updates are generally safe and include security fixes.', '0-day-analytics' ), $details ); } // Just a patch version behind. return static::warning( sprintf( /* translators: 1: current version, 2: latest version */ __( 'A newer version of WordPress (%2$s) is available. You\'re running %1$s.', '0-day-analytics' ), $current_version, $latest_version ), __( 'Go to Dashboard → Updates to update WordPress. Keep your site updated for the best security.', '0-day-analytics' ), $details ); } /** * Get the latest WordPress version. * * Uses the update_core transient that WordPress core populates * during its regular update checks. This transient is automatically * refreshed by WordPress in admin context. * * @return string|false Latest version or false on failure. * * @since 4.9.0 */ private static function get_latest_version() { // Get cached version info from WordPress core's update check. // This transient is populated by WordPress when checking for updates. $update_core = get_site_transient( 'update_core' ); // If transient exists and has version info, return it. if ( isset( $update_core->updates[0]->version ) ) { return $update_core->updates[0]->version; } // If no transient exists yet and wp_version_check() is available, // trigger an update check. This function is loaded in admin context. if ( function_exists( 'wp_version_check' ) ) { wp_version_check(); $update_core = get_site_transient( 'update_core' ); if ( isset( $update_core->updates[0]->version ) ) { return $update_core->updates[0]->version; } } return false; } } }