WC_POS_Deactivator

Fired during plugin activation.

Defined (1)

The class is defined in the following location(s).

/includes/class-wc-pos-deactivator.php  
  1. class WC_POS_Deactivator { 
  2.  
  3. /** 
  4. * @param $file 
  5. */ 
  6. public function __construct( $file ) { 
  7. register_deactivation_hook( $file, array( $this, 'deactivate' ) ); 
  8.  
  9. /** 
  10. * Fired when the plugin is deactivated. 
  11. * @param $network_wide 
  12. */ 
  13. public function deactivate( $network_wide ) { 
  14.  
  15. if ( function_exists( 'is_multisite' ) && is_multisite() ) { 
  16.  
  17. if ( $network_wide ) { 
  18.  
  19. // Get all blog ids 
  20. $blog_ids = $this->get_blog_ids(); 
  21.  
  22. foreach ( $blog_ids as $blog_id ) { 
  23.  
  24. switch_to_blog( $blog_id ); 
  25. $this->single_deactivate(); 
  26.  
  27. restore_current_blog(); 
  28.  
  29.  
  30. } else { 
  31. $this->single_deactivate(); 
  32.  
  33. } else { 
  34. $this->single_deactivate(); 
  35.  
  36.  
  37. /** 
  38. * Get all blog ids of blogs in the current network that are: 
  39. * - not archived 
  40. * - not spam 
  41. * - not deleted 
  42. */ 
  43. private static function get_blog_ids() { 
  44.  
  45. global $wpdb; 
  46.  
  47. // get an array of blog ids 
  48. $sql = "SELECT blog_id FROM $wpdb->blogs 
  49. WHERE archived = '0' AND spam = '0' 
  50. AND deleted = '0'"; 
  51.  
  52. return $wpdb->get_col( $sql ); 
  53.  
  54.  
  55. /** 
  56. * Fired when the plugin is deactivated. 
  57. */ 
  58. public function single_deactivate() { 
  59.  
  60. // remove pos capabilities 
  61. $this->remove_pos_capability(); 
  62.  
  63. // remove pos rewrite rule 
  64. flush_rewrite_rules( false ); // false will not overwrite .htaccess 
  65.  
  66. /** 
  67. * remove default pos capabilities to administrator and 
  68. * shop_manager roles 
  69. */ 
  70. static private function remove_pos_capability() { 
  71. $roles = array('administrator', 'shop_manager'); 
  72. $caps = array('manage_woocommerce_pos', 'access_woocommerce_pos'); 
  73. foreach($roles as $slug) : 
  74. $role = get_role($slug); 
  75. if($role) : foreach($caps as $cap) : 
  76. $role->remove_cap($cap); 
  77. endforeach; endif; 
  78. endforeach; 
  79.