WordPress.org

Make WordPress Core

Opened 3 years ago

Last modified 3 years ago

#31106 new enhancement

Introduce nicename_exists

Reported by: voldemortensen Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Users Keywords: has-patch
Focuses: Cc:

Description

Currently there are functions for username_exists and email_exists, but none for nicename_exists. Patch introduces nicename_exists with accompanying unit tests.

Related: #30647

Attachments (1)

31106.diff (1.2 KB) - added by voldemortensen 3 years ago.

Download all attachments as: .zip

Change History (6)

@voldemortensen
3 years ago

#1 follow-up: @nacin
3 years ago

I'm not sure we need to bother with this — I'd rather encourage usage of get_user_by(), which is a bit newer than the other _exists() functions. Thoughts?

#2 in reply to: ↑ 1 @SergeyBiryukov
3 years ago

Replying to nacin:

I'd rather encourage usage of get_user_by(), which is a bit newer than the other _exists() functions. Thoughts?

I agree. Getting a user by slug isn't as common as by ID or email (we only do that once in core), so this seems like unnecessary abstraction to me.

#3 @voldemortensen
3 years ago

I think
if(!nicename_exists( 'stuff' ) ) { things(); }
looks cleaner and more readable than
if(!get_user_by( 'slug', 'stuff' ) ) { things(); }

Which raises another issue of 'slug' being slightly confusing. It would make more sense if get_user_by( 'nicename', 'stuff' ) available.

#4 @voldemortensen
3 years ago

Additionally, the more I think about it the more it semantically makes sense.
get_user_by seems to be used with the expectation that a user will be returned and error if the user doesn't exist. *_exists seem to be used when we aren't sure or are hoping that a user doesn't exist.

This ticket was mentioned in Slack in #core by drew. View the logs.


3 years ago

Note: See TracTickets for help on using tickets.