Make WordPress Core

Opened 10 years ago

Last modified 5 years ago

#31106 new enhancement

Introduce nicename_exists

Reported by: voldemortensen's profile voldemortensen Owned by:
Milestone: 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 10 years ago.

Download all attachments as: .zip

Change History (6)

#1 follow-up: @nacin
10 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
10 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
10 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
10 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.


10 years ago

Note: See TracTickets for help on using tickets.