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

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