From 7da4900087c06820fe13c5b61f8e886b5a2fca11 Mon Sep 17 00:00:00 2001 From: Olivier Gorzalka Date: Wed, 7 Oct 2026 17:47:02 +0200 Subject: [PATCH] fix: guard determine_locale() before restoring the locale --- CHANGELOG.md | 9 ++++++++- src/Async/AsyncRunner.php | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e589e8..ca1707d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to `pollora/hook` are documented in this file. ## [Unreleased] +## [1.4.1] - 2026-10-07 + +### Fixed + +- The runner checks that `determine_locale()` exists before restoring the locale, not only `switch_to_locale()`, so an environment that defines one without the other (a test suite, an early bootstrap) no longer fails with an undefined function. + ## [1.4.0] - 2026-10-07 ### Added @@ -64,7 +70,8 @@ All notable changes to `pollora/hook` are documented in this file. - A `[ClassName::class, 'method']` callback naming an instance method is now instantiated at registration, through the callback resolver when one is set, as a class name is. WordPress used to receive it as a static call and threw a `TypeError` when the hook fired. Static methods and classes not loaded yet are unchanged. - `remove()` and `exists()` accept that same `[ClassName::class, 'method']` form and find the instance it was registered as. `exists()` now accepts a non-callable array or string as its callback. -[Unreleased]: https://github.com/Pollora/hook/compare/v1.4.0...HEAD +[Unreleased]: https://github.com/Pollora/hook/compare/v1.4.1...HEAD +[1.4.1]: https://github.com/Pollora/hook/compare/v1.4.0...v1.4.1 [1.4.0]: https://github.com/Pollora/hook/compare/v1.3.0...v1.4.0 [1.3.0]: https://github.com/Pollora/hook/compare/v1.2.0...v1.3.0 [1.2.0]: https://github.com/Pollora/hook/compare/v1.1.1...v1.2.0 diff --git a/src/Async/AsyncRunner.php b/src/Async/AsyncRunner.php index 1faaf38..a09ab0e 100644 --- a/src/Async/AsyncRunner.php +++ b/src/Async/AsyncRunner.php @@ -108,8 +108,8 @@ private function enterContext(AsyncPayload $payload): \Closure wp_set_current_user($userId); } - $switchedLocale = function_exists('switch_to_locale') && determine_locale() !== $locale - && switch_to_locale($locale); + $switchedLocale = function_exists('switch_to_locale') && function_exists('determine_locale') + && determine_locale() !== $locale && switch_to_locale($locale); return static function () use ($switchedBlog, $previousUser, $switchedLocale): void { if ($switchedLocale) {