Files
wp-healthcheck/includes/steps/90-database.php
Steve Hanlon 6dd050ea1d Rename to ATT Site Healthcheck (private prefix)
Wholesale rename to avoid clashes with generic 'site healthcheck'
plugin names on a target site:

  - Plugin Name:        'Site Healthcheck' → 'ATT Site Healthcheck'
  - Main file:          site-healthcheck.php → att-site-healthcheck.php
  - Plugin folder:      site-healthcheck → att-site-healthcheck
  - Admin menu slug:    site-healthcheck → att-site-healthcheck
  - Settings slug:      site-healthcheck-settings → att-site-healthcheck-settings
  - PHP class prefix:   WPH_ → ATT_HC_
  - Function prefix:    wph_ → att_hc_
  - Option / transient: wph_* → att_hc_*
  - Action/filter:      wph_* → att_hc_*
  - CSS class prefix:   wph- → att-hc-
  - Constants:          WPH_GITEA_* → ATT_HC_GITEA_*
  - Class file names:   class-wph-*.php → class-att-hc-*.php
  - Dev folder:         ~/dev/wp-healthcheck → ~/dev/att-site-healthcheck

Existing in-progress sessions on installs that had the old wph_session
option will not migrate — they were intended for dev use only and the
user has confirmed this is OK for the rename window.

Smoke-tested on testsite: classes load, 14 steps discovered, save/load
round-trip works, admin page renders with new att-hc- CSS classes.

Recovery plugin detection unchanged — that lives in wp-site-recovery
and continues to be detected by Name + Author header.
2026-06-12 11:11:42 +01:00

77 lines
3.1 KiB
PHP

<?php
if (!defined('ABSPATH')) exit;
return new class extends ATT_HC_Step {
public function id(): string { return 'database'; }
public function title(): string { return 'Step 9 — Database'; }
public function sub_items(): array {
return [
'Run a database optimisation (via WP-CLI: wp db optimize, or via a plugin such as WP-Optimize)',
'Check for and remove any spam comments if comment moderation hasn\'t been keeping up',
'Check post revisions — if excessive (thousands), note for client discussion on whether a revision limit should be set',
];
}
public function autocheck(array $session_state): array {
/** @var wpdb $wpdb */
global $wpdb;
$f = [];
// Spam comments
$counts = wp_count_comments();
$f[] = $this->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;
}
};