fix|link|toggle, label, fix|url]), * how (list of plain-text steps, optional). * * @package PumpAudit_WP */ namespace PumpAudit_WP; if ( ! defined( 'ABSPATH' ) ) { exit; } /** * Runs the checks and caches the report. */ class Checks { const CACHE = 'pumpaudit_wp_report'; /** * Site option with what WordPress.org said about each plugin this week. */ const STATE = 'pumpaudit_wp_plugin_state'; /** * Plugins that protect the login form (folder names). * * @var string[] */ const LOGIN_PLUGINS = array( 'wordfence', 'limit-login-attempts-reloaded', 'limit-login-attempts', 'two-factor', 'wp-2fa', 'better-wp-security', 'ithemes-security-pro', 'all-in-one-wp-security-and-firewall', 'loginizer', 'wp-cerber', 'wps-limit-login', 'login-lockdown', 'shield-security', 'wp-simple-firewall', 'sucuri-scanner', 'miniorange-2-factor-authentication', 'google-authenticator', 'two-factor-authentication', 'jetpack-protect', 'defender-security', 'solid-security' ); /** * Backup plugins (folder names). * * @var string[] */ const BACKUP_PLUGINS = array( 'updraftplus', 'backwpup', 'duplicator', 'duplicator-pro', 'all-in-one-wp-migration', 'wpvivid-backuprestore', 'backup-backup', 'backupbuddy', 'blogvault-real-time-backup', 'wp-time-capsule', 'boldgrid-backup', 'jetpack-backup', 'vaultpress', 'xcloner-backup-and-restore', 'wp-database-backup', 'backup', 'solid-backups' ); /** * Page cache plugins (folder names). * * @var string[] */ const CACHE_PLUGINS = array( 'wp-rocket', 'w3-total-cache', 'wp-super-cache', 'litespeed-cache', 'wp-fastest-cache', 'cache-enabler', 'breeze', 'sg-cachepress', 'hummingbird-performance', 'wp-optimize', 'nitropack', 'comet-cache', 'swift-performance-lite', 'wp-cloudflare-page-cache', 'powered-cache', 'flying-press' ); /** * Returns the cached report, or runs the checks. * * @param bool $fresh Run the checks even when a cached report exists. * @return array{score:int,counts:array,results:array,time:int,took:float} */ public static function run( $fresh = false ) { if ( ! $fresh ) { $cached = self::cached(); if ( $cached ) { return $cached; } } $start = microtime( true ); $results = array(); foreach ( self::ids() as $id ) { $method = 'check_' . $id; $r = self::$method(); $r['id'] = $id; $results[] = $r; } $counts = array( 'urgent' => 0, 'recommended' => 0, 'passed' => 0, ); foreach ( $results as $r ) { ++$counts[ $r['status'] ]; } $report = array( 'score' => max( 10, 100 - 8 * $counts['urgent'] - 3 * $counts['recommended'] ), 'counts' => $counts, 'results' => $results, 'time' => time(), 'took' => round( microtime( true ) - $start, 1 ), ); // Saved as an option, not a transient: some object caches lose transients between requests. update_option( self::CACHE, $report, false ); return $report; } /** * The last report if it is less than a day old, without running anything. * * @return array|null */ public static function cached() { $report = get_option( self::CACHE ); if ( is_array( $report ) && isset( $report['time'] ) && (int) $report['time'] > time() - DAY_IN_SECONDS ) { return $report; } return null; } /** * Check ids in report order. * * @return string[] */ public static function ids() { return array( 'search_engines', 'site_address', 'admin_user', 'file_edit', 'login_protection', 'closed_plugins', 'registration', 'debug', 'core_version', 'php', 'permalinks', 'attachment_pages', 'sample_content', 'tagline', 'front_page', 'timezone', 'plugin_updates', 'theme_updates', 'auto_updates', 'inactive', 'backup', 'admins', 'xmlrpc', 'cron', 'page_cache', 'big_media', 'database', 'comments', ); } /** * Builds a result. * * @param string $group Group. * @param string $status urgent|recommended|passed. * @param string $title Title (the consequence, in plain words). * @param string $desc One or two sentences. * @param string $passed Short phrase for the passed line. * @param array $actions Buttons. * @param array $how Steps. * @return array */ private static function result( $group, $status, $title, $desc, $passed, $actions = array(), $how = array() ) { return compact( 'group', 'status', 'title', 'desc', 'passed', 'actions', 'how' ); } /** * One-click fix button. * * @param string $fix Fix id. * @param string $label Label. * @return array */ private static function fix( $fix, $label ) { return array( 'type' => 'fix', 'fix' => $fix, 'label' => $label, ); } /** * Button to a screen. * * @param string $url Admin URL. * @param string $label Label. * @return array */ private static function link( $url, $label ) { return array( 'type' => 'link', 'url' => $url, 'label' => $label, ); } /** * Folder names of installed plugins, with their active state. * * @return array */ private static function plugin_dirs() { if ( ! function_exists( 'get_plugins' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } $out = array(); foreach ( array_keys( get_plugins() ) as $file ) { $dir = strpos( $file, '/' ) !== false ? dirname( $file ) : basename( $file, '.php' ); $out[ $dir ] = ( $out[ $dir ] ?? false ) || is_plugin_active( $file ); } return $out; } /** * Whether one of the given plugins is active. * * @param string[] $dirs Folder names. * @return bool */ private static function has_active( array $dirs ) { foreach ( self::plugin_dirs() as $dir => $active ) { if ( $active && in_array( $dir, $dirs, true ) ) { return true; } } return false; } /* ---------------------------------------------------------------- */ /** 26. Search engines discouraged. */ private static function check_search_engines() { if ( '0' !== (string) get_option( 'blog_public' ) ) { return self::result( 'visibility', 'passed', '', '', __( 'search engines can see your site', 'pumpaudit' ) ); } return self::result( 'visibility', 'urgent', __( 'Google has been asked not to show your site', 'pumpaudit' ), __( 'The "Discourage search engines" box in Settings > Reading is ticked.', 'pumpaudit' ), '', array( self::fix( 'search_engines', __( 'Untick it', 'pumpaudit' ) ) ) ); } /** 28. Site address on http. */ private static function check_site_address() { $home = (string) get_option( 'home' ); if ( 0 !== strpos( $home, 'http://' ) || in_array( wp_parse_url( $home, PHP_URL_HOST ), array( 'localhost', '127.0.0.1' ), true ) ) { return self::result( 'security', 'passed', '', '', __( 'the site address uses https', 'pumpaudit' ) ); } return self::result( 'security', 'urgent', __( 'Your site address starts with http, not https', 'pumpaudit' ), __( 'Browsers mark http sites as "Not secure", and forms sent over http can be read on the way.', 'pumpaudit' ), '', array( self::link( admin_url( 'options-general.php' ), __( 'Open settings', 'pumpaudit' ) ) ), array( __( 'Make sure your host has an SSL certificate for your domain (most give one free).', 'pumpaudit' ), __( 'Then change both addresses in Settings > General to start with https://. Take a backup first.', 'pumpaudit' ), ) ); } /** 6. A user called "admin". */ private static function check_admin_user() { $user = get_user_by( 'login', 'admin' ); if ( ! $user || ! user_can( $user, 'manage_options' ) ) { return self::result( 'security', 'passed', '', '', __( 'no "admin" user', 'pumpaudit' ) ); } return self::result( 'security', 'urgent', __( 'Attackers already know half of your login', 'pumpaudit' ), __( 'An administrator is called "admin", the first name every password-guessing bot tries.', 'pumpaudit' ), '', array( self::link( admin_url( 'user-new.php' ), __( 'Add a new admin', 'pumpaudit' ) ) ), array( __( 'Add a new administrator with a name that is not easy to guess.', 'pumpaudit' ), __( 'Log in as the new user and delete "admin". WordPress asks who should own its posts: choose the new user.', 'pumpaudit' ), ) ); } /** 8. File editor on. */ private static function check_file_edit() { if ( ( defined( 'DISALLOW_FILE_EDIT' ) && DISALLOW_FILE_EDIT ) || ( defined( 'DISALLOW_FILE_MODS' ) && DISALLOW_FILE_MODS ) ) { return self::result( 'security', 'passed', '', '', __( 'the code editor is off', 'pumpaudit' ) ); } return self::result( 'security', 'urgent', __( "Anyone who steals an admin password can change your site's code", 'pumpaudit' ), __( 'The theme and plugin file editor is switched on. One stolen login is enough to plant harmful code that your visitors would load.', 'pumpaudit' ), '', array(), array( /* translators: %s: a line of PHP code. */ sprintf( __( "Add one line to your site's wp-config.php file: %s", 'pumpaudit' ), "define( 'DISALLOW_FILE_EDIT', true );" ), __( 'Your host or developer can do this in a minute. PumpAudit never edits wp-config.php for you.', 'pumpaudit' ), ) ); } /** 10. No login protection. */ private static function check_login_protection() { if ( self::has_active( self::LOGIN_PLUGINS ) ) { return self::result( 'security', 'passed', '', '', __( 'the login is protected', 'pumpaudit' ) ); } return self::result( 'security', 'urgent', __( 'Nothing stops someone guessing passwords all day', 'pumpaudit' ), __( 'We found no login limit or two-step login. Bots try thousands of passwords against WordPress sites every day.', 'pumpaudit' ), '', array( self::link( admin_url( 'plugin-install.php?s=two-factor&tab=search&type=term' ), __( 'Find a plugin', 'pumpaudit' ) ) ), array( __( 'Install a plugin that limits login attempts or adds two-step login, for example "Two Factor" by the WordPress community.', 'pumpaudit' ), __( 'If your host already protects the login page, you can ignore this.', 'pumpaudit' ), ) ); } /** 11. Closed or abandoned plugins (asks WordPress.org, cached a week). */ private static function check_closed_plugins() { if ( ! function_exists( 'get_plugins' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } $closed = array(); $stale = array(); $cache = self::fill_plugin_states( 5 ); foreach ( get_plugins() as $file => $data ) { $state = $cache[ self::plugin_slug( $file ) ] ?? 'unknown'; if ( 'closed' === $state ) { $closed[] = $data['Name']; } elseif ( 'stale' === $state ) { $stale[] = $data['Name']; } } if ( $closed ) { return self::result( 'security', 'urgent', /* translators: %d: number of plugins. */ sprintf( _n( '%d of your plugins is no longer maintained', '%d of your plugins are no longer maintained', count( $closed ), 'pumpaudit' ), count( $closed ) ), /* translators: %s: plugin names. */ sprintf( __( '%s was closed on WordPress.org. New security holes in it will not be fixed.', 'pumpaudit' ), '"' . implode( '", "', $closed ) . '"' ) . ( $stale /* translators: %s: plugin names. */ ? ' ' . sprintf( __( '%s has also not been updated for two years.', 'pumpaudit' ), '"' . implode( '", "', $stale ) . '"' ) : '' ), '', array( self::link( admin_url( 'plugins.php' ), __( 'See plugins', 'pumpaudit' ) ) ), array( __( 'Look for a maintained plugin that does the same job, switch to it, then delete the closed one.', 'pumpaudit' ) ) ); } if ( $stale ) { return self::result( 'security', 'recommended', /* translators: %d: number of plugins. */ sprintf( _n( '%d plugin has not been updated for two years', '%d plugins have not been updated for two years', count( $stale ), 'pumpaudit' ), count( $stale ) ), /* translators: %s: plugin names. */ sprintf( __( '%s may be abandoned. Old plugins are a common way into WordPress sites.', 'pumpaudit' ), '"' . implode( '", "', $stale ) . '"' ), '', array( self::link( admin_url( 'plugins.php' ), __( 'See plugins', 'pumpaudit' ) ) ) ); } return self::result( 'security', 'passed', '', '', __( 'your plugins are maintained', 'pumpaudit' ) ); } /** * Folder name (slug) of a plugin file. * * @param string $file Plugin file, relative to the plugins folder. * @return string */ private static function plugin_slug( $file ) { return strpos( $file, '/' ) !== false ? dirname( $file ) : basename( $file, '.php' ); } /** * Asks WordPress.org about installed plugins it has not asked about this * week, within a time budget so the report opens quickly. What is left is * asked in the background (a single cron event), and the report refreshes. * * @param float $budget Seconds to spend; 0 means no limit. * @return array slug => closed|stale|ok|notfound */ public static function fill_plugin_states( $budget = 0 ) { if ( ! function_exists( 'get_plugins' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } // A site option with its own date, not a transient: some object caches lose transients between requests. $saved = get_site_option( self::STATE ); $cache = is_array( $saved ) && isset( $saved['time'], $saved['states'] ) && (int) $saved['time'] > time() - WEEK_IN_SECONDS ? (array) $saved['states'] : array(); $since = is_array( $saved ) && isset( $saved['time'] ) && $cache ? (int) $saved['time'] : time(); $start = microtime( true ); $changed = false; $left = false; foreach ( array_keys( get_plugins() ) as $file ) { $slug = self::plugin_slug( $file ); if ( 'pumpaudit' === $slug || isset( $cache[ $slug ] ) ) { continue; } if ( $budget && microtime( true ) - $start > $budget ) { $left = true; break; } $state = self::wporg_state( $slug ); if ( 'unknown' !== $state ) { // A failed request is asked again next time, not remembered for a week. $cache[ $slug ] = $state; $changed = true; } } if ( $changed ) { update_site_option( self::STATE, array( 'time' => $since, 'states' => $cache, ) ); } if ( $left && ! wp_next_scheduled( 'pumpaudit_wp_fill_plugin_states' ) ) { wp_schedule_single_event( time() + 10, 'pumpaudit_wp_fill_plugin_states' ); } return $cache; } /** * Background run: finishes the WordPress.org questions, then refreshes the report. */ public static function background_fill() { self::fill_plugin_states( 0 ); self::run( true ); } /** * Asks WordPress.org about one plugin. * * @param string $slug Plugin slug. * @return string closed|stale|ok|notfound|unknown (request failed) */ private static function wporg_state( $slug ) { $url = add_query_arg( array( 'action' => 'plugin_information', 'slug' => $slug, 'fields' => array( 'sections' => 0, 'last_updated' => 1 ), ), 'https://api.wordpress.org/plugins/info/1.2/' ); $resp = wp_remote_get( $url, array( 'timeout' => 4 ) ); if ( is_wp_error( $resp ) ) { return 'unknown'; } $body = json_decode( wp_remote_retrieve_body( $resp ), true ); if ( ! is_array( $body ) ) { return 'unknown'; } if ( ! empty( $body['error'] ) ) { // Not on WordPress.org (premium or custom): nothing to report, remembered. return ! empty( $body['closed'] ) ? 'closed' : 'notfound'; } $last = isset( $body['last_updated'] ) ? strtotime( $body['last_updated'] ) : 0; return ( $last && $last < time() - 2 * YEAR_IN_SECONDS ) ? 'stale' : 'ok'; } /** 23. Open registration with a dangerous role. */ private static function check_registration() { $role = (string) get_option( 'default_role' ); if ( ! get_option( 'users_can_register' ) || ! in_array( $role, array( 'administrator', 'editor', 'author', 'shop_manager' ), true ) ) { return self::result( 'security', 'passed', '', '', __( 'sign-ups are safe', 'pumpaudit' ) ); } return self::result( 'security', 'urgent', __( 'Anyone can sign up and change your content', 'pumpaudit' ), /* translators: %s: role name. */ sprintf( __( 'Anyone can register, and new users become "%s".', 'pumpaudit' ), translate_user_role( ucfirst( str_replace( '_', ' ', $role ) ) ) ), '', array( self::fix( 'registration', __( 'Make new users Subscribers', 'pumpaudit' ) ) ) ); } /** 21. Debug output on a live site. */ private static function check_debug() { $debug = defined( 'WP_DEBUG' ) && WP_DEBUG; $display = $debug && ( ! defined( 'WP_DEBUG_DISPLAY' ) || WP_DEBUG_DISPLAY ); if ( ! $display ) { return self::result( 'security', 'passed', '', '', __( 'errors are not shown to visitors', 'pumpaudit' ) ); } return self::result( 'security', 'recommended', __( 'Visitors can see error messages from your site', 'pumpaudit' ), __( 'Debug mode is on and shows errors on the page. They look broken and tell attackers about your setup.', 'pumpaudit' ), '', array(), /* translators: %s: a line of PHP code. */ array( sprintf( __( 'In wp-config.php change WP_DEBUG to false, or add %s. Your host or developer can do this.', 'pumpaudit' ), "define( 'WP_DEBUG_DISPLAY', false );" ) ) ); } /** 27. WordPress itself out of date. */ private static function check_core_version() { $core = get_site_transient( 'update_core' ); $up = false; if ( is_object( $core ) && ! empty( $core->updates ) ) { foreach ( $core->updates as $u ) { if ( isset( $u->response ) && 'upgrade' === $u->response ) { $up = $u->current ?? true; } } } if ( ! $up ) { return self::result( 'maintenance', 'passed', '', '', __( 'WordPress is up to date', 'pumpaudit' ) ); } return self::result( 'maintenance', 'recommended', /* translators: %s: version number. */ is_string( $up ) ? sprintf( __( 'WordPress %s is waiting to be installed', 'pumpaudit' ), $up ) : __( 'A new version of WordPress is waiting', 'pumpaudit' ), __( 'Updates fix security holes. Take a backup, then update.', 'pumpaudit' ), '', array( self::link( admin_url( 'update-core.php' ), __( 'Go to updates', 'pumpaudit' ) ) ) ); } /** 20. Old PHP. */ private static function check_php() { $status = 'passed'; if ( function_exists( 'wp_check_php_version' ) ) { $res = wp_check_php_version(); if ( is_array( $res ) ) { if ( empty( $res['is_secure'] ) || empty( $res['is_acceptable'] ) ) { $status = 'urgent'; } elseif ( ! empty( $res['is_lower_than_future_minimum'] ) || version_compare( PHP_VERSION, $res['recommended_version'] ?? '8.1', '<' ) ) { $status = 'recommended'; } } } elseif ( version_compare( PHP_VERSION, '8.1', '<' ) ) { $status = 'recommended'; } if ( 'passed' === $status ) { return self::result( 'maintenance', 'passed', '', '', __( 'PHP is current', 'pumpaudit' ) ); } return self::result( 'maintenance', $status, /* translators: %s: PHP version. */ sprintf( __( 'Your server runs an old PHP (%s)', 'pumpaudit' ), PHP_VERSION ), __( 'PHP is the language WordPress runs on. Old versions are slower and no longer get security fixes.', 'pumpaudit' ), '', array(), array( __( 'Most hosts let you pick the PHP version in their control panel. Ask your host if you cannot find it.', 'pumpaudit' ) ) ); } /** 1. Plain permalinks. */ private static function check_permalinks() { if ( '' !== (string) get_option( 'permalink_structure' ) ) { return self::result( 'visibility', 'passed', '', '', __( 'addresses are readable', 'pumpaudit' ) ); } return self::result( 'visibility', 'recommended', __( 'Your page addresses are numbers, not words', 'pumpaudit' ), __( 'Addresses look like ?p=123. Words in the address help people and Google understand the page.', 'pumpaudit' ), '', array( self::fix( 'permalinks', __( 'Use page names', 'pumpaudit' ) ) ) ); } /** 5. Attachment pages on. */ private static function check_attachment_pages() { // The switch arrived in WordPress 6.4. Before that attachment pages are always on, unless an SEO plugin redirects them. $has_switch = version_compare( get_bloginfo( 'version' ), '6.4', '>=' ); if ( $has_switch ) { $on = (bool) (int) get_option( 'wp_attachment_pages_enabled', 0 ); } else { $yoast = self::has_active( array( 'wordpress-seo', 'wordpress-seo-premium' ) ) ? get_option( 'wpseo_titles' ) : null; $rank = self::has_active( array( 'seo-by-rank-math' ) ) ? get_option( 'rank-math-options-general' ) : null; $on = ! ( is_array( $yoast ) && ! empty( $yoast['disable-attachment'] ) ) && ! ( is_array( $rank ) && isset( $rank['attachment_redirect_urls'] ) && 'on' === $rank['attachment_redirect_urls'] ); } $count = $on ? (int) wp_count_posts( 'attachment' )->inherit : 0; if ( ! $count ) { return self::result( 'visibility', 'passed', '', '', __( 'no empty image pages', 'pumpaudit' ) ); } $action = $has_switch ? self::fix( 'attachment_pages', __( 'Fix in one click', 'pumpaudit' ) ) : self::link( admin_url( 'update-core.php' ), __( 'Go to updates', 'pumpaudit' ) ); return self::result( 'visibility', 'recommended', __( 'Google can see an empty page for every file you uploaded', 'pumpaudit' ), /* translators: %d: number of pages. */ sprintf( _n( 'Attachment pages are switched on, so %d thin page competes with your real ones in search.', 'Attachment pages are switched on, so %d thin pages compete with your real ones in search.', $count, 'pumpaudit' ), $count ), '', array( $action ) ); } /** * The example content WordPress adds on install, if still published. * * @return array{posts:int[],comments:int[]} */ public static function sample_content() { $posts = array(); foreach ( array( array( 'hello-world', 'post' ), array( 'sample-page', 'page' ) ) as $p ) { $found = get_posts( array( 'name' => $p[0], 'post_type' => $p[1], 'post_status' => 'publish', 'numberposts' => 1, 'fields' => 'ids', ) ); if ( $found ) { $posts[] = (int) $found[0]; } } $comments = get_comments( array( 'author_email' => 'wapuu@wordpress.example', 'fields' => 'ids', 'number' => 5, ) ); return array( 'posts' => $posts, 'comments' => array_map( 'intval', $comments ), ); } /** 3. Example content still live. */ private static function check_sample_content() { $s = self::sample_content(); if ( ! $s['posts'] && ! $s['comments'] ) { return self::result( 'visibility', 'passed', '', '', __( 'no example content', 'pumpaudit' ) ); } return self::result( 'visibility', 'recommended', __( 'The example content from the install is still live', 'pumpaudit' ), __( 'Visitors and Google can still find "Hello world!", "Sample Page" or the example comment.', 'pumpaudit' ), '', array( self::fix( 'sample_content', __( 'Move it to the trash', 'pumpaudit' ) ) ) ); } /** 2. Default or empty tagline. */ private static function check_tagline() { $tag = trim( (string) get_option( 'blogdescription' ) ); $defaults = array( 'Just another WordPress site', __( 'Just another WordPress site' ) ); // phpcs:ignore WordPress.WP.I18n.MissingArgDomain -- compares with the core string. if ( '' !== $tag && ! in_array( $tag, $defaults, true ) ) { return self::result( 'visibility', 'passed', '', '', __( 'your tagline is your own', 'pumpaudit' ) ); } return self::result( 'visibility', 'recommended', '' === $tag ? __( 'Your site has no tagline', 'pumpaudit' ) : __( "Your tagline is still WordPress's sample text", 'pumpaudit' ), __( 'The tagline can show in search results and browser tabs. One short line about what you do is enough.', 'pumpaudit' ), '', array( self::link( admin_url( 'options-general.php' ), __( 'Open settings', 'pumpaudit' ) ) ) ); } /** 4. Front page shows latest posts. */ private static function check_front_page() { if ( 'page' === get_option( 'show_on_front' ) || (int) wp_count_posts( 'post' )->publish > 10 ) { return self::result( 'visibility', 'passed', '', '', __( 'the home page is a page', 'pumpaudit' ) ); } return self::result( 'visibility', 'recommended', __( 'Your home page is a list of blog posts', 'pumpaudit' ), __( 'For most businesses the first page should say what you do. Fine to ignore if your site is a blog.', 'pumpaudit' ), '', array( self::link( admin_url( 'options-reading.php' ), __( 'Open settings', 'pumpaudit' ) ) ) ); } /** 16. Plain UTC time zone. */ private static function check_timezone() { if ( '' !== (string) get_option( 'timezone_string' ) || 0.0 !== (float) get_option( 'gmt_offset' ) ) { return self::result( 'visibility', 'passed', '', '', __( 'the time zone is set', 'pumpaudit' ) ); } return self::result( 'visibility', 'recommended', __( 'Your site may show the wrong time', 'pumpaudit' ), __( 'The time zone is plain UTC, so post dates, scheduled posts and form emails can be hours off from your local time. Pick your city instead.', 'pumpaudit' ), '', array( self::link( admin_url( 'options-general.php' ), __( 'Open settings', 'pumpaudit' ) ) ) ); } /** 17. Plugin updates waiting. */ private static function check_plugin_updates() { $t = get_site_transient( 'update_plugins' ); $n = is_object( $t ) && ! empty( $t->response ) ? count( $t->response ) : 0; if ( ! $n ) { return self::result( 'maintenance', 'passed', '', '', __( 'plugins are up to date', 'pumpaudit' ) ); } return self::result( 'maintenance', 'recommended', /* translators: %d: number of plugins. */ sprintf( _n( '%d plugin is waiting for an update', '%d plugins are waiting for updates', $n, 'pumpaudit' ), $n ), __( 'Most updates are security fixes. The longer they wait, the bigger the risk.', 'pumpaudit' ), '', array( self::link( admin_url( 'update-core.php' ), __( 'Go to updates', 'pumpaudit' ) ) ) ); } /** 18. Theme updates waiting. */ private static function check_theme_updates() { $t = get_site_transient( 'update_themes' ); $n = is_object( $t ) && ! empty( $t->response ) ? count( $t->response ) : 0; if ( ! $n ) { return self::result( 'maintenance', 'passed', '', '', __( 'themes are up to date', 'pumpaudit' ) ); } return self::result( 'maintenance', 'recommended', /* translators: %d: number of themes. */ sprintf( _n( '%d theme is waiting for an update', '%d themes are waiting for updates', $n, 'pumpaudit' ), $n ), __( 'Theme updates also fix security holes, even for themes you are not using.', 'pumpaudit' ), '', array( self::link( admin_url( 'update-core.php' ), __( 'Go to updates', 'pumpaudit' ) ) ) ); } /** 22. Automatic updates off. */ private static function check_auto_updates() { $off = ( defined( 'AUTOMATIC_UPDATER_DISABLED' ) && AUTOMATIC_UPDATER_DISABLED ) || ( defined( 'WP_AUTO_UPDATE_CORE' ) && false === WP_AUTO_UPDATE_CORE ); if ( ! $off ) { return self::result( 'maintenance', 'passed', '', '', __( 'security updates install themselves', 'pumpaudit' ) ); } return self::result( 'maintenance', 'recommended', __( 'Security updates do not install themselves', 'pumpaudit' ), __( 'Automatic WordPress updates are switched off in wp-config.php, so every security release waits for someone to log in.', 'pumpaudit' ), '', array(), array( __( 'Remove AUTOMATIC_UPDATER_DISABLED or WP_AUTO_UPDATE_CORE from wp-config.php, unless your host updates WordPress for you.', 'pumpaudit' ) ) ); } /** 19. Inactive plugins and themes. */ private static function check_inactive() { $plugins = 0; foreach ( self::plugin_dirs() as $dir => $active ) { if ( ! $active ) { ++$plugins; } } // Active theme, its parent and one spare default theme are fine. $themes = max( 0, count( wp_get_themes() ) - 1 - ( get_template() !== get_stylesheet() ? 1 : 0 ) - 1 ); if ( ! $plugins && ! $themes ) { return self::result( 'maintenance', 'passed', '', '', __( 'no unused plugins', 'pumpaudit' ) ); } if ( $plugins && $themes ) { /* translators: 1: number of plugins, 2: number of themes. */ $title = sprintf( __( '%1$d unused plugins and %2$d unused themes are installed', 'pumpaudit' ), $plugins, $themes ); } elseif ( $plugins ) { /* translators: %d: number of plugins. */ $title = sprintf( _n( '%d unused plugin is installed', '%d unused plugins are installed', $plugins, 'pumpaudit' ), $plugins ); } else { /* translators: %d: number of themes. */ $title = sprintf( _n( '%d unused theme is installed', '%d unused themes are installed', $themes, 'pumpaudit' ), $themes ); } return self::result( 'maintenance', 'recommended', $title, __( 'Switched-off plugins and themes can still be attacked. Keep one spare default theme, delete the rest.', 'pumpaudit' ), '', array( self::link( admin_url( 'plugins.php?plugin_status=inactive' ), __( 'See unused plugins', 'pumpaudit' ) ) ) ); } /** 12. No backup plugin. */ private static function check_backup() { if ( get_option( 'pumpaudit_wp_host_backups' ) || self::has_active( self::BACKUP_PLUGINS ) ) { return self::result( 'maintenance', 'passed', '', '', __( 'backups are covered', 'pumpaudit' ) ); } return self::result( 'maintenance', 'recommended', __( 'We could not find a backup plugin', 'pumpaudit' ), __( 'If your host already backs up your site every day, you are fine. If not, one bad update could cost you everything.', 'pumpaudit' ), '', array( self::fix( 'host_backups', __( 'My host backs up', 'pumpaudit' ) ), self::link( admin_url( 'plugin-install.php?s=backup&tab=search&type=term' ), __( 'Find a plugin', 'pumpaudit' ) ), ) ); } /** 7. Too many administrators. */ private static function check_admins() { $n = count( get_users( array( 'role' => 'administrator', 'fields' => 'ID', ) ) ); if ( $n <= 3 ) { return self::result( 'security', 'passed', '', '', __( 'few administrators', 'pumpaudit' ) ); } return self::result( 'security', 'recommended', /* translators: %d: number of users. */ sprintf( __( '%d people can do anything on your site', 'pumpaudit' ), $n ), __( 'Every administrator account is a way in. People who only write or edit pages do not need it.', 'pumpaudit' ), '', array( self::link( admin_url( 'users.php?role=administrator' ), __( 'See administrators', 'pumpaudit' ) ) ) ); } /** 9. XML-RPC on. */ private static function check_xmlrpc() { if ( get_option( 'pumpaudit_wp_xmlrpc_off' ) || ! apply_filters( 'xmlrpc_enabled', true ) || self::has_active( array( 'jetpack' ) ) ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- core filter. return self::result( 'security', 'passed', '', '', __( 'the old login door is closed', 'pumpaudit' ) ); } return self::result( 'security', 'recommended', __( 'An old back door for logging in is open', 'pumpaudit' ), __( 'XML-RPC is a remote login method that most sites no longer use. Bots use it to guess passwords quickly. Keep it if you post from an old app.', 'pumpaudit' ), '', array( self::fix( 'xmlrpc', __( 'Close it', 'pumpaudit' ) ) ) ); } /** 25. Scheduled tasks late. */ private static function check_cron() { $late = 0; $now = time(); foreach ( (array) _get_cron_array() as $ts => $hooks ) { if ( (int) $ts < $now - HOUR_IN_SECONDS ) { $late += count( (array) $hooks ); } } if ( $late < 3 ) { return self::result( 'maintenance', 'passed', '', '', __( 'scheduled tasks run', 'pumpaudit' ) ); } return self::result( 'maintenance', 'recommended', __( 'Scheduled tasks are running late', 'pumpaudit' ), /* translators: %d: number of tasks. */ sprintf( __( '%d tasks are more than an hour late: scheduled posts, update checks and backups may not happen.', 'pumpaudit' ), $late ), '', array( self::link( admin_url( 'site-health.php' ), __( 'Open Site Health', 'pumpaudit' ) ) ), array( __( 'Ask your host to set up a real cron job for WordPress, or check that DISABLE_WP_CRON is not set without one.', 'pumpaudit' ) ) ); } /** 24. No page cache. */ private static function check_page_cache() { if ( ( defined( 'WP_CACHE' ) && WP_CACHE ) || self::has_active( self::CACHE_PLUGINS ) || self::cache_headers() ) { return self::result( 'storage', 'passed', '', '', __( 'pages are cached', 'pumpaudit' ) ); } return self::result( 'storage', 'recommended', __( 'Every visit builds your page from scratch', 'pumpaudit' ), __( 'We found no page cache. A cache keeps a ready copy of each page, so it opens faster and your server copes with busy days.', 'pumpaudit' ), '', array( self::link( admin_url( 'plugin-install.php?s=cache&tab=search&type=term' ), __( 'Find a plugin', 'pumpaudit' ) ) ), array( __( 'Many hosts have their own cache: look in your hosting panel before installing a plugin.', 'pumpaudit' ) ) ); } /** * Whether the home page answers with headers a cache adds (one request to this site). * * @return bool */ private static function cache_headers() { $resp = wp_remote_get( home_url( '/' ), array( 'timeout' => 5, 'sslverify' => false, ) ); if ( is_wp_error( $resp ) ) { return false; } foreach ( array( 'x-cache', 'cf-cache-status', 'x-litespeed-cache', 'x-proxy-cache', 'x-nginx-cache', 'x-cache-enabled', 'x-srcache-fetch-status', 'x-varnish', 'age', 'x-hcdn-cache-status' ) as $h ) { if ( '' !== (string) wp_remote_retrieve_header( $resp, $h ) ) { return true; } } return false; } /** 13. Very large files in the media library. */ private static function check_big_media() { $ids = get_posts( array( 'post_type' => 'attachment', 'post_mime_type' => 'image', 'post_status' => 'inherit', 'numberposts' => 3000, 'fields' => 'ids', ) ); $big = 0; foreach ( $ids as $id ) { $meta = wp_get_attachment_metadata( $id ); $size = isset( $meta['filesize'] ) ? (int) $meta['filesize'] : 0; // WordPress shrinks big uploads and keeps the original on disk. if ( ! empty( $meta['original_image'] ) ) { $original = wp_get_original_image_path( $id ); $size = max( $size, $original && file_exists( $original ) ? (int) filesize( $original ) : 0 ); } if ( $size > 2 * MB_IN_BYTES || ( empty( $meta['original_image'] ) && ( $meta['width'] ?? 0 ) > 3000 ) ) { ++$big; } } if ( ! $big ) { return self::result( 'storage', 'passed', '', '', __( 'images are a sensible size', 'pumpaudit' ) ); } return self::result( 'storage', 'recommended', /* translators: %d: number of images. */ sprintf( _n( '%d image is very large', '%d images are very large', $big, 'pumpaudit' ), $big ), __( 'Images over 2 MB fill your hosting space and slow down any page that uses them.', 'pumpaudit' ), '', array( self::link( admin_url( 'upload.php?mode=list' ), __( 'Open the media library', 'pumpaudit' ) ) ), array( __( 'Resize them to the size you show (about 2000 pixels wide is plenty) and upload again, or use an image optimisation plugin.', 'pumpaudit' ) ) ); } /** * Revisions beyond the last five of each post. * * @return int */ public static function extra_revisions() { global $wpdb; // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- one count for the report. $rows = $wpdb->get_col( "SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_type = 'revision' GROUP BY post_parent HAVING COUNT(*) > 5" ); $extra = 0; foreach ( $rows as $n ) { $extra += (int) $n - 5; } return $extra; } /** 14. Database clutter. */ private static function check_database() { $rev = self::extra_revisions(); $spam = (int) wp_count_comments()->spam; if ( $rev < 500 && $spam < 200 ) { return self::result( 'storage', 'passed', '', '', __( 'the database is tidy', 'pumpaudit' ) ); } return self::result( 'storage', 'recommended', $rev >= 500 /* translators: %s: number. */ ? sprintf( __( '%s old revisions are filling your database', 'pumpaudit' ), number_format_i18n( $rev ) ) /* translators: %s: number. */ : sprintf( __( '%s spam comments are filling your database', 'pumpaudit' ), number_format_i18n( $spam ) ), __( 'Clearing them is safe: the last 5 versions of every page are kept, and spam is only what is already marked as spam.', 'pumpaudit' ), '', array( self::fix( 'database', __( 'Clean up', 'pumpaudit' ) ) ) ); } /** 15. Comments open and spam waiting. */ private static function check_comments() { $c = wp_count_comments(); $waiting = (int) $c->moderated; if ( 'open' !== get_option( 'default_comment_status' ) || $waiting < 20 ) { return self::result( 'visibility', 'passed', '', '', __( 'comments are under control', 'pumpaudit' ) ); } return self::result( 'visibility', 'recommended', /* translators: %d: number of comments. */ sprintf( __( '%d comments are waiting for you', 'pumpaudit' ), $waiting ), __( 'Comments are open on new posts and most of what arrives is spam. If you do not use comments, switch them off.', 'pumpaudit' ), '', array( self::link( admin_url( 'options-discussion.php' ), __( 'Open settings', 'pumpaudit' ) ) ) ); } }