PluginProbe
Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution / 1.8.0
Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution v1.8.0
2.0.1 trunk 1.0.0 1.1.0 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.5.0 1.6.0 1.6.1 1.7.0 1.7.1 1.8.0 1.9.0 2.0.0
solid-performance / src / Performance / Plugin / Uninstaller.php

Uninstaller.php in Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution 1.8.0, at src/Performance/Plugin/Uninstaller.php

96 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * All functionality related to uninstalling the plugin.
4 *
5 * @package SolidWP\Performance
6 */
7
8 declare( strict_types=1 );
9
10 namespace SolidWP\Performance\Plugin;
11
12 use SolidWP\Performance\Container;
13 use SolidWP\Performance\Database\Provider;
14 use SolidWP\Performance\StellarWP\Schema\Register;
15 use SolidWP\Performance\StellarWP\Schema\Tables\Contracts\Table;
16
17 if ( ! defined( 'ABSPATH' ) ) {
18 exit;
19 }
20
21 /**
22 * Handles actions that should run when the plugin is uninstalled.
23 *
24 * WordPress does not allow anonymous callbacks with register_uninstall_hook.
25 *
26 * @package SolidWP\Performance
27 */
28 final class Uninstaller {
29
30 /**
31 * @var Container
32 */
33 private Container $container;
34
35 /**
36 * The Singleton instance.
37 *
38 * @var self|null
39 */
40 private static ?self $instance = null;
41
42 /**
43 * @param Container $container The container.
44 */
45 private function __construct( Container $container ) {
46 $this->container = $container;
47 }
48
49 /**
50 * Get the singleton instance.
51 *
52 * @return self
53 */
54 public static function instance(): self {
55 if ( self::$instance === null ) {
56 self::$instance = new self( swpsp_plugin()->container() );
57 }
58
59 return self::$instance;
60 }
61
62 /**
63 * Uninstall hook run via register_uninstall_hook().
64 *
65 * @return void
66 */
67 public static function uninstall(): void {
68 self::instance()->handle_uninstall();
69 }
70
71 /**
72 * Actual uninstall logic.
73 *
74 * @return void
75 */
76 private function handle_uninstall(): void {
77 $this->remove_database_tables();
78 }
79
80 /**
81 * Remove database tables.
82 *
83 * @return void
84 */
85 private function remove_database_tables(): void {
86 $this->container->get( Provider::class )->register();
87
88 $tables = $this->container->get( Provider::SCHEMA_TABLES );
89
90 /** @var class-string<Table> $table */
91 foreach ( $tables as $table ) {
92 Register::remove_table( $table );
93 }
94 }
95 }
96