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