From 573dd364a8feb43cc956c5d13b31ddb187a4614f Mon Sep 17 00:00:00 2001 From: Justin Tadlock Date: Wed, 27 Sep 2017 13:52:35 -0500 Subject: [PATCH] Make sure role labels are translated where the plugin outputs them. Fixes: https://github.com/justintadlock/members/issues/157 Note that fixing this ticket brought up another issue, which is that core WP outputs the role in some places. This is out of scope for this commit, so a second ticket was created: https://github.com/justintadlock/members/issues/158 --- admin/class-meta-box-content-permissions.php | 2 +- inc/functions-roles.php | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/admin/class-meta-box-content-permissions.php b/admin/class-meta-box-content-permissions.php index 3e1b68a..f24c428 100644 --- a/admin/class-meta-box-content-permissions.php +++ b/admin/class-meta-box-content-permissions.php @@ -198,7 +198,7 @@ public function meta_box( $post ) {
  • diff --git a/inc/functions-roles.php b/inc/functions-roles.php index 322355c..2852a33 100644 --- a/inc/functions-roles.php +++ b/inc/functions-roles.php @@ -40,7 +40,7 @@ function members_register_default_roles( $wp_roles ) { foreach ( $wp_roles->roles as $name => $object ) { $args = array( - 'label' => $object['name'], + 'label' => members_translate_role_hook( $object['name'], $name ), 'caps' => $object['capabilities'] ); @@ -247,7 +247,23 @@ function members_sanitize_role( $role ) { function members_translate_role( $role ) { global $wp_roles; - return apply_filters( 'members_translate_role', translate_user_role( $wp_roles->role_names[ $role ] ), $role ); + return members_translate_role_hook( $wp_roles->role_names[ $role ], $role ); +} + +/** + * Hook for translating user roles. I needed to separate this from the primary + * `members_translate_role()` function in case `$wp_roles` was not yet available + * but both the role and role label were. + * + * @since 2.0.1 + * @access public + * @param string $label + * @param string $role + * @return string + */ +function members_translate_role_hook( $label, $role ) { + + return apply_filters( 'members_translate_role', translate_user_role( $label ), $role ); } /**