PluginProbe
Polylang / 2.2.2
Polylang v2.2.2
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.2.2, at install/install-base.php

119 lines 2.5 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 * @param string $plugin_basename Plugin basename
17 */
18 public function __construct( $plugin_basename ) {
19 $this->plugin_basename = $plugin_basename;
20
21 // Manages plugin activation and deactivation
22 register_activation_hook( $plugin_basename, array( $this, 'activate' ) );
23 register_deactivation_hook( $plugin_basename, array( $this, 'deactivate' ) );
24
25 // Blog creation on multisite
26 add_action( 'wpmu_new_blog', array( $this, 'wpmu_new_blog' ), 5 ); // Before WP attempts to send mails which can break on some PHP versions
27 }
28
29 /**
30 * Allows to detect plugin deactivation
31 *
32 * @since 1.7
33 *
34 * @return bool true if the plugin is currently beeing deactivated
35 */
36 public function is_deactivation() {
37 return isset( $_GET['action'], $_GET['plugin'] ) && 'deactivate' == $_GET['action'] && $this->plugin_basename == $_GET['plugin'];
38 }
39
40 /**
41 * Activation or deactivation for all blogs
42 *
43 * @since 1.2
44 *
45 * @param string $what Either 'activate' or 'deactivate'
46 * @param bool $networkwide
47 */
48 protected function do_for_all_blogs( $what, $networkwide ) {
49 // Network
50 if ( is_multisite() && $networkwide ) {
51 global $wpdb;
52
53 foreach ( $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ) as $blog_id ) {
54 switch_to_blog( $blog_id );
55 'activate' == $what ? $this->_activate() : $this->_deactivate();
56 }
57 restore_current_blog();
58 }
59
60 // Single blog
61 else {
62 'activate' == $what ? $this->_activate() : $this->_deactivate();
63 }
64 }
65
66 /**
67 * Plugin activation for multisite
68 *
69 * @since 1.7
70 *
71 * @param bool $networkwide
72 */
73 public function activate( $networkwide ) {
74 $this->do_for_all_blogs( 'activate', $networkwide );
75 }
76
77 /**
78 * Plugin activation
79 *
80 * @since 0.5
81 */
82 protected function _activate() {
83 // Can be overriden in child class
84 }
85
86 /**
87 * Plugin deactivation for multisite
88 *
89 * @since 0.1
90 *
91 * @param bool $networkwide
92 */
93 public function deactivate( $networkwide ) {
94 $this->do_for_all_blogs( 'deactivate', $networkwide );
95 }
96
97 /**
98 * Plugin deactivation
99 *
100 * @since 0.5
101 */
102 protected function _deactivate() {
103 // Can be overriden in child class
104 }
105
106 /**
107 * Blog creation on multisite ( to set default options )
108 *
109 * @since 0.9.4
110 *
111 * @param int $blog_id
112 */
113 public function wpmu_new_blog( $blog_id ) {
114 switch_to_blog( $blog_id );
115 $this->_activate();
116 restore_current_blog();
117 }
118 }
119