[wp-trac] [WordPress Trac] #56400: Rename is_admin() and related functions for clarity

WordPress Trac noreply at wordpress.org
Tue Sep 20 15:18:49 UTC 2022


#56400: Rename is_admin() and related functions for clarity
----------------------------+-----------------------------
 Reporter:  SergeyBiryukov  |       Owner:  SergeyBiryukov
     Type:  enhancement     |      Status:  accepted
 Priority:  normal          |   Milestone:  6.1
Component:  Bootstrap/Load  |     Version:
 Severity:  normal          |  Resolution:
 Keywords:                  |     Focuses:
----------------------------+-----------------------------

Comment (by SergeyBiryukov):

 In [changeset:"54259" 54259]:
 {{{
 #!CommitTicketReference repository="" revision="54259"
 Bootstrap/Load: Introduce `is_*_admin_screen()` aliases for `is_*_admin()`
 function family.

 Following the introduction of `is_login_screen()` in [53884], it is time
 to reconsider the `is_*_admin()` functions:

 * `is_admin()`: Determines whether the current request is for an
 administrative interface page.
 * `is_blog_admin()`: Whether the current request is for a site's
 administrative interface, e.g. `/wp-admin/`.
 * `is_network_admin()`: Whether the current request is for the network
 administrative interface, e.g. `/wp-admin/network/`.
 * `is_user_admin()`: Whether the current request is for a user admin
 screen, e.g. `/wp-admin/user/`.

 For someone new to WordPress, these names can be quite confusing,
 especially the last one. When using these functions, one always needs to
 remember that they don't actually check if the current user is a site
 administrator.

 To complicate things further, there is one more similarly named function
 that does exactly the latter:
 * `is_super_admin()`: Determines whether user is a site admin.

 With the above in mind, this commit introduces aliases that better match
 the functionality and allow for more descriptive code:

 * `is_admin()` → `is_admin_screen()`
 * `is_blog_admin()` → `is_site_admin_screen()`
 * `is_network_admin()` → `is_network_admin_screen()`
 * `is_user_admin()` → `is_user_admin_screen()`

 Additionally, `is_super_admin_user()` is introduced as an alias for
 `is_super_admin()`:
 * `is_super_admin()` → `is_super_admin_user()`

 Plugins and themes are encouraged to start using the newer function names
 to make code self-descriptive and bring more clarity. The older names are
 not deprecated at this time, though it may be up for discussion in the
 future.

 Follow-up to [2481], [6412], [12393], [12732], [15558], [15481], [15746],
 [53884].

 Props jrf, tobifjellner, SergeyBiryukov.
 See #56400.
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/56400#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list