| @@ -8,9 +8,8 @@ | ||
| 8 | 8 | declare( strict_types=1 ); |
| 9 | 9 | |
| 10 | 10 | namespace Packetery\Module; |
| 11 | 11 | |
| 12 | -use Packetery\Module\Dashboard\DashboardPage; | |
| 13 | 12 | use Packetery\Module\Hooks\HookRegistrar; |
| 14 | 13 | |
| 15 | 14 | /** |
| 16 | 15 | * Class Plugin |
| @@ -18,9 +17,9 @@ | ||
| 18 | 17 | * @package Packetery |
| 19 | 18 | */ |
| 20 | 19 | class Plugin { |
| 21 | 20 | |
| 22 | - public const VERSION = '2.3.2'; | |
| 21 | + public const VERSION = '2.0.9'; | |
| 23 | 22 | public const DOMAIN = 'packeta'; |
| 24 | 23 | public const PARAM_PACKETERY_ACTION = 'packetery_action'; |
| 25 | 24 | public const PARAM_NONCE = '_wpnonce'; |
| 26 | 25 | |
| @@ -55,8 +54,70 @@ | ||
| 55 | 54 | $this->hookRegistrar->register(); |
| 56 | 55 | } |
| 57 | 56 | |
| 58 | 57 | /** |
| 58 | + * Uninstalls plugin and drops custom database table. | |
| 59 | + * Only a static class method or function can be used in an uninstall hook. | |
| 60 | + */ | |
| 61 | + public static function uninstall(): void { | |
| 62 | + if ( defined( 'PACKETERY_DEBUG' ) && constant( 'PACKETERY_DEBUG' ) === true ) { | |
| 63 | + return; | |
| 64 | + } | |
| 65 | + | |
| 66 | + if ( is_multisite() ) { | |
| 67 | + self::cleanUpRepositoriesForMultisite(); | |
| 68 | + } else { | |
| 69 | + self::cleanUpRepositories(); | |
| 70 | + } | |
| 71 | + } | |
| 72 | + | |
| 73 | + /** | |
| 74 | + * Drops all plugin tables when Multisite is enabled. | |
| 75 | + * | |
| 76 | + * @return void | |
| 77 | + */ | |
| 78 | + private static function cleanUpRepositoriesForMultisite(): void { | |
| 79 | + $sites = self::getSites(); | |
| 80 | + | |
| 81 | + foreach ( $sites as $site ) { | |
| 82 | + switch_to_blog( $site ); | |
| 83 | + self::cleanUpRepositories(); | |
| 84 | + restore_current_blog(); | |
| 85 | + } | |
| 86 | + } | |
| 87 | + | |
| 88 | + /** | |
| 89 | + * Drops all plugin tables for a single site. | |
| 90 | + * | |
| 91 | + * @return void | |
| 92 | + */ | |
| 93 | + private static function cleanUpRepositories(): void { | |
| 94 | + $container = require PACKETERY_PLUGIN_DIR . '/bootstrap.php'; | |
| 95 | + | |
| 96 | + $optionsRepository = $container->getByType( Options\Repository::class ); | |
| 97 | + $pluginOptions = $optionsRepository->getPluginOptions(); | |
| 98 | + foreach ( $pluginOptions as $option ) { | |
| 99 | + // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps | |
| 100 | + delete_option( $option->option_name ); | |
| 101 | + } | |
| 102 | + | |
| 103 | + $logRepository = $container->getByType( Log\Repository::class ); | |
| 104 | + $logRepository->drop(); | |
| 105 | + | |
| 106 | + $carrierRepository = $container->getByType( Carrier\Repository::class ); | |
| 107 | + $carrierRepository->drop(); | |
| 108 | + | |
| 109 | + $orderRepository = $container->getByType( Order\Repository::class ); | |
| 110 | + $orderRepository->drop(); | |
| 111 | + | |
| 112 | + $customsDeclarationItemsRepository = $container->getByType( CustomsDeclaration\Repository::class ); | |
| 113 | + $customsDeclarationItemsRepository->dropItems(); | |
| 114 | + | |
| 115 | + $customsDeclarationRepository = $container->getByType( CustomsDeclaration\Repository::class ); | |
| 116 | + $customsDeclarationRepository->drop(); | |
| 117 | + } | |
| 118 | + | |
| 119 | + /** | |
| 59 | 120 | * Hides submenu item. Must not be called too early. |
| 60 | 121 | * |
| 61 | 122 | * @param string $itemSlug Item slug. |
| 62 | 123 | */ |
| @@ -61,12 +122,12 @@ | ||
| 61 | 122 | * @param string $itemSlug Item slug. |
| 62 | 123 | */ |
| 63 | 124 | public static function hideSubmenuItem( string $itemSlug ): void { |
| 64 | 125 | global $submenu; |
| 65 | - if ( isset( $submenu[ DashboardPage::SLUG ] ) ) { | |
| 66 | - foreach ( $submenu[ DashboardPage::SLUG ] as $key => $menu ) { | |
| 126 | + if ( isset( $submenu[ Options\Page::SLUG ] ) ) { | |
| 127 | + foreach ( $submenu[ Options\Page::SLUG ] as $key => $menu ) { | |
| 67 | 128 | if ( $itemSlug === $menu[2] ) { |
| 68 | - unset( $submenu[ DashboardPage::SLUG ][ $key ] ); | |
| 129 | + unset( $submenu[ Options\Page::SLUG ][ $key ] ); | |
| 69 | 130 | } |
| 70 | 131 | } |
| 71 | 132 | } |
| 72 | 133 | } |