hardening 2.3: 2meet-data-optimizer 1.3.0 (flat-table DDL outside web requests, routed count cache, audit fixes) #7
+15
-15
@@ -30,7 +30,7 @@ if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
|
||||
global $wpdb;
|
||||
|
||||
// ── Load shared cleanup logic + snapshot classes ─────────────────────────
|
||||
$bootstrap_files = array(
|
||||
$wpdo_bootstrap_files = array(
|
||||
__DIR__ . '/includes/class-tmdo-logger.php',
|
||||
__DIR__ . '/includes/class-tmdo-feature-flags.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-pruner.php',
|
||||
);
|
||||
$bootstrap_ok = true;
|
||||
foreach ( $bootstrap_files as $f ) {
|
||||
if ( ! is_file( $f ) ) {
|
||||
$bootstrap_ok = false;
|
||||
$wpdo_bootstrap_ok = true;
|
||||
foreach ( $wpdo_bootstrap_files as $wpdo_bootstrap_file ) {
|
||||
if ( ! is_file( $wpdo_bootstrap_file ) ) {
|
||||
$wpdo_bootstrap_ok = false;
|
||||
continue;
|
||||
}
|
||||
require_once $f;
|
||||
require_once $wpdo_bootstrap_file;
|
||||
}
|
||||
|
||||
// ── 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 ───
|
||||
if ( ! $bootstrap_ok ) {
|
||||
if ( ! $wpdo_bootstrap_ok ) {
|
||||
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
|
||||
// site-level table DROP that happens later). Best-effort.
|
||||
if ( class_exists( 'TMDO_Snapshot_Manager' ) ) {
|
||||
$result = TMDO_Snapshot_Manager::create(
|
||||
$wpdo_snapshot = TMDO_Snapshot_Manager::create(
|
||||
'pre_uninstall',
|
||||
array(),
|
||||
array(
|
||||
@@ -112,18 +112,18 @@ if ( class_exists( 'TMDO_Snapshot_Manager' ) ) {
|
||||
'inline_threshold_bytes' => 0,
|
||||
)
|
||||
);
|
||||
if ( ! empty( $result['ok'] ) ) {
|
||||
$snapshot_id = $result['snapshot_id'];
|
||||
$dir = TMDO_Snapshot_Manager::backup_dir();
|
||||
if ( is_dir( $dir ) ) {
|
||||
if ( ! empty( $wpdo_snapshot['ok'] ) ) {
|
||||
$wpdo_snapshot_id = $wpdo_snapshot['snapshot_id'];
|
||||
$wpdo_backup_dir = TMDO_Snapshot_Manager::backup_dir();
|
||||
if ( is_dir( $wpdo_backup_dir ) ) {
|
||||
file_put_contents(
|
||||
trailingslashit( $dir ) . 'README-pre-uninstall.txt',
|
||||
"WPDO pre-uninstall snapshot: {$snapshot_id}\n"
|
||||
trailingslashit( $wpdo_backup_dir ) . 'README-pre-uninstall.txt',
|
||||
"WPDO pre-uninstall snapshot: {$wpdo_snapshot_id}\n"
|
||||
. 'Created: ' . gmdate( 'Y-m-d H:i:s' ) . " UTC\n\n"
|
||||
. "To restore after re-installing wp-data-optimizer:\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"
|
||||
. " 3. Run: wp wpdo snapshot restore {$snapshot_id} --apply\n"
|
||||
. " 3. Run: wp wpdo snapshot restore {$wpdo_snapshot_id} --apply\n"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user