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
This commit is contained in:
Sergey Biryukov 2022-10-10 17:57:52 +00:00
parent bd001e80df
commit 5cbf7edcc8
3 changed files with 22 additions and 22 deletions

View File

@ -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'] );
}

View File

@ -0,0 +1,21 @@
<?php
/**
* Tests for is_login().
*
* @group load.php
* @covers ::is_login
*/
class Tests_Load_IsLogin extends WP_UnitTestCase {
/**
* @ticket 19898
*/
public function test_is_login() {
$this->assertFalse( is_login() );
$_SERVER['SCRIPT_NAME'] = '/wp-login.php';
$this->assertTrue( is_login() );
}
}

View File

@ -1,21 +0,0 @@
<?php
/**
* Tests for is_login_screen().
*
* @group load.php
* @covers ::is_login_screen
*/
class Tests_Load_IsLoginScreen extends WP_UnitTestCase {
/**
* @ticket 19898
*/
public function test_is_login_screen() {
$this->assertFalse( is_login_screen() );
$_SERVER['SCRIPT_NAME'] = '/wp-login.php';
$this->assertTrue( is_login_screen() );
}
}