| @@ -24,10 +24,15 @@ | ||
| 24 | 24 | // Manages plugin activation and deactivation |
| 25 | 25 | register_activation_hook( $plugin_basename, array( $this, 'activate' ) ); |
| 26 | 26 | register_deactivation_hook( $plugin_basename, array( $this, 'deactivate' ) ); |
| 27 | 27 | |
| 28 | - // Site creation on multisite. | |
| 29 | - 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 | + } | |
| 30 | 35 | } |
| 31 | 36 | |
| 32 | 37 | /** |
| 33 | 38 | * Allows to detect plugin deactivation |
| @@ -114,8 +119,22 @@ | ||
| 114 | 119 | * @param WP_Site $new_site New site object. |
| 115 | 120 | */ |
| 116 | 121 | public function new_site( $new_site ) { |
| 117 | 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 ); | |
| 118 | 137 | $this->_activate(); |
| 119 | 138 | restore_current_blog(); |
| 120 | 139 | } |
| 121 | 140 | } |