diff --git a/includes/core/settings/register-general.php b/includes/core/settings/register-general.php index 9890d339..c338f024 100644 --- a/includes/core/settings/register-general.php +++ b/includes/core/settings/register-general.php @@ -79,6 +79,7 @@ function register_subsections( $subsections ) { */ function register_settings( $settings ) { register_currency_settings( $settings ); + register_advanced_settings( $settings ); } add_action( 'simpay_register_settings', __NAMESPACE__ . '\\register_settings' ); @@ -198,3 +199,47 @@ function register_currency_settings( $settings ) { ) ); } + +/** + * Registers advanced settings. + * + * @since 4.1.0 + * + * @param \SimplePay\Core\Settings\Setting_Collection $settings Settings collection. + */ +function register_advanced_settings( $settings ) { + // Save Settings. + $settings->add( + new Settings\Setting_Checkbox( + array( + 'id' => 'save_settings', + 'section' => 'general', + 'subsection' => 'advanced', + 'label' => esc_html_x( + 'Save Plugin Settings', + 'setting label', + 'stripe' + ), + 'input_label' => esc_html_x( + 'Save plugin settings', + 'setting input label', + 'stripe' + ), + 'value' => simpay_get_setting( 'save_settings', 'yes' ), + 'description' => wpautop( + esc_html( + sprintf( + /* translators: %s Plugin name. */ + __( + 'If UN-checked, all %s plugin data will be removed when the plugin is deleted. However, your data saved with Stripe will not be deleted.', + 'stripe' + ), + SIMPLE_PAY_PLUGIN_NAME + ) + ) + ), + 'priority' => 50, + ) + ) + ); +} diff --git a/uninstall.php b/uninstall.php index 5da164f0..041baa79 100644 --- a/uninstall.php +++ b/uninstall.php @@ -1,70 +1,53 @@ 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;" );