PluginProbe ʕ •ᴥ•ʔ
Oxyplug Preload / 2.2.1
Oxyplug Preload v2.2.1
2.2.1 2.2.0 trunk 2.0.0 2.1.0 2.1.1 2.1.2 2.1.3 2.1.5
oxyplug-preload / uninstall.php
oxyplug-preload Last commit date
assets 1 week ago lang 2 weeks ago oxy-preload.php 1 week ago readme.txt 1 week ago uninstall.php 1 week ago
uninstall.php
89 lines
1 <?php
2 /**
3 * Uninstall routine for Oxyplug Preload.
4 *
5 * Runs only when the plugin is deleted from the WordPress admin. It removes the
6 * `# BEGIN Oxyplug Preload ... # END Oxyplug Preload` block from `.htaccess` and
7 * deletes the `_oxyplug_preload_*` options so nothing stale is left behind.
8 */
9
10 // Bail if WordPress did not invoke this file as an uninstall.
11 if (!defined('WP_UNINSTALL_PLUGIN')) {
12 exit;
13 }
14
15 /**
16 * Delete the plugin's options for the current site/blog context.
17 *
18 * Mirrors OxyPreload::oxyplug_preload_update_option(), which stores options as
19 * network options (keyed by the current blog id) on multisite and as regular
20 * options otherwise.
21 *
22 * @return void
23 */
24 function oxyplug_preload_delete_options(): void
25 {
26 $option_names = array(
27 '_oxyplug_preload_featured_image',
28 '_oxyplug_preload_preloads',
29 );
30
31 foreach ($option_names as $option_name) {
32 if (is_multisite()) {
33 delete_network_option(get_current_blog_id(), $option_name);
34 } else {
35 delete_option($option_name);
36 }
37 }
38 }
39
40 /**
41 * Strip the Oxyplug Preload section from the site's .htaccess file.
42 *
43 * @return void
44 */
45 function oxyplug_preload_clean_htaccess(): void
46 {
47 $htaccess_path = ABSPATH . '.htaccess';
48
49 global $wp_filesystem;
50 if (!$wp_filesystem) {
51 require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php';
52 require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-direct.php';
53 $wp_filesystem = new \WP_Filesystem_Direct(null);
54 }
55
56 if (!$wp_filesystem->exists($htaccess_path)
57 || !$wp_filesystem->is_readable($htaccess_path)
58 || !$wp_filesystem->is_writable($htaccess_path)) {
59 return;
60 }
61
62 $current_content = $wp_filesystem->get_contents($htaccess_path);
63 if ($current_content === false) {
64 return;
65 }
66
67 // Same marker pattern used when writing the section in oxy-preload.php.
68 $pattern = '/\n*# BEGIN Oxyplug Preload\n.*?# END Oxyplug Preload\n*/s';
69 $cleaned = preg_replace($pattern, '', $current_content);
70
71 if ($cleaned !== null && $cleaned !== $current_content) {
72 $wp_filesystem->put_contents($htaccess_path, rtrim($cleaned) . "\n");
73 }
74 }
75
76 oxyplug_preload_clean_htaccess();
77
78 if (is_multisite()) {
79 // The plugin stores options per blog, so clean each site on the network.
80 $site_ids = get_sites(array('fields' => 'ids'));
81 foreach ($site_ids as $site_id) {
82 switch_to_blog($site_id);
83 oxyplug_preload_delete_options();
84 restore_current_blog();
85 }
86 } else {
87 oxyplug_preload_delete_options();
88 }
89