From d0a77e1108429370f984d35099ebdac7be0bfc28 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Tue, 20 Sep 2022 15:18:34 +0000 Subject: [PATCH] Bootstrap/Load: Introduce `is_*_admin_screen()` aliases for `is_*_admin()` function family. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. git-svn-id: https://develop.svn.wordpress.org/trunk@54259 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/capabilities.php | 16 +++++++ src/wp-includes/load.php | 72 ++++++++++++++++++++++++++++++-- 2 files changed, 84 insertions(+), 4 deletions(-) diff --git a/src/wp-includes/capabilities.php b/src/wp-includes/capabilities.php index 1e55d55f5382c..6c6b30575ad31 100644 --- a/src/wp-includes/capabilities.php +++ b/src/wp-includes/capabilities.php @@ -1084,6 +1084,22 @@ function get_super_admins() { } } +/** + * Determines whether user is a site admin. + * + * @since 6.1.0 + * + * This function is an alias for is_super_admin(). + * + * @see is_super_admin() + * + * @param int|false $user_id Optional. The ID of a user. Defaults to false, to check the current user. + * @return bool Whether the user is a site admin. + */ +function is_super_admin_user( $user_id = false ) { + return is_super_admin( $user_id ); +} + /** * Determines whether user is a site admin. * diff --git a/src/wp-includes/load.php b/src/wp-includes/load.php index f927fd3e4f5d7..6ea81319fe809 100644 --- a/src/wp-includes/load.php +++ b/src/wp-includes/load.php @@ -1154,6 +1154,21 @@ function is_login_screen() { return false !== stripos( wp_login_url(), $_SERVER['SCRIPT_NAME'] ); } +/** + * Determines whether the current request is for an administrative interface page. + * + * This function is an alias for is_admin(). + * + * @since 6.1.0 + * + * @see is_admin() + * + * @return bool True if inside WordPress administration interface, false otherwise. + */ +function is_admin_screen() { + return is_admin(); +} + /** * Determines whether the current request is for an administrative interface page. * @@ -1181,7 +1196,22 @@ function is_admin() { } /** - * Whether the current request is for a site's administrative interface. + * Determines whether the current request is for a site's administrative interface. + * + * This function is an alias for is_blog_admin(). + * + * @since 6.1.0 + * + * @see is_blog_admin() + * + * @return bool True if inside WordPress site administration pages. + */ +function is_site_admin_screen() { + return is_blog_admin(); +} + +/** + * Determines whether the current request is for a site's administrative interface. * * e.g. `/wp-admin/` * @@ -1192,7 +1222,7 @@ function is_admin() { * * @global WP_Screen $current_screen WordPress current screen object. * - * @return bool True if inside WordPress blog administration pages. + * @return bool True if inside WordPress site administration pages. */ function is_blog_admin() { if ( isset( $GLOBALS['current_screen'] ) ) { @@ -1205,7 +1235,24 @@ function is_blog_admin() { } /** - * Whether the current request is for the network administrative interface. + * Determines whether the current request is for the network administrative interface. + * + * e.g. `/wp-admin/network/` + * + * This function is an alias for is_network_admin(). + * + * @since 6.1.0 + * + * @see is_network_admin() + * + * @return bool True if inside WordPress network administration pages. + */ +function is_network_admin_screen() { + return is_network_admin(); +} + +/** + * Determines whether the current request is for the network administrative interface. * * e.g. `/wp-admin/network/` * @@ -1232,7 +1279,24 @@ function is_network_admin() { } /** - * Whether the current request is for a user admin screen. + * Determines whether the current request is for a user admin screen. + * + * e.g. `/wp-admin/user/` + * + * This function is an alias for is_user_admin(). + * + * @since 6.1.0 + * + * @see is_user_admin() + * + * @return bool True if inside WordPress user administration pages. + */ +function is_user_admin_screen() { + return is_user_admin(); +} + +/** + * Determines whether the current request is for a user admin screen. * * e.g. `/wp-admin/user/` *