hardening 2.3: 2meet-data-optimizer 1.3.0 (flat-table DDL outside web requests, routed count cache, audit fixes) #7

Merged
wpdev merged 20 commits from hardening/2.3 into main 2026-09-27 18:19:18 +08:00
Showing only changes of commit d46913de41 - Show all commits
+15 -15
View File
@@ -30,7 +30,7 @@ if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
global $wpdb; global $wpdb;
// ── Load shared cleanup logic + snapshot classes ───────────────────────── // ── Load shared cleanup logic + snapshot classes ─────────────────────────
$bootstrap_files = array( $wpdo_bootstrap_files = array(
__DIR__ . '/includes/class-tmdo-logger.php', __DIR__ . '/includes/class-tmdo-logger.php',
__DIR__ . '/includes/class-tmdo-feature-flags.php', __DIR__ . '/includes/class-tmdo-feature-flags.php',
__DIR__ . '/includes/class-tmdo-installer.php', __DIR__ . '/includes/class-tmdo-installer.php',
@@ -39,13 +39,13 @@ $bootstrap_files = array(
__DIR__ . '/includes/snapshots/class-tmdo-snapshot-reader.php', __DIR__ . '/includes/snapshots/class-tmdo-snapshot-reader.php',
__DIR__ . '/includes/snapshots/class-tmdo-snapshot-pruner.php', __DIR__ . '/includes/snapshots/class-tmdo-snapshot-pruner.php',
); );
$bootstrap_ok = true; $wpdo_bootstrap_ok = true;
foreach ( $bootstrap_files as $f ) { foreach ( $wpdo_bootstrap_files as $wpdo_bootstrap_file ) {
if ( ! is_file( $f ) ) { if ( ! is_file( $wpdo_bootstrap_file ) ) {
$bootstrap_ok = false; $wpdo_bootstrap_ok = false;
continue; continue;
} }
require_once $f; require_once $wpdo_bootstrap_file;
} }
// ── Sites to check and clean (0 = single site, no blog switching) ──────── // ── Sites to check and clean (0 = single site, no blog switching) ────────
@@ -77,7 +77,7 @@ $wpdo_for_each_site = static function ( callable $callback ) use ( $wpdo_site_id
}; };
// ── Refuse while any site holds data that exists only in wpdo_* tables ─── // ── Refuse while any site holds data that exists only in wpdo_* tables ───
if ( ! $bootstrap_ok ) { if ( ! $wpdo_bootstrap_ok ) {
wp_die( esc_html( '2meet Data Optimizer:無法載入資料安全檢查,為避免資料遺失,已停止解除安裝。' ) ); wp_die( esc_html( '2meet Data Optimizer:無法載入資料安全檢查,為避免資料遺失,已停止解除安裝。' ) );
} }
@@ -103,7 +103,7 @@ if ( $wpdo_blocked ) {
// wpdo_snapshots rows (which is per-site so per-site snapshots survive the // wpdo_snapshots rows (which is per-site so per-site snapshots survive the
// site-level table DROP that happens later). Best-effort. // site-level table DROP that happens later). Best-effort.
if ( class_exists( 'TMDO_Snapshot_Manager' ) ) { if ( class_exists( 'TMDO_Snapshot_Manager' ) ) {
$result = TMDO_Snapshot_Manager::create( $wpdo_snapshot = TMDO_Snapshot_Manager::create(
'pre_uninstall', 'pre_uninstall',
array(), array(),
array( array(
@@ -112,18 +112,18 @@ if ( class_exists( 'TMDO_Snapshot_Manager' ) ) {
'inline_threshold_bytes' => 0, 'inline_threshold_bytes' => 0,
) )
); );
if ( ! empty( $result['ok'] ) ) { if ( ! empty( $wpdo_snapshot['ok'] ) ) {
$snapshot_id = $result['snapshot_id']; $wpdo_snapshot_id = $wpdo_snapshot['snapshot_id'];
$dir = TMDO_Snapshot_Manager::backup_dir(); $wpdo_backup_dir = TMDO_Snapshot_Manager::backup_dir();
if ( is_dir( $dir ) ) { if ( is_dir( $wpdo_backup_dir ) ) {
file_put_contents( file_put_contents(
trailingslashit( $dir ) . 'README-pre-uninstall.txt', trailingslashit( $wpdo_backup_dir ) . 'README-pre-uninstall.txt',
"WPDO pre-uninstall snapshot: {$snapshot_id}\n" "WPDO pre-uninstall snapshot: {$wpdo_snapshot_id}\n"
. 'Created: ' . gmdate( 'Y-m-d H:i:s' ) . " UTC\n\n" . 'Created: ' . gmdate( 'Y-m-d H:i:s' ) . " UTC\n\n"
. "To restore after re-installing wp-data-optimizer:\n" . "To restore after re-installing wp-data-optimizer:\n"
. " 1. Re-install the plugin (it will re-create wp_wpdo_snapshots).\n" . " 1. Re-install the plugin (it will re-create wp_wpdo_snapshots).\n"
. " 2. Manually re-insert this snapshot's catalog row, or use wp wpdo snapshot list to confirm.\n" . " 2. Manually re-insert this snapshot's catalog row, or use wp wpdo snapshot list to confirm.\n"
. " 3. Run: wp wpdo snapshot restore {$snapshot_id} --apply\n" . " 3. Run: wp wpdo snapshot restore {$wpdo_snapshot_id} --apply\n"
); );
} }
} }