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