PLL_Install_Base

A generic activation / de-activation class compatble with multisite.

Defined (1)

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

/install/install-base.php  
  1. class PLL_Install_Base { 
  2. protected $plugin_basename; 
  3.  
  4. /** 
  5. * constructor 
  6. * @since 1.7 
  7. */ 
  8. public function __construct( $plugin_basename ) { 
  9. $this->plugin_basename = $plugin_basename; 
  10.  
  11. // manages plugin activation and deactivation 
  12. register_activation_hook( $plugin_basename, array( $this, 'activate' ) ); 
  13. register_deactivation_hook( $plugin_basename, array( $this, 'deactivate' ) ); 
  14.  
  15. // blog creation on multisite 
  16. add_action( 'wpmu_new_blog', array( $this, 'wpmu_new_blog' ), 5 ); // before WP attempts to send mails which can break on some PHP versions 
  17.  
  18. /** 
  19. * allows to detect plugin deactivation 
  20. * @since 1.7 
  21. * @return bool true if the plugin is currently beeing deactivated 
  22. */ 
  23. public function is_deactivation() { 
  24. return isset( $_GET['action'], $_GET['plugin'] ) && 'deactivate' == $_GET['action'] && $this->plugin_basename == $_GET['plugin']; 
  25.  
  26. /** 
  27. * activation or deactivation for all blogs 
  28. * @since 1.2 
  29. * @param string $what either 'activate' or 'deactivate' 
  30. */ 
  31. protected function do_for_all_blogs( $what, $networkwide ) { 
  32. // network 
  33. if ( is_multisite() && $networkwide ) { 
  34. global $wpdb; 
  35.  
  36. foreach ( $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ) as $blog_id ) { 
  37. switch_to_blog( $blog_id ); 
  38. 'activate' == $what ? $this->_activate() : $this->_deactivate(); 
  39. restore_current_blog(); 
  40.  
  41. // single blog 
  42. else { 
  43. 'activate' == $what ? $this->_activate() : $this->_deactivate(); 
  44.  
  45. /** 
  46. * plugin activation for multisite 
  47. * @since 1.7 
  48. */ 
  49. public function activate( $networkwide ) { 
  50. $this->do_for_all_blogs( 'activate', $networkwide ); 
  51.  
  52. /** 
  53. * plugin activation 
  54. * @since 0.5 
  55. */ 
  56. protected function _activate() { 
  57. // can be overriden in child class 
  58.  
  59. /** 
  60. * plugin deactivation for multisite 
  61. * @since 0.1 
  62. */ 
  63. public function deactivate( $networkwide ) { 
  64. $this->do_for_all_blogs( 'deactivate', $networkwide ); 
  65.  
  66. /** 
  67. * plugin deactivation 
  68. * @since 0.5 
  69. */ 
  70. protected function _deactivate() { 
  71. // can be overriden in child class 
  72.  
  73. /** 
  74. * blog creation on multisite ( to set default options ) 
  75. * @since 0.9.4 
  76. * @param int $blog_id 
  77. */ 
  78. public function wpmu_new_blog( $blog_id ) { 
  79. switch_to_blog( $blog_id ); 
  80. $this->_activate(); 
  81. restore_current_blog();