From 8d8030f70ea4e5e9e162e1c13b13ace49649570e Mon Sep 17 00:00:00 2001 From: andrewshuba Date: Wed, 15 May 2019 14:09:54 +0300 Subject: [PATCH 1/4] - fix user cache delete - delete options - delete um upload folder --- uninstall.php | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/uninstall.php b/uninstall.php index 9651399d..f6bef013 100644 --- a/uninstall.php +++ b/uninstall.php @@ -27,6 +27,10 @@ require_once plugin_dir_path( __FILE__ ) . 'includes/class-init.php'; $delete_options = UM()->options()->get( 'uninstall_on_delete' ); if ( ! empty( $delete_options ) ) { + //remove uploads + $upl_folder = UM()->files()->upload_basedir; + UM()->files()->remove_dir( $upl_folder ); + //remove core pages foreach ( UM()->config()->core_pages as $page_key => $page_value ) { $page_id = UM()->options()->get( UM()->options()->get_core_page_id( $page_key ) ); @@ -50,9 +54,22 @@ if ( ! empty( $delete_options ) ) { 'numberposts' => -1 ) ); - foreach ( $um_posts as $um_post ) + foreach ( $um_posts as $um_post ){ + delete_option( 'um_existing_rows_' . $um_post->ID ); + delete_option( 'um_form_rowdata_' . $um_post->ID ); wp_delete_post( $um_post->ID, 1 ); + } + delete_option( 'um_first_activation_date' ); + delete_option( 'um_role_subscriber_meta' ); + delete_option( 'um_role_author_meta' ); + delete_option( 'um_role_contributor_meta' ); + delete_option( 'um_role_editor_meta' ); + delete_option( 'um_role_administrator_meta' ); + delete_option( 'um_roles' ); + delete_option( 'um_role_um_user_meta' ); + delete_option( 'um_fields' ); + delete_option( 'um_roles' ); delete_option( 'um_options' ); delete_option( 'um_version' ); delete_option( 'um_is_installed' ); @@ -69,11 +86,8 @@ if ( ! empty( $delete_options ) ) { delete_option( 'widget_um_search_widget' ); delete_option( '__ultimatemember_sitekey' ); - foreach ( wp_load_alloptions() as $k => $v ) { - if ( substr( $k, 0, 18 ) == 'um_cache_userdata_' ) - delete_option( $k ); - } - + //remove all users cache + UM()->user()->remove_cache_all_users(); global $wpdb; From 035cdb91960e361b10935e3d31bfadd94372758a Mon Sep 17 00:00:00 2001 From: andrewshuba Date: Thu, 16 May 2019 12:44:02 +0300 Subject: [PATCH 2/4] - remove user role meta for custom roles --- uninstall.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/uninstall.php b/uninstall.php index f6bef013..1c3994d4 100644 --- a/uninstall.php +++ b/uninstall.php @@ -30,7 +30,7 @@ if ( ! empty( $delete_options ) ) { //remove uploads $upl_folder = UM()->files()->upload_basedir; UM()->files()->remove_dir( $upl_folder ); - + //remove core pages foreach ( UM()->config()->core_pages as $page_key => $page_value ) { $page_id = UM()->options()->get( UM()->options()->get_core_page_id( $page_key ) ); @@ -60,6 +60,14 @@ if ( ! empty( $delete_options ) ) { wp_delete_post( $um_post->ID, 1 ); } + //remove user role meta + $role_keys = get_option( 'um_roles' ); + if ( $role_keys ) { + foreach ( $role_keys as $role_key ) { + delete_option( 'um_role_' . $role_key . '_meta' ); + } + } + delete_option( 'um_first_activation_date' ); delete_option( 'um_role_subscriber_meta' ); delete_option( 'um_role_author_meta' ); From 5bc09b2d4b904c28d05e01c1b412b7d0c659becd Mon Sep 17 00:00:00 2001 From: andrewshuba Date: Thu, 16 May 2019 15:02:41 +0300 Subject: [PATCH 3/4] - remove all tables in database from extensions --- uninstall.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/uninstall.php b/uninstall.php index 1c3994d4..8fb0472d 100644 --- a/uninstall.php +++ b/uninstall.php @@ -30,7 +30,7 @@ if ( ! empty( $delete_options ) ) { //remove uploads $upl_folder = UM()->files()->upload_basedir; UM()->files()->remove_dir( $upl_folder ); - + //remove core pages foreach ( UM()->config()->core_pages as $page_key => $page_value ) { $page_id = UM()->options()->get( UM()->options()->get_core_page_id( $page_key ) ); @@ -123,4 +123,22 @@ if ( ! empty( $delete_options ) ) { meta_key = 'synced_profile_photo' OR meta_key = 'full_name'" ); + + //remove all tables from extensions + $all_tables = "SHOW TABLES LIKE '{$wpdb->prefix}um\_%'"; + $results = $wpdb->get_results( $all_tables ); + if( $results ){ + foreach( $results as $index => $value ) { + foreach( $value as $table_name ) { + $wpdb->query( "DROP TABLE IF EXISTS $table_name" ); + } + } + } + + //remove options from extensions + delete_option( 'um_messaging_last_version_upgrade' ); + delete_option( 'um_messaging_version' ); + delete_option( 'ultimatemember_messaging_db2' ); + + } \ No newline at end of file From a0cacee1ae18d7576c4240a89b49a964fd0746cd Mon Sep 17 00:00:00 2001 From: andrewshuba Date: Wed, 29 May 2019 18:42:17 +0300 Subject: [PATCH 4/4] - remove all UM extensions data from DB --- uninstall.php | 159 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 130 insertions(+), 29 deletions(-) diff --git a/uninstall.php b/uninstall.php index 8fb0472d..964758cb 100644 --- a/uninstall.php +++ b/uninstall.php @@ -49,8 +49,16 @@ if ( ! empty( $delete_options ) ) { 'post_type' => array( 'um_form', 'um_directory', - 'um_role' + 'um_role', + 'um_private_content', + 'um_mailchimp', + 'um_profile_tabs', + 'um_social_login', + 'um_review', + 'um_frontend_posting', + 'um_notice' ), + 'post_status' => array( 'publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', 'trash' ), 'numberposts' => -1 ) ); @@ -68,30 +76,6 @@ if ( ! empty( $delete_options ) ) { } } - delete_option( 'um_first_activation_date' ); - delete_option( 'um_role_subscriber_meta' ); - delete_option( 'um_role_author_meta' ); - delete_option( 'um_role_contributor_meta' ); - delete_option( 'um_role_editor_meta' ); - delete_option( 'um_role_administrator_meta' ); - delete_option( 'um_roles' ); - delete_option( 'um_role_um_user_meta' ); - delete_option( 'um_fields' ); - delete_option( 'um_roles' ); - delete_option( 'um_options' ); - delete_option( 'um_version' ); - delete_option( 'um_is_installed' ); - delete_option( 'um_core_forms' ); - delete_option( 'um_core_directories' ); - delete_option( 'um_last_version_upgrade' ); - delete_option( 'um_first_setup_roles' ); - delete_option( 'um_hashed_passwords_fix' ); - delete_option( 'um_cached_users_queue' ); - delete_option( 'um_options-transients' ); - delete_option( 'um_cached_role_admin' ); - delete_option( 'um_cached_role_member' ); - delete_option( 'um_cache_fonticons' ); - delete_option( 'widget_um_search_widget' ); delete_option( '__ultimatemember_sitekey' ); //remove all users cache @@ -99,6 +83,16 @@ if ( ! empty( $delete_options ) ) { global $wpdb; + //remove extensions core pages + $ext_pages = $wpdb->get_results( " + SELECT post_id + FROM {$wpdb->postmeta} + WHERE meta_key = '_um_core' + ", ARRAY_A ); + + foreach ( $ext_pages as $page_id ) { + wp_delete_post( $page_id['post_id'], 1 ); + } $wpdb->query( "DELETE @@ -121,7 +115,18 @@ if ( ! empty( $delete_options ) ) { meta_key = '_completed' OR meta_key = '_cannot_add_review' OR meta_key = 'synced_profile_photo' OR - meta_key = 'full_name'" + meta_key = 'full_name' OR + meta_key = '_reviews' OR + meta_key = '_reviews_compound' OR + meta_key = '_reviews_total' OR + meta_key = '_reviews_avg'" + ); + + $wpdb->query( + "DELETE + FROM {$wpdb->postmeta} + WHERE meta_key LIKE '_um%' OR + meta_key LIKE 'um%'" ); //remove all tables from extensions @@ -130,15 +135,111 @@ if ( ! empty( $delete_options ) ) { if( $results ){ foreach( $results as $index => $value ) { foreach( $value as $table_name ) { + $um_groups_members = $wpdb->prefix.'um_groups_members'; + if( $table_name == $um_groups_members ){ + $wpdb->query( " + DELETE posts, term_rel, pmeta, terms, tax, commetns + FROM {$wpdb->posts} posts + LEFT JOIN {$wpdb->term_relationships} term_rel + ON (posts.ID = term_rel.object_id) + LEFT JOIN {$wpdb->postmeta} pmeta + ON (posts.ID = pmeta.post_id) + LEFT JOIN {$wpdb->terms} terms + ON (term_rel.term_taxonomy_id = terms.term_id) + LEFT JOIN {$wpdb->term_taxonomy} tax + ON (term_rel.term_taxonomy_id = tax.term_taxonomy_id) + LEFT JOIN {$wpdb->comments} commetns + ON (commetns.comment_post_ID = posts.ID) + WHERE posts.post_type = 'um_groups' OR posts.post_type = 'um_groups_discussion'" + ); + } $wpdb->query( "DROP TABLE IF EXISTS $table_name" ); } } } //remove options from extensions - delete_option( 'um_messaging_last_version_upgrade' ); - delete_option( 'um_messaging_version' ); - delete_option( 'ultimatemember_messaging_db2' ); + //user photos + $um_user_photos = get_posts( array( + 'post_type' => array( + 'um_user_photos' + ), + 'post_status' => array( 'publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', 'trash' ), + 'numberposts' => -1 + ) ); + if( $um_user_photos ) { + foreach ( $um_user_photos as $um_user_photo ) { + $attachments = get_attached_media( 'image', $um_user_photo->ID ); + foreach ( $attachments as $attachment ) { + wp_delete_attachment( $attachment->ID, 1 ); + } + wp_delete_post( $um_user_photo->ID, 1 ); + } + } + //user notes + $um_notes = get_posts( array( + 'post_type' => array( + 'um_notes' + ), + 'post_status' => array( 'publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', 'trash' ), + 'numberposts' => -1 + ) ); + if( $um_notes ){ + foreach ( $um_notes as $um_note ){ + $attachments = get_attached_media( 'image', $um_note->ID ); + foreach ( $attachments as $attachment ){ + wp_delete_attachment( $attachment->ID, 1 ); + } + wp_delete_post( $um_note->ID, 1 ); + } + } + //user tags + $wpdb->query( " + DELETE tax, terms + FROM {$wpdb->term_taxonomy} tax + LEFT JOIN {$wpdb->terms} terms + ON (tax.term_taxonomy_id = terms.term_id) + WHERE tax.taxonomy = 'um_user_tag'" + ); + + //mailchimp + $mailchimp_log = UM()->files()->upload_basedir . 'mailchimp.log'; + if ( file_exists( $mailchimp_log ) ) { + unlink( $mailchimp_log ); + } + + $um_options = $wpdb->get_results( + "SELECT option_name + FROM {$wpdb->options} + WHERE option_name LIKE '_um%' OR + option_name LIKE 'um_%' OR + option_name LIKE 'widget_um%' OR + option_name LIKE 'ultimatemember_%'" ); + + foreach( $um_options as $um_option ) { + delete_option( $um_option->option_name ); + } + + //social activity + $um_activities = get_posts( array( + 'post_type' => array( + 'um_activity' + ), + 'post_status' => array( 'publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', 'trash' ), + 'numberposts' => -1 + ) ); + foreach ( $um_activities as $um_activity ) { + $image = get_post_meta( $um_activity->ID, '_photo', true ); + if( $image ){ + $user_id = get_post_meta( $um_activity->ID, '_user_id', true ); + $upload_dir = wp_upload_dir(); + $image_path = $upload_dir['basedir'] . '/ultimatemember/' . $user_id . '/' . $image; + if ( file_exists( $image_path ) ) { + unlink( $image_path ); + } + } + wp_delete_post( $um_activity->ID, 1 ); + } } \ No newline at end of file