1 <?php
2
3 4 5 6 7 8 9 10 11 12
13
14 namespace WC_POS;
15
16 class Deactivator {
17
18 19 20
21 public function __construct(){
22 register_deactivation_hook( PLUGIN_FILE, array( $this, 'deactivate' ) );
23 }
24
25 26 27 28 29
30 public function deactivate( $network_wide ) {
31
32 if ( function_exists( 'is_multisite' ) && is_multisite() ) {
33
34 if ( $network_wide ) {
35
36
37 $blog_ids = $this->get_blog_ids();
38
39 foreach ( $blog_ids as $blog_id ) {
40
41 switch_to_blog( $blog_id );
42 $this->single_deactivate();
43
44 restore_current_blog();
45
46 }
47
48 } else {
49 $this->single_deactivate();
50 }
51
52 } else {
53 $this->single_deactivate();
54 }
55
56 }
57
58 59 60 61 62 63
64 private static function get_blog_ids() {
65
66 global $wpdb;
67
68
69 $sql = "SELECT blog_id FROM $wpdb->blogs
70 WHERE archived = '0' AND spam = '0'
71 AND deleted = '0'";
72
73 return $wpdb->get_col( $sql );
74
75 }
76
77 78 79
80 public function single_deactivate() {
81
82
83 $this->remove_pos_capability();
84
85
86 flush_rewrite_rules( false );
87 }
88
89 90 91 92
93 static private function remove_pos_capability(){
94 $roles = array('administrator', 'shop_manager');
95 $caps = array('manage_woocommerce_pos', 'access_woocommerce_pos');
96 foreach($roles as $slug) :
97 $role = get_role($slug);
98 if($role) : foreach($caps as $cap) :
99 $role->remove_cap($cap);
100 endforeach; endif;
101 endforeach;
102 }
103
104 }
105