PluginProbe
Polylang / 2.0.3
Polylang v2.0.3
3.8.9 3.8.8 3.8.7 3.8.6 3.8.5 3.8.4 3.8.3 2.7 2.7.0.1 2.7.1 2.7.2 2.7.3 2.7.4 2.8 2.8.1 2.8.2 2.8.3 2.8.4 2.9 2.9.1 2.9.2 3.0 3.0.1 3.0.2 3.0.3 All 233 releases
polylang / install / install-base.php

install-base.php in Polylang 2.0.3, at install/install-base.php

112 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * a generic activation / de-activation class compatble with multisite
5 *
6 * @since 1.7
7 */
8 class PLL_Install_Base {
9 protected $plugin_basename;
10
11 /**
12 * constructor
13 *
14 * @since 1.7
15 */
16 public function __construct( $plugin_basename ) {
17 $this->plugin_basename = $plugin_basename;
18
19 // manages plugin activation and deactivation
20 register_activation_hook( $plugin_basename, array( $this, 'activate' ) );
21 register_deactivation_hook( $plugin_basename, array( $this, 'deactivate' ) );
22
23 // blog creation on multisite
24 add_action( 'wpmu_new_blog', array( $this, 'wpmu_new_blog' ), 5 ); // before WP attempts to send mails which can break on some PHP versions
25 }
26
27 /**
28 * allows to detect plugin deactivation
29 *
30 * @since 1.7
31 *
32 * @return bool true if the plugin is currently beeing deactivated
33 */
34 public function is_deactivation() {
35 return isset( $_GET['action'], $_GET['plugin'] ) && 'deactivate' == $_GET['action'] && $this->plugin_basename == $_GET['plugin'];
36 }
37
38 /**
39 * activation or deactivation for all blogs
40 *
41 * @since 1.2
42 *
43 * @param string $what either 'activate' or 'deactivate'
44 */
45 protected function do_for_all_blogs( $what, $networkwide ) {
46 // network
47 if ( is_multisite() && $networkwide ) {
48 global $wpdb;
49
50 foreach ( $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ) as $blog_id ) {
51 switch_to_blog( $blog_id );
52 'activate' == $what ? $this->_activate() : $this->_deactivate();
53 }
54 restore_current_blog();
55 }
56
57 // single blog
58 else {
59 'activate' == $what ? $this->_activate() : $this->_deactivate();
60 }
61 }
62
63 /**
64 * plugin activation for multisite
65 *
66 * @since 1.7
67 */
68 public function activate( $networkwide ) {
69 $this->do_for_all_blogs( 'activate', $networkwide );
70 }
71
72 /**
73 * plugin activation
74 *
75 * @since 0.5
76 */
77 protected function _activate() {
78 // can be overriden in child class
79 }
80
81 /**
82 * plugin deactivation for multisite
83 *
84 * @since 0.1
85 */
86 public function deactivate( $networkwide ) {
87 $this->do_for_all_blogs( 'deactivate', $networkwide );
88 }
89
90 /**
91 * plugin deactivation
92 *
93 * @since 0.5
94 */
95 protected function _deactivate() {
96 // can be overriden in child class
97 }
98
99 /**
100 * blog creation on multisite ( to set default options )
101 *
102 * @since 0.9.4
103 *
104 * @param int $blog_id
105 */
106 public function wpmu_new_blog( $blog_id ) {
107 switch_to_blog( $blog_id );
108 $this->_activate();
109 restore_current_blog();
110 }
111 }
112