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