Commit e2cc1e795d2 for woocommerce
commit e2cc1e795d2af3e7fd9f46e91a9092b063f9cfc3
Author: Cem Ünalan <raicem@users.noreply.github.com>
Date: Thu Apr 9 16:41:22 2026 +0300
[Performance] Scope wc_translate_user_roles to default-domain gettext hook (#64078)
* [Performance] Scope wc_translate_user_roles to default-domain gettext hook
* Keep wc_translate_user_roles legacy version guard
* Remove wc_translate_user_roles test additions
* Remove redundant default-domain check in wc_translate_user_roles
* Ignore unused wc_translate_user_roles domain parameter for PHPCS
* Match wc_translate_user_roles signature to default hook args
diff --git a/plugins/woocommerce/changelog/performance-wc-translate-user-roles-default-domain-hook b/plugins/woocommerce/changelog/performance-wc-translate-user-roles-default-domain-hook
new file mode 100644
index 00000000000..4b4a49e3348
--- /dev/null
+++ b/plugins/woocommerce/changelog/performance-wc-translate-user-roles-default-domain-hook
@@ -0,0 +1,4 @@
+Significance: patch
+Type: performance
+
+Limit wc_translate_user_roles() to the default-domain contextual gettext hook.
diff --git a/plugins/woocommerce/includes/wc-user-functions.php b/plugins/woocommerce/includes/wc-user-functions.php
index 55b8871fb04..2d15d5621f9 100644
--- a/plugins/woocommerce/includes/wc-user-functions.php
+++ b/plugins/woocommerce/includes/wc-user-functions.php
@@ -1153,19 +1153,18 @@ function wc_update_user_last_active( $user_id ) {
* @param string $translation Translated text.
* @param string $text Text to translate.
* @param string $context Context information for the translators.
- * @param string $domain Text domain. Unique identifier for retrieving translated strings.
* @return string
*/
-function wc_translate_user_roles( $translation, $text, $context, $domain ) {
+function wc_translate_user_roles( $translation, $text, $context ) {
// translate_user_role() only accepts a second parameter starting in WP 5.2.
if ( version_compare( get_bloginfo( 'version' ), '5.2', '<' ) ) {
return $translation;
}
- if ( 'User role' === $context && 'default' === $domain && in_array( $text, array( 'Shop manager', 'Customer' ), true ) ) {
+ if ( 'User role' === $context && in_array( $text, array( 'Shop manager', 'Customer' ), true ) ) {
return translate_user_role( $text, 'woocommerce' );
}
return $translation;
}
-add_filter( 'gettext_with_context', 'wc_translate_user_roles', 10, 4 );
+add_filter( 'gettext_with_context_default', 'wc_translate_user_roles', 10, 3 );