Coding Standards: Bring some consistency to wp_validate_redirect() existence checks.

The `wp_get_referer()` and `wp_get_original_referer()` functions both depend on `wp_validate_redirect()` and check whether it is defined by the time they run, but do so in a slightly different way.

This commit ensures both functions return early if they are called before `wp_validate_redirect()` is defined.

Follow-up to [3908], [25399], [25400].

See #57839.
Built from https://develop.svn.wordpress.org/trunk@55540


git-svn-id: http://core.svn.wordpress.org/trunk@55052 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2023-03-13 10:54:22 +00:00
parent a2c7bba031
commit 34662ac6d6
2 changed files with 11 additions and 3 deletions

View File

@ -1953,13 +1953,16 @@ function wp_original_referer_field( $display = true, $jump_back_to = 'current' )
* @return string|false Referer URL on success, false on failure.
*/
function wp_get_referer() {
// Return early if called before wp_validate_redirect() is defined.
if ( ! function_exists( 'wp_validate_redirect' ) ) {
return false;
}
$ref = wp_get_raw_referer();
if ( $ref && wp_unslash( $_SERVER['REQUEST_URI'] ) !== $ref && home_url() . wp_unslash( $_SERVER['REQUEST_URI'] ) !== $ref ) {
if ( $ref && wp_unslash( $_SERVER['REQUEST_URI'] ) !== $ref
&& home_url() . wp_unslash( $_SERVER['REQUEST_URI'] ) !== $ref
) {
return wp_validate_redirect( $ref, false );
}
@ -1993,7 +1996,12 @@ function wp_get_raw_referer() {
* @return string|false Original referer URL on success, false on failure.
*/
function wp_get_original_referer() {
if ( ! empty( $_REQUEST['_wp_original_http_referer'] ) && function_exists( 'wp_validate_redirect' ) ) {
// Return early if called before wp_validate_redirect() is defined.
if ( ! function_exists( 'wp_validate_redirect' ) ) {
return false;
}
if ( ! empty( $_REQUEST['_wp_original_http_referer'] ) ) {
return wp_validate_redirect( wp_unslash( $_REQUEST['_wp_original_http_referer'] ), false );
}

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.3-alpha-55539';
$wp_version = '6.3-alpha-55540';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.