-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restore "Save Plugin Settings" option (#146)
Allows plugin settings/data to be saved when the plugin is deleted and prevents deletions affecting Pro installs.
- Loading branch information
1 parent
99a38c5
commit e66b423
Showing
2 changed files
with
83 additions
and
55 deletions.
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
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 |
---|---|---|
@@ -1,70 +1,53 @@ | ||
<?php | ||
/** | ||
* Uninstall | ||
* | ||
* Runs when WP Simple Pay is deleted if "Save Settings" is unchecked in | ||
* "Settings > General > Advanced" | ||
* | ||
* @package SimplePay | ||
* @copyright Copyright (c) 2021, Sandhills Development, LLC | ||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License | ||
* @since unknown | ||
*/ | ||
|
||
// Exit if not uninstalling from WordPress. | ||
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { | ||
exit; | ||
} | ||
|
||
global $wpdb; | ||
|
||
$general = get_option( 'simpay_settings_general' ); | ||
|
||
// Check save settings option before removing everything | ||
if ( ! isset( $general['general_misc']['save_settings'] ) ) { | ||
|
||
|
||
// First remove the payment confirmation pages | ||
$success_page = $general['general']['success_page']; | ||
$failure_page = $general['general']['failure_page']; | ||
|
||
wp_delete_post( $success_page, true ); | ||
wp_delete_post( $failure_page, true ); | ||
|
||
// Remove main options | ||
delete_option( 'simpay_settings' ); | ||
// Do nothing if settings should be saved. | ||
$settings = get_option( 'simpay_settings' ); | ||
$save_settings = isset( $settings[ 'save_settings' ] ) | ||
? $settings['save_settings'] | ||
: 'yes'; | ||
|
||
// Remove misc options | ||
delete_option( 'simpay_use_php_sessions' ); | ||
delete_option( 'simpay_dismiss_ssl' ); | ||
delete_option( 'simpay_dismiss_dropping_php53_bitcoin' ); | ||
|
||
// Remove settings options | ||
delete_option( 'simpay_settings_general' ); | ||
delete_option( 'simpay_settings_keys' ); | ||
delete_option( 'simpay_settings_display' ); | ||
delete_option( 'simpay_settings_shipping_billing' ); | ||
|
||
// Remove legacy options | ||
delete_option( 'simpay_preview_form_id' ); | ||
if ( 'yes' === $save_settings ) { | ||
return; | ||
} | ||
|
||
// Delete form posts. | ||
$wpdb->query( "DELETE FROM {$wpdb->posts} WHERE post_type IN ( 'simple-pay' );" ); | ||
global $wpdb; | ||
|
||
// Delete forms postmeta. | ||
$wpdb->query( "DELETE meta FROM {$wpdb->postmeta} meta LEFT JOIN {$wpdb->posts} posts ON posts.ID = meta.post_id WHERE posts.ID IS NULL;" ); | ||
// Delete pages. | ||
$success_page = isset( $settings['success_page'] ) | ||
? $settings['success_page'] | ||
: ''; | ||
|
||
} | ||
$failure_page = isset( $settings['failure_page'] ) | ||
? $settings['failure_page'] | ||
: ''; | ||
|
||
// Check if we need to remove legacy settings | ||
$settings = get_option( 'sc_settings' ); | ||
$cancelled_page = isset( $settings['cancelled_page'] ) | ||
? $settings['cancelled_page'] | ||
: ''; | ||
|
||
if ( ! isset( $settings['uninstall_save_settings'] ) || 1 != $settings['uninstall_save_settings'] ) { | ||
wp_delete_post( $success_page, true ); | ||
wp_delete_post( $failure_page, true ); | ||
wp_delete_post( $cancelled_page, true ); | ||
|
||
// Remove options used by current version of the plugin. | ||
delete_option( 'sc_settings' ); | ||
delete_option( 'sc_set_defaults' ); | ||
delete_option( 'sc_had_upgrade' ); | ||
delete_option( 'sc_upgrade_has_run' ); | ||
delete_option( 'sc_show_admin_install_notice' ); | ||
delete_option( 'sc_show_api_notice' ); | ||
// Delete options. | ||
$wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE 'simpay\_%'" ); | ||
|
||
// Remove options that may be hanging around from old versions. | ||
delete_option( 'sc_settings_master' ); | ||
delete_option( 'sc_settings_default' ); | ||
delete_option( 'sc_settings_keys' ); | ||
delete_option( 'sc_has_run' ); | ||
delete_option( 'sc_version' ); | ||
delete_option( 'sc_settings_licenses' ); | ||
delete_option( 'sc_licenses' ); | ||
delete_option( 'sc_license' ); | ||
} | ||
// Delete Payment Forms. | ||
$wpdb->query( "DELETE FROM {$wpdb->posts} WHERE post_type = 'simple-pay'" ); | ||
$wpdb->query( "DELETE meta FROM {$wpdb->postmeta} meta LEFT JOIN {$wpdb->posts} posts ON posts.ID = meta.post_id WHERE posts.ID IS NULL;" ); |