From 54aad2345b423595acadd011fd3f43ea6aee8e97 Mon Sep 17 00:00:00 2001 From: Erfan Kargosha Date: Mon, 13 Jan 2025 13:45:44 +0330 Subject: [PATCH 1/2] add multisite compatibility after publishing, the implementing plugins onActivation should be updated to avoid fatal errors. --- src/Plugin.php | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/src/Plugin.php b/src/Plugin.php index 4d3f9c1..aa04d42 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -263,7 +263,7 @@ protected function setConstants() { * @return void */ public function loadPluginTextDomain() { - load_plugin_textdomain( $this->getHeader( 'text_domain' ), false, plugin_basename( $this->basePath( ltrim( $this->getHeader( 'domain_path' ), '/' ) ) ) ); + load_plugin_textdomain( $this->getHeader( 'text_domain' ), false, $this->basePath( ltrim( $this->getHeader( 'domain_path' ), '/' ) ) ); } /** @@ -272,24 +272,46 @@ public function loadPluginTextDomain() { * @param \Closure $activation * @return void */ - public function onActivation( \Closure $activation ) { - + public function onActivation( \Closure $activation ){ $instance = $this; register_activation_hook( $this->filePath, - function () use ( $activation, $instance ) { + function ( $network_wide ) use ( $activation, $instance ) { try { - call_user_func_array( $activation, [ $instance ] ); + call_user_func_array( $activation, [ $instance, $network_wide ]); } catch ( \Exception $e ) { deactivate_plugins( basename( $this->filePath ) ); wp_die( $e->getMessage() ); //phpcs:ignore } } ); + } + + /** + * Trigger callback for initializing a site in the network. + * + * @param \Closure $networkAdd + * @return void + */ + public function onNetworkAdd( \Closure $networkAdd ){ + + $instance = $this; + add_action( + 'wp_initialize_site', + function ( $newSite, $args ) use ( $networkAdd, $instance ) { + try { + call_user_func_array( $networkAdd, [ $instance, $newSite, $args ]); + } catch ( \Exception $e ) { + wp_die( $e->getMessage() ); + } + }, 10, 2 + ); } + + /** * Trigger callback on plugin deactivation. * From 460899a9db303f999617f14e8621b391cbc011e4 Mon Sep 17 00:00:00 2001 From: Erfan Kargosha Date: Mon, 13 Jan 2025 18:08:05 +0330 Subject: [PATCH 2/2] change basename to default --- src/Plugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Plugin.php b/src/Plugin.php index aa04d42..b9f1890 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -263,7 +263,7 @@ protected function setConstants() { * @return void */ public function loadPluginTextDomain() { - load_plugin_textdomain( $this->getHeader( 'text_domain' ), false, $this->basePath( ltrim( $this->getHeader( 'domain_path' ), '/' ) ) ); + load_plugin_textdomain( $this->getHeader( 'text_domain' ), false, plugin_basename( $this->basePath( ltrim( $this->getHeader( 'domain_path' ), '/' ) ) ) ); } /**