woocommerce-paypal-payments
Last commit date
api
3 months ago
assets
1 week ago
lib
3 months ago
modules
1 week ago
src
1 month ago
vendor
1 week ago
LICENSE
5 years ago
bootstrap.php
9 months ago
changelog.txt
1 week ago
modules.php
1 week ago
readme.txt
1 week ago
uninstall.php
1 month ago
woocommerce-paypal-payments.php
1 week ago
uninstall.php
58 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Uninstalls the plugin. |
| 5 | * |
| 6 | * @package WooCommerce\PayPalCommerce |
| 7 | */ |
| 8 | declare (strict_types=1); |
| 9 | namespace WooCommerce\PayPalCommerce; |
| 10 | |
| 11 | use Throwable; |
| 12 | use WooCommerce\PayPalCommerce\Uninstall\ClearDatabase; |
| 13 | use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface; |
| 14 | use WooCommerce\PayPalCommerce\Settings\Data\GeneralSettings; |
| 15 | if (!defined('WP_UNINSTALL_PLUGIN')) { |
| 16 | die('Direct access not allowed.'); |
| 17 | } |
| 18 | $root_dir = __DIR__; |
| 19 | $main_plugin_file = "{$root_dir}/woocommerce-paypal-payments.php"; |
| 20 | if (!file_exists($main_plugin_file)) { |
| 21 | return; |
| 22 | } |
| 23 | require $main_plugin_file; |
| 24 | (static function (string $root_dir): void { |
| 25 | $autoload_filepath = "{$root_dir}/vendor/autoload.php"; |
| 26 | if (file_exists($autoload_filepath) && !class_exists('\WooCommerce\PayPalCommerce\PluginModule')) { |
| 27 | require $autoload_filepath; |
| 28 | } |
| 29 | $bootstrap = require "{$root_dir}/bootstrap.php"; |
| 30 | $app_container = $bootstrap($root_dir); |
| 31 | assert($app_container instanceof ContainerInterface); |
| 32 | $general_settings = $app_container->get('settings.data.general'); |
| 33 | assert($general_settings instanceof GeneralSettings); |
| 34 | /** |
| 35 | * Delete the branded flag unconditionally so reinstalling from a different |
| 36 | * source (e.g. WordPress.org) does not silently re-enter branded-only mode. |
| 37 | * Unlike most settings, this flag must be cleared on every uninstall — even |
| 38 | * when the full-reset filter is off — because keeping it prevents merchants |
| 39 | * from ever escaping branded-only mode without direct DB intervention. |
| 40 | */ |
| 41 | delete_option('woocommerce_paypal_branded'); |
| 42 | if ($general_settings->reset_installation_path('plugin_uninstall')) { |
| 43 | $general_settings->save(); |
| 44 | } |
| 45 | /** |
| 46 | * Allows a full reset of the plugin data. |
| 47 | * |
| 48 | * By default, this is false, preserving plugin settings in the DB during uninstallation. |
| 49 | * This filter has no toggle in the UI yet and can only be set using custom code. |
| 50 | */ |
| 51 | $should_reset_db = apply_filters('woocommerce_paypal_payments_uninstall_full_reset', \false); |
| 52 | if ($should_reset_db) { |
| 53 | $clear_db = $app_container->get('uninstall.clear-db'); |
| 54 | assert($clear_db instanceof ClearDatabase); |
| 55 | $clear_db->clean_up(); |
| 56 | } |
| 57 | })($root_dir); |
| 58 |