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
This commit is contained in:
Sergey Biryukov 2023-03-13 10:52:26 +00:00
parent aa66009d6a
commit 66896d0b65

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 );
}