From 34662ac6d6bd2646b24adddb3959525e24fdbb6f Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 13 Mar 2023 10:54:22 +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. Built from https://develop.svn.wordpress.org/trunk@55540 git-svn-id: http://core.svn.wordpress.org/trunk@55052 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/functions.php | 12 ++++++++++-- wp-includes/version.php | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/wp-includes/functions.php b/wp-includes/functions.php index fca19a32d5..8a02df2d5c 100644 --- a/wp-includes/functions.php +++ b/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 ); } diff --git a/wp-includes/version.php b/wp-includes/version.php index eb2478a980..ecd6379884 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -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.