Bug #21886 » action-scheduler-table-cleanup.php
| 1 |
<?php
|
|---|---|
| 2 |
|
| 3 |
global $wpdb; |
| 4 |
|
| 5 |
$tables = $wpdb->get_col( "SHOW TABLES LIKE '%actionscheduler_logs%'" ); |
| 6 |
|
| 7 |
$as_plugins = [ |
| 8 |
'easy-wp-smtp/easy-wp-smtp.php', |
| 9 |
'event-tickets/event-tickets.php', |
| 10 |
'pdf-embedder/pdf_embedder.php', |
| 11 |
'the-events-calendar/the-events-calendar.php', |
| 12 |
'widget-for-eventbright-api/widget-for-eventbright-api.php', |
| 13 |
];
|
| 14 |
|
| 15 |
foreach ( $tables as $table ) { |
| 16 |
$matched = preg_match( '/^' . $wpdb->base_prefix . '([0-9]+)_/', $table, $matches ); |
| 17 |
|
| 18 |
if ( ! $matched ) { |
| 19 |
continue; |
| 20 |
}
|
| 21 |
|
| 22 |
$site_id = (int) $matches[1]; |
| 23 |
|
| 24 |
$needs_as_tables = false; |
| 25 |
|
| 26 |
switch_to_blog( $site_id ); |
| 27 |
|
| 28 |
foreach ( $as_plugins as $as_plugin ) { |
| 29 |
if ( is_plugin_active( $as_plugin ) ) { |
| 30 |
$needs_as_tables = true; |
| 31 |
break; |
| 32 |
}
|
| 33 |
}
|
| 34 |
|
| 35 |
restore_current_blog(); |
| 36 |
|
| 37 |
if ( ! $needs_as_tables ) { |
| 38 |
WP_CLI::log( "Dropping Action Scheduler tables for site ID {$site_id}." ); |
| 39 |
} else { |
| 40 |
WP_CLI::log( "Keeping Action Scheduler tables for site ID {$site_id}." ); |
| 41 |
}
|
| 42 |
}
|