-
Notifications
You must be signed in to change notification settings - Fork 156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: Uninstall distributor #540
Open
dinhtungdu
wants to merge
60
commits into
develop
Choose a base branch
from
fix/349
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+279
−1
Open
Changes from 57 commits
Commits
Show all changes
60 commits
Select commit
Hold shift + click to select a range
863ab95
feat: add uninstall script
dinhtungdu 00b3768
feat: update uninstall script comment
dinhtungdu 27d45b5
Merge branch 'develop' into fix/349
ravinderk b5e16da
Merge branch 'develop' into fix/349
ravinderk 69ff81e
Merge branch 'develop' into fix/349
ravinderk c2fd377
format: add file doc tags
ravinderk 620f8ef
fix: add prefix to transient name
ravinderk 0f8eaec
refactor: remove unnecessary code
ravinderk 07d1d3b
feat: flush cache
ravinderk f79234e
refactor: remove unnecessary check
ravinderk 4d1dfad
format: improve code formatting
ravinderk fcd4299
format: disable phpcs for uninstall.php
ravinderk ab9e708
Merge branch 'develop' into fix/349
ravinderk 1f5caf0
fix: define global variable
ravinderk f8b5fb9
feat: update last cache update date
ravinderk e62c579
feat: delete comment and term data
ravinderk 74ceb30
fix: remove as from sql query
ravinderk 034891e
fix: resolve sql query issue
ravinderk 65a69b0
fix: delete only connections and options data
ravinderk 3d02f1d
format: improve code formatting
ravinderk 543be5e
feat: delete plugin data from post meta table
ravinderk 910ff84
feat: merge sql query
ravinderk 7c7856f
Merge branch 'develop' into fix/349
ravinderk 12c1485
Merge branch 'develop' into fix/349
ravinderk bb7df21
feat: dispaly modal when click on plugin deactivaiton link
ravinderk 0ede961
feat: update deacrtivation modal content
ravinderk 71fdbd5
fix: deactivate modal should not display on sub sites
ravinderk d9b4b57
doc: update message in modal
ravinderk a149f14
format: remove extra line
ravinderk 09f07b5
format: improve code formatting
ravinderk 30d31b4
Merge branch 'develop' into fix/349
ravinderk 76eb110
Merge branch 'develop' into fix/349
ravinderk 8395719
Update uninstall.php
ravinderk d10a2f7
add: escape data for javascript
38c8d15
change: use function to regiter deaactivatin modal
fdae543
delete data for each sub-site when it is a network
faisal-alvi 393ccdb
Delete only subscription data; keeping other posts w/meta
faisal-alvi 2890ce9
Merge branch 'develop' into fix/349
faisal-alvi 2506645
update the popup notice for more clarity
faisal-alvi 45786f1
improve query; remove meta first and then posts (only subc)
faisal-alvi 1188c05
remove unnec word
faisal-alvi 27ab735
Merge branch 'develop' into fix/349
Sidsector9 2551260
Merge branch 'develop' into fix/349
Sidsector9 9854aed
Merge branch 'develop' into fix/349
Sidsector9 ff2b790
Merge branch 'develop' into fix/349
peterwilsoncc f2f9b73
suggestions implemented
faisal-alvi e0530b9
improvise the code
faisal-alvi b96e12a
coding standards
faisal-alvi ef103dd
add semicolon to help non-tech users
faisal-alvi 7826ef2
fix the issue - options are not deleting in multisite network
faisal-alvi 4f480a7
Merge branch 'develop' into fix/349
faisal-alvi 6923237
Apply suggestions from code review
faisal-alvi 15e060d
pass `option_name` in `wp_cache_delete_multiple` for `options`
faisal-alvi 39830c6
pass `site_id:meta_key` in `wp_cache_delete_multiple` for `site-options`
faisal-alvi 548c8a1
include site transient keys to delete
faisal-alvi 2aa68df
phpcs: fixes and ignores
faisal-alvi 8444087
Site transients can be used on single sites too.
faisal-alvi 49aa191
Merge branch 'develop' into fix/349
faisal-alvi 64621e9
Merge branch 'develop' into fix/349
faisal-alvi a46f0b5
include uninstall.php to release version
faisal-alvi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,5 @@ tests/cypress/reports | |
tests/cypress/downloads | ||
|
||
distributor.zip | ||
|
||
.github/phpcs-report.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,205 @@ | ||
<?php | ||
/** | ||
* Distributor uninstall script. | ||
* | ||
* @package distributor | ||
* @since x.x.x | ||
*/ | ||
|
||
// phpcs:disable WordPress.DB.DirectDatabaseQuery, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber | ||
|
||
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { | ||
die; | ||
} | ||
|
||
/* | ||
* Only remove ALL data if DT_REMOVE_ALL_DATA constant is set to true in user's | ||
* wp-config.php. This is to prevent data loss when deleting the plugin from the backend | ||
* and to ensure only the site owner can perform this action. | ||
*/ | ||
if ( defined( 'DT_REMOVE_ALL_DATA' ) && true === DT_REMOVE_ALL_DATA ) { | ||
peterwilsoncc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
global $wpdb; | ||
|
||
/** | ||
* Function to delete all relevant data from the site. | ||
*/ | ||
function dt_delete_data() { | ||
global $wpdb; | ||
|
||
// Delete post meta and posts of type 'dt_subscription'. | ||
$subscription_post_ids = $wpdb->get_col( | ||
$wpdb->prepare( | ||
"SELECT ID FROM $wpdb->posts WHERE post_type = %s", | ||
'dt_subscription' | ||
) | ||
); | ||
|
||
if ( ! empty( $subscription_post_ids ) ) { | ||
$ids_string = implode( ',', array_map( 'intval', $subscription_post_ids ) ); | ||
|
||
// Delete subscription meta. | ||
$wpdb->query( | ||
"DELETE FROM $wpdb->postmeta WHERE post_id IN ($ids_string)" | ||
); | ||
|
||
// Delete subscription posts. | ||
$wpdb->query( | ||
$wpdb->prepare( | ||
"DELETE FROM $wpdb->posts WHERE ID IN (%s)", | ||
$ids_string | ||
) | ||
); | ||
|
||
// Clear the post cache. | ||
wp_cache_set_posts_last_changed(); | ||
wp_cache_delete_multiple( $subscription_post_ids, 'posts' ); | ||
wp_cache_delete_multiple( $subscription_post_ids, 'post_meta' ); | ||
} | ||
|
||
// Delete relevant options from the options table. | ||
delete_site_options(); | ||
} | ||
|
||
/** | ||
* Delete all relevant options from the options table. | ||
*/ | ||
function delete_site_options() { | ||
global $wpdb; | ||
|
||
$option_prefixes = array( | ||
'dt_', | ||
'_transient_dt_', | ||
'_transient_timeout_dt_', | ||
); | ||
|
||
peterwilsoncc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Site transients can be used on single sites too. | ||
// See https://github.com/10up/distributor/pull/540#discussion_r1759587692 | ||
if ( ! is_multisite() ) { | ||
$option_prefixes = array_merge( | ||
$option_prefixes, | ||
array( | ||
'_site_transient_dt_', | ||
'_site_transient_timeout_dt_', | ||
) | ||
); | ||
} | ||
|
||
// Prepare the WHERE clause for the options table. | ||
$where_clause = implode( ' OR ', array_fill( 0, count( $option_prefixes ), 'option_name LIKE %s' ) ); | ||
|
||
// Prepare the query. | ||
$query = $wpdb->prepare( | ||
sprintf( | ||
"SELECT option_id, option_name FROM $wpdb->options WHERE %s;", | ||
$where_clause | ||
), | ||
array_map( | ||
function( $prefix ) use ( $wpdb ) { | ||
return $wpdb->esc_like( $prefix ) . '%'; | ||
}, | ||
$option_prefixes | ||
) | ||
); | ||
|
||
// Fetch the options to delete. | ||
$options_to_delete = $wpdb->get_results( $query, ARRAY_A ); | ||
|
||
if ( ! empty( $options_to_delete ) ) { | ||
// Collect IDs from fetched options. | ||
$ids = array_column( $options_to_delete, 'option_id' ); | ||
$ids_string = implode( ',', array_map( 'intval', $ids ) ); | ||
|
||
// Delete the options using the retrieved IDs. | ||
$wpdb->query( | ||
$wpdb->prepare( | ||
"DELETE FROM $wpdb->options WHERE option_id IN ($ids_string)" | ||
) | ||
); | ||
|
||
// Flush the options cache. | ||
$option_names = array_column( $options_to_delete, 'option_name' ); | ||
wp_cache_delete_multiple( $option_names, 'options' ); | ||
|
||
// Flush the alloptions cache. | ||
wp_cache_delete( 'alloptions', 'options' ); | ||
} | ||
} | ||
|
||
/** | ||
* Delete all relevant options from the sitemeta table (multisite only). | ||
*/ | ||
function delete_sitemeta_options() { | ||
global $wpdb; | ||
|
||
$option_prefixes = array( | ||
'dt_', | ||
'_site_transient_dt_', | ||
'_site_transient_timeout_dt_', | ||
); | ||
|
||
// Prepare the WHERE clause for the sitemeta table. | ||
$where_clause = implode( ' OR ', array_fill( 0, count( $option_prefixes ), 'meta_key LIKE %s' ) ); | ||
|
||
$site_id = get_current_network_id(); | ||
|
||
$query = $wpdb->prepare( | ||
sprintf( | ||
"SELECT meta_id, meta_key FROM $wpdb->sitemeta WHERE site_id = %%d AND (%s);", | ||
$where_clause | ||
), | ||
array_merge( | ||
[ $site_id ], | ||
array_map( | ||
function( $prefix ) use ( $wpdb ) { | ||
return $wpdb->esc_like( $prefix ) . '%'; | ||
}, | ||
$option_prefixes | ||
) | ||
) | ||
); | ||
|
||
// Fetch the sitemeta to delete. | ||
$sitemeta_to_delete = $wpdb->get_results( $query, ARRAY_A ); | ||
|
||
if ( ! empty( $sitemeta_to_delete ) ) { | ||
// Collect IDs from fetched options. | ||
$ids = array_column( $sitemeta_to_delete, 'meta_id' ); | ||
$ids_string = implode( ',', array_map( 'intval', $ids ) ); | ||
|
||
// Delete the sitemeta using the retrieved IDs. | ||
$wpdb->query( | ||
$wpdb->prepare( | ||
"DELETE FROM $wpdb->sitemeta WHERE meta_id IN ($ids_string)" | ||
) | ||
); | ||
|
||
// Flush the site options cache. | ||
$key_names = array_column( $sitemeta_to_delete, 'meta_key' ); | ||
$key_names = array_map( | ||
function( $key ) use ( $site_id ) { | ||
return $site_id . ':' . $key; | ||
}, | ||
$key_names | ||
); | ||
wp_cache_delete_multiple( $key_names, 'site-options' ); | ||
} | ||
} | ||
|
||
// Check if it's a multisite installation. | ||
if ( is_multisite() ) { | ||
// Loop through each site in the network. | ||
$sites = get_sites(); | ||
foreach ( $sites as $site ) { | ||
switch_to_blog( $site->blog_id ); | ||
dt_delete_data(); | ||
restore_current_blog(); | ||
} | ||
|
||
// Delete network-wide sitemeta options. | ||
delete_sitemeta_options(); | ||
} else { | ||
// Single site. | ||
dt_delete_data(); | ||
} | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
File needs to be added to this block of code
distributor/webpack.config.release.js
Lines 11 to 29 in c27d99a