From 5cbf7edcc8b8d7ecf9633b9f96961d21e44f6f37 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 10 Oct 2022 17:57:52 +0000 Subject: [PATCH] Login and Registration: Rename `is_login_screen()` function to `is_login()`. As the function can be used in a variety of contexts, the `_screen` suffix may not always be appropriate. This commit aims to reduce confusion by renaming the newly added `is_login_screen()` function to `is_login()`, which better aligns with `is_admin()` and the related `is_*_admin()` function family. While it does not save a lot of lines of code, this function aims to save developers some time that would otherwise be spent investigating the most reliable way to determine whether the current request is for the login screen. Implementation details: * By checking `wp_login_url()`, the function accounts for custom login locations set via the `login_url` filter. * By checking `$_SERVER['SCRIPT_NAME']` directly, instead of `did_action( 'login_form_login' )` or `$pagenow` global, the function can work as early as possible, for example in a must-use plugin. Follow-up to [53884]. Props azaozz. Fixes #19898. See #56400. git-svn-id: https://develop.svn.wordpress.org/trunk@54447 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/load.php | 2 +- tests/phpunit/tests/load/isLogin.php | 21 +++++++++++++++++++++ tests/phpunit/tests/load/isLoginScreen.php | 21 --------------------- 3 files changed, 22 insertions(+), 22 deletions(-) create mode 100644 tests/phpunit/tests/load/isLogin.php delete mode 100644 tests/phpunit/tests/load/isLoginScreen.php diff --git a/src/wp-includes/load.php b/src/wp-includes/load.php index 91ddc56d34..183144ef9b 100644 --- a/src/wp-includes/load.php +++ b/src/wp-includes/load.php @@ -1150,7 +1150,7 @@ function wp_clone( $object ) { * * @return bool True if inside WordPress login screen, false otherwise. */ -function is_login_screen() { +function is_login() { return false !== stripos( wp_login_url(), $_SERVER['SCRIPT_NAME'] ); } diff --git a/tests/phpunit/tests/load/isLogin.php b/tests/phpunit/tests/load/isLogin.php new file mode 100644 index 0000000000..84d9a26d9a --- /dev/null +++ b/tests/phpunit/tests/load/isLogin.php @@ -0,0 +1,21 @@ +assertFalse( is_login() ); + + $_SERVER['SCRIPT_NAME'] = '/wp-login.php'; + + $this->assertTrue( is_login() ); + } +} diff --git a/tests/phpunit/tests/load/isLoginScreen.php b/tests/phpunit/tests/load/isLoginScreen.php deleted file mode 100644 index d0cd1df9a6..0000000000 --- a/tests/phpunit/tests/load/isLoginScreen.php +++ /dev/null @@ -1,21 +0,0 @@ -assertFalse( is_login_screen() ); - - $_SERVER['SCRIPT_NAME'] = '/wp-login.php'; - - $this->assertTrue( is_login_screen() ); - } -}