WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.32k stars 4.12k forks source link

Author's Username is missing from Author dropdown. #17364

Open TwisterMc opened 5 years ago

TwisterMc commented 5 years ago

Describe the bug In the classic editor, the author drop down included their name followed by their username in parentheses. This is needed when there are two or more people with the same name, or one user that has different kinds of access for testing things. Gutenberg however only shows the author's name.

To reproduce Steps to reproduce the behavior:

  1. Create a new post using the Classic editor.
  2. Click on the author drop down and you'll see users in this format: Name (username)
  3. Create a new post using the Gutenberg editor.
  4. Click on the author drop down and you'll see users in this format: Name

Expected behavior I'd see users in this format: Name (username)

Screenshots Gutenberg Classic Editor Quick Edit Post

Desktop (please complete the following information):

Additional context I marked this as a bug because the author drop down is consistent across the backend, except for in Gutenberg. If you were to quick edit a post or page, the format would match what I'm expecting. Gutenberg seems to be breaking the consistency.

Additionally my client has nearly 150 users so what we have today in Gutenberg doesn't scale well if we just assume there will never be two users with the same name.

I've also dug for hooks or filters to try and customize what appears in the author drop down but have had no luck.

draganescu commented 4 years ago

The REST API response to /wp/v2/users/&who=authors&per_page=100&_locale=user does not return username so that should be augmented 1st.

cc @spacedmonkey do you have any ideas here other than just adding a new field in the response with the username? I ask because slug already "seems" to be the username.

noisysocks commented 2 years ago

There's a new design by @javierarce for the Author dropdown in https://github.com/WordPress/gutenberg/pull/41430#issuecomment-1157690629. Perhaps we could include username in the line underneath the display name alongside the user's role?

It's worth noting is that users are able to select how they want their name to appear in profile settings. This should be respected.

Screen Shot 2022-07-15 at 13 14 23
yanksyoon commented 4 months ago

Hello! I am having the same issue with truncated response from the API - would there be a way to search by username only rather than including user's email in the search as well? Thank you!

draganescu commented 4 months ago

My previous comment is actually wrong. It appears that the endpoint is ready to return username, if it's present in the _fields param and the context is edit.

Currently the post authhor component in editor:

The context on request has to be view so that the list of authors can be retrieved even if the logged in user does not have edit context caps.

@swissspidy @TimothyBJacobs could you shed some light why on the user schema username is restricted to the edit context? It seems from the OP that the data is visible in author lists in other WP editors. Would you advise this control callse with an edit context just to get the username or change the schema to allow username (which is a user detail) be available in the view context.

I remember seeing people wanting to hide usernames for security reasons so I will assume the solution here is to:

TimothyBJacobs commented 4 months ago

Yeah, the username is not intended to be a public field so it's only available in edit. There is no cap like view_usernames, so we have to be more blunt. Fundamentally, we can't be as loosey goosey as a PHP interface (so to speak), because we aren't building bespoke endpoints for each interface.

So I'm not sure what the right solve here is, or if there even is a solve.

We could have a larger conversation around introducing a context like block-editor. That would be available to any user who can use a block editor. And then potentially expose the username field in the block-editor context. But even that isn't so obvious, for instance what happens with the "Block Editor Everywhere" project. It'd probably be unexpected that all form users on w.org could see usernames.

draganescu commented 4 months ago

Maybe then only users who can request the edit context will see the username like the OP exemplifies. Like in the editor if the logged in user is admin we request with edit and if not we request with view and no username appears in the control 🤷🏻

TimothyBJacobs commented 4 months ago

Yeah I think that would be where I lean to for a practical solve. The client can know whether the user has edit permissions, and can alter it's request appropriately.

abhi3315 commented 3 months ago

I was thinking about whether there should be an autocomplete feature to select authors. It could be very useful, especially if there are a lot of authors on a site. Although there are many plugins available to handle this, such as Co-Author Plus, having an autocomplete feature to list authors would make sense.