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

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