Skip to content

Commit

Permalink
Merge pull request #7 from inpsyde/fix_is_login
Browse files Browse the repository at this point in the history
WpContext // fix isLoginRequest() to use correct new WP 6.1 Core function
  • Loading branch information
Chrico authored Jan 9, 2023
2 parents 1e30337 + c868dfc commit 1f61ccb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
20 changes: 16 additions & 4 deletions src/WpContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,28 @@ private static function isRestRequest(): bool
*/
private static function isLoginRequest(): bool
{
/** TODO: we'll just use is_login_screen() when 6.1 will be the min WP supported version */
if (function_exists('is_login_screen')) {
return is_login_screen() !== false;
/**
* New core function with WordPress 6.1
* @link https://make.wordpress.org/core/2022/09/11/new-is_login-function-for-determining-if-a-page-is-the-login-screen/
*/
if (function_exists('is_login')) {
return is_login() !== false;
}

if (!empty($_REQUEST['interim-login'])) { // phpcs:ignore
return true;
}

return static::isPageNow('wp-login.php', wp_login_url());
/**
* Fallback and 1:1 copy from is_login() in case, the function is
* not available for WP < 6.1.
* phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotValidated
* phpcs:disable WordPress.Security.ValidatedSanitizedInput.MissingUnslash
* phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
*/
$scriptName = $_SERVER['SCRIPT_NAME'] ?? '';

return false !== stripos(wp_login_url(), $scriptName);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/WpContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ private function mockIsRestRequest(bool $is): void
private function mockIsLoginRequest(bool $is): void
{
$is and $this->currentPath = '/wp-login.php';
Monkey\Functions\when('wp_login_url')->justReturn('https://example.com/wp-login.php');
Monkey\Functions\when('is_login')->justReturn($is);
}

/**
Expand Down

0 comments on commit 1f61ccb

Please sign in to comment.