v3.7.1
This commit is contained in:
parent
54122d3d95
commit
ba2c697d36
1 changed files with 374 additions and 139 deletions
|
|
@ -98,44 +98,40 @@ delete_option( 'noindex_seo_config_granular' );
|
|||
delete_option( 'noindex_seo_config_version' );
|
||||
delete_option( 'noindex_seo_config_delete_on_uninstall' );
|
||||
|
||||
// Delete transient cache.
|
||||
// Delete transient caches (through the API so persistent object caches are
|
||||
// cleared too; the SQL wildcard below only reaches database-stored rows).
|
||||
delete_transient( 'noindex_seo_options' );
|
||||
delete_transient( 'noindex_seo_import_counts' );
|
||||
|
||||
// Clean up any leftover options (in case of partial uninstall or pre-3.0 installs).
|
||||
/**
|
||||
* WordPress database abstraction object.
|
||||
*
|
||||
* @var wpdb $wpdb
|
||||
*/
|
||||
global $wpdb;
|
||||
|
||||
// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
|
||||
// Direct database queries are necessary here for complete cleanup during uninstall.
|
||||
// This is a DELETE operation (not SELECT), so caching is not applicable.
|
||||
// Using wildcards with delete_option() is not possible, requiring direct SQL.
|
||||
// Clean up all directive-related options (noindex, nofollow, noarchive, nosnippet, noimageindex).
|
||||
// Direct database queries are necessary here for complete cleanup during uninstall:
|
||||
// delete_option() has no wildcard form. These are DELETE operations (not SELECT),
|
||||
// so caching is not applicable. Prefixes are LIKE-escaped (the "_" in them is a
|
||||
// LIKE wildcard otherwise) and the table name goes through the %i placeholder.
|
||||
//
|
||||
// Prefixes: every directive's legacy options (noindex_seo_*, nofollow_seo_*, ...),
|
||||
// the consolidated option plus any stray noindex_seo_config_* rows (belt-and-
|
||||
// suspenders in case delete_option() above failed on a corrupted cache), and
|
||||
// the plugin's transients.
|
||||
$noindex_seo_option_prefixes = array( 'noindex_seo_', '_transient_noindex_seo_', '_transient_timeout_noindex_seo_' );
|
||||
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_%' ) );
|
||||
$noindex_seo_option_prefixes[] = $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(
|
||||
"DELETE FROM {$wpdb->options} WHERE option_name LIKE %s",
|
||||
'_transient_noindex_seo_%'
|
||||
)
|
||||
);
|
||||
$wpdb->query(
|
||||
$wpdb->prepare(
|
||||
"DELETE FROM {$wpdb->options} WHERE option_name LIKE %s",
|
||||
'_transient_timeout_noindex_seo_%'
|
||||
)
|
||||
);
|
||||
foreach ( array_unique( $noindex_seo_option_prefixes ) as $noindex_seo_option_prefix ) {
|
||||
$noindex_seo_sql = $wpdb->prepare( 'DELETE FROM %i WHERE option_name LIKE %s', $wpdb->options, $wpdb->esc_like( $noindex_seo_option_prefix ) . '%' );
|
||||
if ( null !== $noindex_seo_sql ) {
|
||||
$wpdb->query( $noindex_seo_sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- prepared on the previous line.
|
||||
}
|
||||
}
|
||||
// phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
|
||||
|
||||
// Clean up post meta (granular control). The 3.6.0 value directives store
|
||||
// their per-post values under the same prefix.
|
||||
|
|
@ -153,28 +149,18 @@ $noindex_seo_meta_keys = array(
|
|||
'_noindex_seo_unavailable_after',
|
||||
);
|
||||
|
||||
foreach ( $noindex_seo_meta_keys as $noindex_seo_meta_key ) {
|
||||
$wpdb->query(
|
||||
$wpdb->prepare(
|
||||
"DELETE FROM {$wpdb->postmeta} WHERE meta_key = %s",
|
||||
$noindex_seo_meta_key
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Clean up term meta (per-term granular control, added in 3.0.2).
|
||||
// delete_term_meta() cannot be used here because term IDs are not known at
|
||||
// uninstall time and there is no built-in "delete all term meta by key".
|
||||
// $wpdb->termmeta is set by WP when the table exists; older WP versions
|
||||
// (pre-4.4) did not have it, hence the property_exists() check.
|
||||
if ( property_exists( $wpdb, 'termmeta' ) && $wpdb->termmeta ) {
|
||||
// Clean up post meta and term meta (per-term granular control, added in 3.0.2).
|
||||
// One prepared DELETE per key and table instead of delete_metadata( ..., true ):
|
||||
// the metadata API loads every matching meta ID into PHP and fires the delete
|
||||
// actions with the full arrays, which does not scale for _noindex_seo_override
|
||||
// (written on every meta box / Quick Edit save) on large sites.
|
||||
// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
|
||||
foreach ( array( $wpdb->postmeta, $wpdb->termmeta ) as $noindex_seo_meta_table ) {
|
||||
foreach ( $noindex_seo_meta_keys as $noindex_seo_meta_key ) {
|
||||
$wpdb->query(
|
||||
$wpdb->prepare(
|
||||
"DELETE FROM {$wpdb->termmeta} WHERE meta_key = %s",
|
||||
$noindex_seo_meta_key
|
||||
)
|
||||
);
|
||||
$noindex_seo_sql = $wpdb->prepare( 'DELETE FROM %i WHERE meta_key = %s', $noindex_seo_meta_table, $noindex_seo_meta_key );
|
||||
if ( null !== $noindex_seo_sql ) {
|
||||
$wpdb->query( $noindex_seo_sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- prepared on the previous line.
|
||||
}
|
||||
}
|
||||
}
|
||||
// phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
|
||||
|
|
|
|||
Loading…
Reference in a new issue