Make WordPress Core


Ignore:
Timestamp:
03/13/2023 10:52:26 AM (3 years ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/functions.php

    r55514 r55540  
    19541954 */
    19551955function wp_get_referer() {
     1956        // Return early if called before wp_validate_redirect() is defined.
    19561957        if ( ! function_exists( 'wp_validate_redirect' ) ) {
    19571958                return false;
     
    19601961        $ref = wp_get_raw_referer();
    19611962
    1962         if ( $ref && wp_unslash( $_SERVER['REQUEST_URI'] ) !== $ref && home_url() . wp_unslash( $_SERVER['REQUEST_URI'] ) !== $ref ) {
     1963        if ( $ref && wp_unslash( $_SERVER['REQUEST_URI'] ) !== $ref
     1964                && home_url() . wp_unslash( $_SERVER['REQUEST_URI'] ) !== $ref
     1965        ) {
    19631966                return wp_validate_redirect( $ref, false );
    19641967        }
     
    19941997 */
    19951998function wp_get_original_referer() {
    1996         if ( ! empty( $_REQUEST['_wp_original_http_referer'] ) && function_exists( 'wp_validate_redirect' ) ) {
     1999        // Return early if called before wp_validate_redirect() is defined.
     2000        if ( ! function_exists( 'wp_validate_redirect' ) ) {
     2001                return false;
     2002        }
     2003
     2004        if ( ! empty( $_REQUEST['_wp_original_http_referer'] ) ) {
    19972005                return wp_validate_redirect( wp_unslash( $_REQUEST['_wp_original_http_referer'] ), false );
    19982006        }
Note: See TracChangeset for help on using the changeset viewer.