| @@ -8,13 +8,8 @@ | ||
| 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 | - */ | |
| 17 | 12 | protected $plugin_basename; |
| 18 | 13 | |
| 19 | 14 | /** |
| 20 | 15 | * Constructor |
| @@ -29,10 +24,15 @@ | ||
| 29 | 24 | // Manages plugin activation and deactivation |
| 30 | 25 | register_activation_hook( $plugin_basename, array( $this, 'activate' ) ); |
| 31 | 26 | register_deactivation_hook( $plugin_basename, array( $this, 'deactivate' ) ); |
| 32 | 27 | |
| 33 | - // Site creation on multisite. | |
| 34 | - add_action( 'wp_insert_site', array( $this, 'new_site' ) ); | |
| 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 | 35 | } |
| 36 | 36 | |
| 37 | 37 | /** |
| 38 | 38 | * Allows to detect plugin deactivation |
| @@ -51,9 +51,8 @@ | ||
| 51 | 51 | * @since 1.2 |
| 52 | 52 | * |
| 53 | 53 | * @param string $what Either 'activate' or 'deactivate' |
| 54 | 54 | * @param bool $networkwide |
| 55 | - * @return void | |
| 56 | 55 | */ |
| 57 | 56 | protected function do_for_all_blogs( $what, $networkwide ) { |
| 58 | 57 | // Network |
| 59 | 58 | if ( is_multisite() && $networkwide ) { |
| @@ -77,9 +76,8 @@ | ||
| 77 | 76 | * |
| 78 | 77 | * @since 1.7 |
| 79 | 78 | * |
| 80 | 79 | * @param bool $networkwide |
| 81 | - * @return void | |
| 82 | 80 | */ |
| 83 | 81 | public function activate( $networkwide ) { |
| 84 | 82 | $this->do_for_all_blogs( 'activate', $networkwide ); |
| 85 | 83 | } |
| @@ -87,10 +85,8 @@ | ||
| 87 | 85 | /** |
| 88 | 86 | * Plugin activation |
| 89 | 87 | * |
| 90 | 88 | * @since 0.5 |
| 91 | - * | |
| 92 | - * @return void | |
| 93 | 89 | */ |
| 94 | 90 | protected function _activate() { |
| 95 | 91 | // Can be overriden in child class |
| 96 | 92 | } |
| @@ -100,9 +96,8 @@ | ||
| 100 | 96 | * |
| 101 | 97 | * @since 0.1 |
| 102 | 98 | * |
| 103 | 99 | * @param bool $networkwide |
| 104 | - * @return void | |
| 105 | 100 | */ |
| 106 | 101 | public function deactivate( $networkwide ) { |
| 107 | 102 | $this->do_for_all_blogs( 'deactivate', $networkwide ); |
| 108 | 103 | } |
| @@ -110,10 +105,8 @@ | ||
| 110 | 105 | /** |
| 111 | 106 | * Plugin deactivation |
| 112 | 107 | * |
| 113 | 108 | * @since 0.5 |
| 114 | - * | |
| 115 | - * @return void | |
| 116 | 109 | */ |
| 117 | 110 | protected function _deactivate() { |
| 118 | 111 | // Can be overriden in child class |
| 119 | 112 | } |
| @@ -123,12 +116,25 @@ | ||
| 123 | 116 | * |
| 124 | 117 | * @since 2.6.8 |
| 125 | 118 | * |
| 126 | 119 | * @param WP_Site $new_site New site object. |
| 127 | - * @return void | |
| 128 | 120 | */ |
| 129 | 121 | public function new_site( $new_site ) { |
| 130 | 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 ); | |
| 131 | 137 | $this->_activate(); |
| 132 | 138 | restore_current_blog(); |
| 133 | 139 | } |
| 134 | 140 | } |