Delete user meta data on uninstall

This commit is contained in:
Shiva Poudel 2018-02-11 16:25:30 +05:45
parent 3ea8629b6e
commit 6bad005c5b
2 changed files with 18 additions and 16 deletions

View File

@ -28,8 +28,8 @@
<rule ref="WordPress">
<exclude name="WordPress.VIP.DirectDatabaseQuery.NoCaching" />
<exclude name="WordPress.VIP.DirectDatabaseQuery.SchemaChange" />
<exclude name="WordPress.VIP.DirectDatabaseQuery.DirectQuery" />
<exclude name="WordPress.VIP.DirectDatabaseQuery.SchemaChange" />
<exclude name="WordPress.VIP.FileSystemWritesDisallow.file_ops_fwrite" />
<exclude name="WordPress.VIP.OrderByRand" />
<exclude name="WordPress.VIP.RestrictedFunctions" />

View File

@ -4,15 +4,11 @@
*
* Uninstalling WooCommerce deletes user roles, pages, tables, and options.
*
* @author WooCommerce
* @category Core
* @package WooCommerce/Uninstaller
* @version 2.3.0
* @package WooCommerce\Uninstaller
* @version 2.3.0
*/
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit;
}
defined( 'WP_UNINSTALL_PLUGIN' ) || exit;
global $wpdb, $wp_version;
@ -28,8 +24,9 @@ wp_clear_scheduled_hook( 'woocommerce_tracker_send_event' );
* and to ensure only the site owner can perform this action.
*/
if ( defined( 'WC_REMOVE_ALL_DATA' ) && true === WC_REMOVE_ALL_DATA ) {
include_once dirname( __FILE__ ) . '/includes/class-wc-install.php';
// Roles + caps.
include_once( dirname( __FILE__ ) . '/includes/class-wc-install.php' );
WC_Install::remove_roles();
// Pages.
@ -71,9 +68,14 @@ if ( defined( 'WC_REMOVE_ALL_DATA' ) && true === WC_REMOVE_ALL_DATA ) {
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}woocommerce_order_items" );
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}woocommerce_order_itemmeta" );
// Delete terms if > WP 4.2 (term splitting was added in 4.2)
// Delete user meta data.
foreach ( array( 'wc_keys_per_page', 'wc_webhooks_per_page' ) as $meta_key ) {
delete_metadata( 'user', 0, $meta_key, '', true );
}
// Delete terms if > WP 4.2 (term splitting was added in 4.2).
if ( version_compare( $wp_version, '4.2', '>=' ) ) {
// Delete term taxonomies
// Delete term taxonomies.
foreach ( array( 'product_cat', 'product_tag', 'product_shipping_class', 'product_type' ) as $taxonomy ) {
$wpdb->delete(
$wpdb->term_taxonomy,
@ -83,7 +85,7 @@ if ( defined( 'WC_REMOVE_ALL_DATA' ) && true === WC_REMOVE_ALL_DATA ) {
);
}
// Delete term attributes
// Delete term attributes.
foreach ( $wc_attributes as $taxonomy ) {
$wpdb->delete(
$wpdb->term_taxonomy,
@ -93,18 +95,18 @@ if ( defined( 'WC_REMOVE_ALL_DATA' ) && true === WC_REMOVE_ALL_DATA ) {
);
}
// Delete orphan relationships
// Delete orphan relationships.
$wpdb->query( "DELETE tr FROM {$wpdb->term_relationships} tr LEFT JOIN {$wpdb->posts} posts ON posts.ID = tr.object_id WHERE posts.ID IS NULL;" );
// Delete orphan terms
// Delete orphan terms.
$wpdb->query( "DELETE t FROM {$wpdb->terms} t LEFT JOIN {$wpdb->term_taxonomy} tt ON t.term_id = tt.term_id WHERE tt.term_id IS NULL;" );
// Delete orphan term meta
// Delete orphan term meta.
if ( ! empty( $wpdb->termmeta ) ) {
$wpdb->query( "DELETE tm FROM {$wpdb->termmeta} tm LEFT JOIN {$wpdb->term_taxonomy} tt ON tm.term_id = tt.term_id WHERE tt.term_id IS NULL;" );
}
}
// Clear any cached data that has been removed
// Clear any cached data that has been removed.
wp_cache_flush();
}