| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Metricool\Support\Helpers; |
| 6 |
|
| 7 |
use Metricool\Services\OptionsService; |
| 8 |
|
| 9 |
class Uninstall |
| 10 |
{ |
| 11 |
private OptionsService $options; |
| 12 |
|
| 13 |
public function __construct(OptionsService $options) |
| 14 |
{ |
| 15 |
$this->options = $options; |
| 16 |
} |
| 17 |
|
| 18 |
/** |
| 19 |
* Handle plugin uninstallation. |
| 20 |
* @internal Method is currently hooked as the uninstallation callback |
| 21 |
* {@see Plugin::boot} |
| 22 |
*/ |
| 23 |
public function handlePluginUninstall(): void |
| 24 |
{ |
| 25 |
$this->deleteAllOptions(); |
| 26 |
$this->deleteCapability(); |
| 27 |
} |
| 28 |
|
| 29 |
/** |
| 30 |
* Delete all Plugin options from wp_options |
| 31 |
*/ |
| 32 |
private function deleteAllOptions(): void |
| 33 |
{ |
| 34 |
$this->options->wipe(true); |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Remove the 'metricool_manage' capability from the administrator role if it exists |
| 39 |
*/ |
| 40 |
private function deleteCapability(): void |
| 41 |
{ |
| 42 |
$role = get_role('administrator'); |
| 43 |
if ($role && $role->has_cap('metricool_manage')) { |
| 44 |
$role->remove_cap('metricool_manage'); |
| 45 |
} |
| 46 |
} |
| 47 |
} |
| 48 |
|