diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f6634a95ea3c0f56b08c7ee580ec856fda8dcf5..3896bae98e5fee5ad63bef9d6ff9ea6d41d316e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # wp-init changelog +## [0.10.6] - 2025-01-10 +### Fixed +- Fixed path for loading plugin translations. +### Changed +- Improved _development_ environment detection. Now, in addition to previous methods, adding `dev` suffix to plugin version enabled development environment (no container compilation). + ## [0.10.5] - 2025-01-09 ### Fixed - Fixed condition checking if current environment is development, causing container to always use live version. diff --git a/src/Extension/CommonBinding/I18n.php b/src/Extension/CommonBinding/I18n.php index 0f5cd6ed64f8cf6440ebc04a80de0753a81ab8e6..702eb449819c5497a348be5b06b31b23a8532a61 100644 --- a/src/Extension/CommonBinding/I18n.php +++ b/src/Extension/CommonBinding/I18n.php @@ -22,10 +22,18 @@ class I18n implements Hookable { } public function __invoke(): void { + $relative_path = str_replace( + WP_PLUGIN_DIR . '/', + '', + $this->plugin->get_path( + $this->plugin->header()->get( 'DomainPath' ) + ) + ); + \load_plugin_textdomain( $this->plugin->get_slug(), false, - $this->plugin->header()->get( 'DomainPath' ) + $relative_path ); } } diff --git a/src/Kernel.php b/src/Kernel.php index 929881bb1efb82be42c31885622202dcfe1eabed..14b1994d9f792869b4e3126c1fb5e402db437ad8 100644 --- a/src/Kernel.php +++ b/src/Kernel.php @@ -79,7 +79,7 @@ final class Kernel { $container->set( Plugin::class, $plugin ); $container->set( Configuration::class, $this->config ); - $this->prepare_driver( $container )->register_hooks(); + $this->prepare_driver( $container, $plugin )->register_hooks(); } private function get_cache_path( string $path = '' ): string { @@ -88,14 +88,19 @@ final class Kernel { ); } + /** + * Container name in scheme: `<slug>_<version>_container`. + * + * Container is compiled in client environment, so in order to allow graceful upgrade, include version name to the container. Compiled container class is also autoloaded, so it is necessary that name is unique enough to avoid clash with other plugins. + */ private function get_container_name( Plugin $plugin ): string { - return preg_replace( '/[^\w_]/', '_', implode("_", [ $plugin->get_slug(), $plugin->get_version(), 'container' ]) ); + return preg_replace( '/[^\w_]/', '_', implode( '_', [ $plugin->get_slug(), $plugin->get_version(), 'container' ] ) ); } private function initialize_container( Plugin $plugin, bool $use_cache = true ): Container { $original_builder = new DiBuilder(); - if ( $this->is_prod() && $use_cache ) { + if ( $this->is_prod( $plugin ) && $use_cache ) { $original_builder->enableCompilation( $this->get_cache_path(), $this->get_container_name( $plugin ) @@ -124,7 +129,7 @@ final class Kernel { } } - private function prepare_driver( ContainerInterface $container ): HookDriver { + private function prepare_driver( ContainerInterface $container, Plugin $plugin ): HookDriver { $loader = new CompositeBindingLoader(); foreach ( $this->extensions as $extension ) { $loader->add( $extension->bindings( $container ) ); @@ -134,7 +139,7 @@ final class Kernel { new ClusteredLoader( $loader ) ); - if ( $this->is_dev() ) { + if ( $this->is_dev( $plugin ) ) { $loader = new DebugBindingLoader( $loader ); } @@ -156,11 +161,11 @@ final class Kernel { return $driver; } - private function is_dev(): bool { - return $this->config->get( 'debug', false ) || wp_get_environment_type() === 'development'; + private function is_dev( Plugin $plugin ): bool { + return $this->config->get( 'debug', false ) || wp_get_environment_type() === 'development' || str_contains( $plugin->get_version(), 'dev' ); } - private function is_prod(): bool { - return $this->is_dev() === false; + private function is_prod( Plugin $plugin ): bool { + return $this->is_dev( $plugin ) === false; } }