v3.0.1
This commit is contained in:
parent
8d5551a8b5
commit
ef4259b3c2
1 changed files with 634 additions and 94 deletions
|
|
@ -11,6 +11,11 @@
|
|||
* @since 2.0.0 Added cleanup for new implementation method option and transients.
|
||||
* @since 2.0.0 Added cleanup for multiple directives (noindex, nofollow, noarchive, nosnippet, noimageindex).
|
||||
* @since 2.0.1 Data is now preserved by default; deletion requires explicit opt-in.
|
||||
* @since 3.0.0 Added cleanup for the consolidated noindex_seo_settings option. Legacy
|
||||
* individual options are still cleaned up so that sites which upgrade from
|
||||
* 2.x and then uninstall (with or without migration having run) are fully
|
||||
* cleaned. Retrocompat: if a user rolls back to 2.x, their data is intact
|
||||
* until they explicitly uninstall.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
|
@ -22,7 +27,19 @@ if ( ! defined( 'ABSPATH' ) || ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
|
|||
|
||||
// Respect the user's data-preservation preference.
|
||||
// Default (0) = preserve data. Only delete when the user has explicitly opted in (1).
|
||||
$noindex_seo_delete = get_option( 'noindex_seo_config_delete_on_uninstall', 0 );
|
||||
// Read from both possible storage locations: the consolidated 3.0 option first, then
|
||||
// the legacy 2.x option as a fallback (covers the case where migration never ran).
|
||||
$noindex_seo_delete = 0;
|
||||
$noindex_seo_consolidated = get_option( 'noindex_seo_settings', array() );
|
||||
$noindex_seo_consolidated = is_array( $noindex_seo_consolidated ) ? $noindex_seo_consolidated : array();
|
||||
$noindex_seo_consolidated_cfg = $noindex_seo_consolidated['config'] ?? array();
|
||||
$noindex_seo_consolidated_cfg = is_array( $noindex_seo_consolidated_cfg ) ? $noindex_seo_consolidated_cfg : array();
|
||||
if ( isset( $noindex_seo_consolidated_cfg['delete_on_uninstall'] ) ) {
|
||||
$noindex_seo_delete = $noindex_seo_consolidated_cfg['delete_on_uninstall'] ? 1 : 0;
|
||||
} else {
|
||||
$noindex_seo_delete = get_option( 'noindex_seo_config_delete_on_uninstall', 0 );
|
||||
}
|
||||
|
||||
if ( ! $noindex_seo_delete ) {
|
||||
// Data is preserved. Nothing to do.
|
||||
exit;
|
||||
|
|
@ -60,14 +77,20 @@ $noindex_seo_contexts = array(
|
|||
);
|
||||
$noindex_seo_directives = array( 'noindex', 'nofollow', 'noarchive', 'nosnippet', 'noimageindex' );
|
||||
|
||||
// Delete all directive options for each context.
|
||||
// 3.0+ consolidated option (single row, autoloaded).
|
||||
delete_option( 'noindex_seo_settings' );
|
||||
|
||||
// Delete all legacy directive options for each context (2.x storage).
|
||||
// Kept for retrocompat: covers installs that upgrade from 2.x and then uninstall
|
||||
// even if the 3.0 migration did not run (e.g. plugin was never activated, only
|
||||
// installed). Each delete_option() is a no-op if the row does not exist.
|
||||
foreach ( $noindex_seo_contexts as $noindex_seo_context ) {
|
||||
foreach ( $noindex_seo_directives as $noindex_seo_directive ) {
|
||||
delete_option( $noindex_seo_directive . '_seo_' . $noindex_seo_context );
|
||||
}
|
||||
}
|
||||
|
||||
// Delete configuration options.
|
||||
// Delete legacy configuration options.
|
||||
delete_option( 'noindex_seo_config_seoplugins' );
|
||||
delete_option( 'noindex_seo_config_method' );
|
||||
delete_option( 'noindex_seo_config_granular' );
|
||||
|
|
@ -77,7 +100,7 @@ delete_option( 'noindex_seo_config_delete_on_uninstall' );
|
|||
// Delete transient cache.
|
||||
delete_transient( 'noindex_seo_options' );
|
||||
|
||||
// Clean up any leftover options (in case of partial uninstall).
|
||||
// Clean up any leftover options (in case of partial uninstall or pre-3.0 installs).
|
||||
global $wpdb;
|
||||
|
||||
// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
|
||||
|
|
@ -89,6 +112,16 @@ foreach ( $noindex_seo_directives as $noindex_seo_directive ) {
|
|||
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->options} WHERE option_name LIKE %s", $noindex_seo_directive . '_seo_%' ) );
|
||||
}
|
||||
|
||||
// Belt-and-suspenders: clean up the consolidated option one more time in case
|
||||
// delete_option() above failed due to a corrupted cache. The wildcard LIKE
|
||||
// matches both noindex_seo_settings and any stray noindex_seo_config_* rows.
|
||||
$wpdb->query(
|
||||
$wpdb->prepare(
|
||||
"DELETE FROM {$wpdb->options} WHERE option_name LIKE %s",
|
||||
'noindex_seo_%'
|
||||
)
|
||||
);
|
||||
|
||||
// Clean up transients.
|
||||
$wpdb->query(
|
||||
$wpdb->prepare(
|
||||
|
|
|
|||
Loading…
Reference in a new issue