Make WordPress Core

Changeset 54259


Ignore:
Timestamp:
09/20/2022 03:18:34 PM (2 years ago)
Author:
SergeyBiryukov
Message:

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.

Location:
trunk/src/wp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/capabilities.php

    r54213 r54259  
    10881088 * Determines whether user is a site admin.
    10891089 *
     1090 * @since 6.1.0
     1091 *
     1092 * This function is an alias for is_super_admin().
     1093 *
     1094 * @see is_super_admin()
     1095 *
     1096 * @param int|false $user_id Optional. The ID of a user. Defaults to false, to check the current user.
     1097 * @return bool Whether the user is a site admin.
     1098 */
     1099function is_super_admin_user( $user_id = false ) {
     1100    return is_super_admin( $user_id );
     1101}
     1102
     1103/**
     1104 * Determines whether user is a site admin.
     1105 *
    10901106 * @since 3.0.0
    10911107 *
  • trunk/src/wp-includes/load.php

    r54239 r54259  
    11581158 * Determines whether the current request is for an administrative interface page.
    11591159 *
     1160 * This function is an alias for is_admin().
     1161 *
     1162 * @since 6.1.0
     1163 *
     1164 * @see is_admin()
     1165 *
     1166 * @return bool True if inside WordPress administration interface, false otherwise.
     1167 */
     1168function is_admin_screen() {
     1169    return is_admin();
     1170}
     1171
     1172/**
     1173 * Determines whether the current request is for an administrative interface page.
     1174 *
    11601175 * Does not check if the user is an administrator; use current_user_can()
    11611176 * for checking roles and capabilities.
     
    11821197
    11831198/**
    1184  * Whether the current request is for a site's administrative interface.
     1199 * Determines whether the current request is for a site's administrative interface.
     1200 *
     1201 * This function is an alias for is_blog_admin().
     1202 *
     1203 * @since 6.1.0
     1204 *
     1205 * @see is_blog_admin()
     1206 *
     1207 * @return bool True if inside WordPress site administration pages.
     1208 */
     1209function is_site_admin_screen() {
     1210    return is_blog_admin();
     1211}
     1212
     1213/**
     1214 * Determines whether the current request is for a site's administrative interface.
    11851215 *
    11861216 * e.g. `/wp-admin/`
     
    11931223 * @global WP_Screen $current_screen WordPress current screen object.
    11941224 *
    1195  * @return bool True if inside WordPress blog administration pages.
     1225 * @return bool True if inside WordPress site administration pages.
    11961226 */
    11971227function is_blog_admin() {
     
    12061236
    12071237/**
    1208  * Whether the current request is for the network administrative interface.
     1238 * Determines whether the current request is for the network administrative interface.
     1239 *
     1240 * e.g. `/wp-admin/network/`
     1241 *
     1242 * This function is an alias for is_network_admin().
     1243 *
     1244 * @since 6.1.0
     1245 *
     1246 * @see is_network_admin()
     1247 *
     1248 * @return bool True if inside WordPress network administration pages.
     1249 */
     1250function is_network_admin_screen() {
     1251    return is_network_admin();
     1252}
     1253
     1254/**
     1255 * Determines whether the current request is for the network administrative interface.
    12091256 *
    12101257 * e.g. `/wp-admin/network/`
     
    12331280
    12341281/**
    1235  * Whether the current request is for a user admin screen.
     1282 * Determines whether the current request is for a user admin screen.
     1283 *
     1284 * e.g. `/wp-admin/user/`
     1285 *
     1286 * This function is an alias for is_user_admin().
     1287 *
     1288 * @since 6.1.0
     1289 *
     1290 * @see is_user_admin()
     1291 *
     1292 * @return bool True if inside WordPress user administration pages.
     1293 */
     1294function is_user_admin_screen() {
     1295    return is_user_admin();
     1296}
     1297
     1298/**
     1299 * Determines whether the current request is for a user admin screen.
    12361300 *
    12371301 * e.g. `/wp-admin/user/`
Note: See TracChangeset for help on using the changeset viewer.