[wp-trac] [WordPress Trac] #34608: Add role display name to WP_Role object

WordPress Trac noreply at wordpress.org
Fri Nov 6 20:32:04 UTC 2015


#34608: Add role display name to WP_Role object
-----------------------------+-----------------------------
 Reporter:  jdgrimes         |      Owner:
     Type:  defect (bug)     |     Status:  new
 Priority:  normal           |  Milestone:  Awaiting Review
Component:  Role/Capability  |    Version:  trunk
 Severity:  normal           |   Keywords:
  Focuses:                   |
-----------------------------+-----------------------------
 Roles have both a `name` (slug) and `display_name`. The `display_name` is
 saved to the database in an untranslated form, and should be translated
 with `translate_user_role()` before display.

 I would have thought that you could get the display name of a role by
 first calling `get_role()` to retrieve the `WP_Role` object, and then
 accessing a property or method. However, the `WP_Role` objects are
 constructed only with the `name` and capabilities of the role. It is
 therefore not possible to retrieve the `display_name` directly from the
 `WP_Role` object.

 Instead, to retrieve the `display_name` for a role, you have to call
 `WP_Roles::get_names()`, which returns an array of (untraslated) role
 display names (not the slug `name`s).

 I am proposing that we introduce a way to get the display name directly
 from the `WP_Role` object. Possibly we could offer two properties:
 `display_name` with the translated display name, and `raw_display_name`
 with the raw display name (in case it would actually be useful for
 anything). I would never have known that the role display names needed
 special treatment for translation if I hadn't done this digging, so it
 would probably be helpful to newbies if the translated names were exposed
 in the API by default, instead of untranslated. (Related: #20764)

 In the process, maybe it would be possible to clear up the difference
 between the name and the name, at least in the docs. Perhaps that deserves
 its own ticket. It really is confusing in the code though, so much so that
 I've had to double-check which name (the display or the slug) was the one
 passed to `WP_Role`. Both of them are just referred to as the name in much
 of the code.

 This goes all the way back to [2703] when the role classes were
 introduced.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/34608>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list