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

138 lines 3.1 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 if ( version_compare( $GLOBALS['wp_version'], '5.1', '<' ) ) {
27 // FIXME: Backward compatibility with WP < 5.1.
28 add_action( 'wpmu_new_blog', array( $this, 'wpmu_new_blog' ), 5 ); // Before WP attempts to send mails which can break on some PHP versions
29 } else {
30 add_action( 'wp_insert_site', array( $this, 'new_site' ) );
31 }
32 }
33
34 /**
35 * Allows to detect plugin deactivation
36 *
37 * @since 1.7
38 *
39 * @return bool true if the plugin is currently beeing deactivated
40 */
41 public function is_deactivation() {
42 return isset( $_GET['action'], $_GET['plugin'] ) && 'deactivate' === $_GET['action'] && $this->plugin_basename === $_GET['plugin']; // phpcs:ignore WordPress.Security.NonceVerification
43 }
44
45 /**
46 * Activation or deactivation for all blogs
47 *
48 * @since 1.2
49 *
50 * @param string $what Either 'activate' or 'deactivate'
51 * @param bool $networkwide
52 */
53 protected function do_for_all_blogs( $what, $networkwide ) {
54 // Network
55 if ( is_multisite() && $networkwide ) {
56 global $wpdb;
57
58 foreach ( $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ) as $blog_id ) {
59 switch_to_blog( $blog_id );
60 'activate' == $what ? $this->_activate() : $this->_deactivate();
61 }
62 restore_current_blog();
63 }
64
65 // Single blog
66 else {
67 'activate' == $what ? $this->_activate() : $this->_deactivate();
68 }
69 }
70
71 /**
72 * Plugin activation for multisite
73 *
74 * @since 1.7
75 *
76 * @param bool $networkwide
77 */
78 public function activate( $networkwide ) {
79 $this->do_for_all_blogs( 'activate', $networkwide );
80 }
81
82 /**
83 * Plugin activation
84 *
85 * @since 0.5
86 */
87 protected function _activate() {
88 // Can be overriden in child class
89 }
90
91 /**
92 * Plugin deactivation for multisite
93 *
94 * @since 0.1
95 *
96 * @param bool $networkwide
97 */
98 public function deactivate( $networkwide ) {
99 $this->do_for_all_blogs( 'deactivate', $networkwide );
100 }
101
102 /**
103 * Plugin deactivation
104 *
105 * @since 0.5
106 */
107 protected function _deactivate() {
108 // Can be overriden in child class
109 }
110
111 /**
112 * Site creation on multisite ( to set default options )
113 *
114 * @since 2.6.8
115 *
116 * @param WP_Site $new_site New site object.
117 */
118 public function new_site( $new_site ) {
119 switch_to_blog( $new_site->id );
120 $this->_activate();
121 restore_current_blog();
122 }
123
124 /**
125 * Blog creation on multisite ( to set default options )
126 * Backward compatibility with WP < 5.1
127 *
128 * @since 0.9.4
129 *
130 * @param int $blog_id
131 */
132 public function wpmu_new_blog( $blog_id ) {
133 switch_to_blog( $blog_id );
134 $this->_activate();
135 restore_current_blog();
136 }
137 }
138