-
Notifications
You must be signed in to change notification settings - Fork 20
/
Deactivator.php
42 lines (37 loc) · 958 Bytes
/
Deactivator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
namespace SlimSEO;
class Deactivator {
public function __construct( $file ) {
register_deactivation_hook( $file, [ $this, 'deactivate' ] );
}
public function deactivate( $network_wide ) {
if ( is_multisite() && $network_wide ) {
$this->network_deactivate();
} else {
$this->site_deactivate();
}
}
private function network_deactivate() {
$sites = get_sites(
[
'fields' => 'ids',
'number' => 0,
'update_site_cache' => false,
]
);
foreach ( $sites as $site ) {
switch_to_blog( $site );
$this->site_deactivate();
restore_current_blog();
}
}
private function site_deactivate() {
/*
* When deactivating the plugin, we hardly remove our rewrite rules.
* flush_rewrite_rules() not working as it re-adds our rewrite rules.
* So, let WordPress regenerates rewrite rules when needed.
*/
delete_option( 'rewrite_rules' );
do_action( 'slim_seo_deactivate' );
}
}