From 66896d0b6550cdb5189f1e41a8a2bd3d76947afe Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 13 Mar 2023 10:52:26 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@55540 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/functions.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index fca19a32d5..8a02df2d5c 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -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 ); }