WordPress.org

Make WordPress Core

Ticket #39695: pluggable.patch

File pluggable.patch, 1.8 KB (added by onnimonni, 3 years ago)

Patch for pluggable.php

  • .php

    old new  
    11761176        if ( !$is_IIS && PHP_SAPI != 'cgi-fcgi' )
    11771177                status_header($status); // This causes problems on IIS and some FastCGI setups
    11781178
     1179    /**
     1180     * http2 enabled servers can push the redirected document immediately to client
     1181     */
     1182    wp_maybe_add_preload_headers($location);
     1183
    11791184    header("Location: $location", true, $status);
    11801185
    11811186    return true;
    11821187}
    11831188endif;
    11841189
     1190if ( !function_exists('wp_maybe_add_redirect_preload_headers') ) :
     1191/**
     1192 * Checks if redirected asset can be preloaded as document
     1193 *
     1194 * @param string $location The path to redirect to.
     1195 * @return bool Redirect-sanitized URL.
     1196 **/
     1197function wp_maybe_add_redirect_preload_headers($location) {
     1198
     1199    $link = null;
     1200
     1201    /**
     1202     * Check if this is redirect to the same domain so we can add Link headers
     1203     */
     1204    $siteurl = site_url();
     1205    if ( substr( $location, 0, 1 ) === '/' || substr( $location, 0, strlen( $siteurl ) ) === $siteurl ) {
     1206
     1207        $location_parts = parse_url( $location );
     1208
     1209        if ( substr($location_parts['path'],-1) === '/' ||
     1210             substr($location_parts['path'],-4) === '.php' ||
     1211             substr($location_parts['path'],-5) === '.html' ) {
     1212
     1213            $link = $location_parts['path'];
     1214            if ( isset( $location_parts['fragment'] ) )
     1215                $link .= $location_parts['fragment'];
     1216            if ( isset( $location_parts['query'] ) )
     1217                $link .= '?' . $location_parts['query'];
     1218        }
     1219    }
     1220    $link = apply_filters( 'wp_maybe_add_preload_headers', $link, $location );
     1221
     1222    if ( $link )
     1223        header("Link: <{$link}>; rel=preload; as=document", false);
     1224}
     1225endif;
     1226
    11851227if ( !function_exists('wp_sanitize_redirect') ) :
    11861228/**
    11871229 * Sanitizes a URL for use in a redirect.