Make WordPress Core

Changeset 54447


Ignore:
Timestamp:
10/10/2022 05:57:52 PM (2 years ago)
Author:
SergeyBiryukov
Message:

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.

Location:
trunk
Files:
1 edited
1 moved

Legend:

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

    r54332 r54447  
    11511151 * @return bool True if inside WordPress login screen, false otherwise.
    11521152 */
    1153 function is_login_screen() {
     1153function is_login() {
    11541154    return false !== stripos( wp_login_url(), $_SERVER['SCRIPT_NAME'] );
    11551155}
  • trunk/tests/phpunit/tests/load/isLogin.php

    r54446 r54447  
    22
    33/**
    4  * Tests for is_login_screen().
     4 * Tests for is_login().
    55 *
    66 * @group load.php
    7  * @covers ::is_login_screen
     7 * @covers ::is_login
    88 */
    9 class Tests_Load_IsLoginScreen extends WP_UnitTestCase {
     9class Tests_Load_IsLogin extends WP_UnitTestCase {
    1010
    1111    /**
    1212     * @ticket 19898
    1313     */
    14     public function test_is_login_screen() {
    15         $this->assertFalse( is_login_screen() );
     14    public function test_is_login() {
     15        $this->assertFalse( is_login() );
    1616
    1717        $_SERVER['SCRIPT_NAME'] = '/wp-login.php';
    1818
    19         $this->assertTrue( is_login_screen() );
     19        $this->assertTrue( is_login() );
    2020    }
    2121}
Note: See TracChangeset for help on using the changeset viewer.