finding( 'spam_comments', ($counts->spam ?? 0) > 100 ? 'warn' : 'ok', 'Spam comments', number_format((int) ($counts->spam ?? 0)), ($counts->trash ?? 0) ? number_format((int) $counts->trash) . ' in trash too.' : '' ); // Post revisions $revisions = (int) $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_type = 'revision'"); $level = $revisions > 5000 ? 'warn' : 'ok'; $f[] = $this->finding( 'revisions', $level, 'Post revisions', number_format($revisions), $level === 'warn' ? 'Consider setting WP_POST_REVISIONS to a sane limit (e.g. 10).' : '' ); // Autoload option size. WP 6.6+ uses 'on'/'auto'/'auto-on' alongside legacy 'yes'. $autoload_in = "autoload IN ('yes', 'on', 'auto', 'auto-on')"; $autoload_bytes = (int) $wpdb->get_var("SELECT SUM(LENGTH(option_value)) FROM {$wpdb->options} WHERE $autoload_in"); $autoload_count = (int) $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->options} WHERE $autoload_in"); $autoload_level = $autoload_bytes > 5 * MB_IN_BYTES ? 'warn' : 'ok'; $f[] = $this->finding( 'autoload', $autoload_level, 'Autoload options', $autoload_count . ' rows · ' . size_format($autoload_bytes), $autoload_level === 'warn' ? 'Large autoload payload slows every request — investigate which plugins are responsible.' : '' ); // Top 3 largest tables. `rows` is reserved in MySQL 8 — alias as table_rows. $tables = $wpdb->get_results(" SELECT TABLE_NAME AS name, DATA_LENGTH + INDEX_LENGTH AS bytes, TABLE_ROWS AS table_rows FROM information_schema.TABLES WHERE TABLE_SCHEMA = DATABASE() ORDER BY bytes DESC LIMIT 3 "); foreach ($tables as $i => $t) { $f[] = $this->finding( 'big_table_' . $i, 'info', ($i === 0 ? 'Largest tables — ' : '') . $t->name, size_format((int) $t->bytes), number_format((int) $t->table_rows) . ' rows' ); } return $f; } };