Make WordPress Core


Ignore:
Timestamp:
08/11/2022 09:49:08 PM (23 months ago)
Author:
SergeyBiryukov
Message:

Login and Registration: Introduce is_login_screen() function.

This should help determine whether the current request is for the login screen.

While it does not save a lot of lines of code, including this function in core aims to save developers some time that would otherwise be spent investigating the most reliable way to solve this problem.

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 [2481], [6412], [12393], [12732], [15558], [15481], [15746].

Props dcowgill, scribu, donmhico, iandunn, wonderboymusic, nacin, robmiller, kitchin, chriscct7, tazotodua, davidbaumwald, SergeyBiryukov.
Fixes #19898.

File:
1 edited

Legend:

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

    r53832 r53884  
    11421142
    11431143/**
     1144 * Determines whether the current request is for the login screen.
     1145 *
     1146 * @since 6.1.0
     1147 *
     1148 * @see wp_login_url()
     1149 *
     1150 * @return bool True if inside WordPress login screen, false otherwise.
     1151 */
     1152function is_login_screen() {
     1153    return false !== stripos( wp_login_url(), $_SERVER['SCRIPT_NAME'] );
     1154}
     1155
     1156/**
    11441157 * Determines whether the current request is for an administrative interface page.
    11451158 *
Note: See TracChangeset for help on using the changeset viewer.