Edit File by line
/home/barbar84/www/wp-inclu...
File: class-wp.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* WordPress environment setup class.
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @since 2.0.0
[5] Fix | Delete
*/
[6] Fix | Delete
class WP {
[7] Fix | Delete
/**
[8] Fix | Delete
* Public query variables.
[9] Fix | Delete
*
[10] Fix | Delete
* Long list of public query variables.
[11] Fix | Delete
*
[12] Fix | Delete
* @since 2.0.0
[13] Fix | Delete
* @var string[]
[14] Fix | Delete
*/
[15] Fix | Delete
public $public_query_vars = array( 'm', 'p', 'posts', 'w', 'cat', 'withcomments', 'withoutcomments', 's', 'search', 'exact', 'sentence', 'calendar', 'page', 'paged', 'more', 'tb', 'pb', 'author', 'order', 'orderby', 'year', 'monthnum', 'day', 'hour', 'minute', 'second', 'name', 'category_name', 'tag', 'feed', 'author_name', 'pagename', 'page_id', 'error', 'attachment', 'attachment_id', 'subpost', 'subpost_id', 'preview', 'robots', 'favicon', 'taxonomy', 'term', 'cpage', 'post_type', 'embed' );
[16] Fix | Delete
[17] Fix | Delete
/**
[18] Fix | Delete
* Private query variables.
[19] Fix | Delete
*
[20] Fix | Delete
* Long list of private query variables.
[21] Fix | Delete
*
[22] Fix | Delete
* @since 2.0.0
[23] Fix | Delete
* @var string[]
[24] Fix | Delete
*/
[25] Fix | Delete
public $private_query_vars = array( 'offset', 'posts_per_page', 'posts_per_archive_page', 'showposts', 'nopaging', 'post_type', 'post_status', 'category__in', 'category__not_in', 'category__and', 'tag__in', 'tag__not_in', 'tag__and', 'tag_slug__in', 'tag_slug__and', 'tag_id', 'post_mime_type', 'perm', 'comments_per_page', 'post__in', 'post__not_in', 'post_parent', 'post_parent__in', 'post_parent__not_in', 'title', 'fields' );
[26] Fix | Delete
[27] Fix | Delete
/**
[28] Fix | Delete
* Extra query variables set by the user.
[29] Fix | Delete
*
[30] Fix | Delete
* @since 2.1.0
[31] Fix | Delete
* @var array
[32] Fix | Delete
*/
[33] Fix | Delete
public $extra_query_vars = array();
[34] Fix | Delete
[35] Fix | Delete
/**
[36] Fix | Delete
* Query variables for setting up the WordPress Query Loop.
[37] Fix | Delete
*
[38] Fix | Delete
* @since 2.0.0
[39] Fix | Delete
* @var array
[40] Fix | Delete
*/
[41] Fix | Delete
public $query_vars;
[42] Fix | Delete
[43] Fix | Delete
/**
[44] Fix | Delete
* String parsed to set the query variables.
[45] Fix | Delete
*
[46] Fix | Delete
* @since 2.0.0
[47] Fix | Delete
* @var string
[48] Fix | Delete
*/
[49] Fix | Delete
public $query_string;
[50] Fix | Delete
[51] Fix | Delete
/**
[52] Fix | Delete
* The request path, e.g. 2015/05/06.
[53] Fix | Delete
*
[54] Fix | Delete
* @since 2.0.0
[55] Fix | Delete
* @var string
[56] Fix | Delete
*/
[57] Fix | Delete
public $request;
[58] Fix | Delete
[59] Fix | Delete
/**
[60] Fix | Delete
* Rewrite rule the request matched.
[61] Fix | Delete
*
[62] Fix | Delete
* @since 2.0.0
[63] Fix | Delete
* @var string
[64] Fix | Delete
*/
[65] Fix | Delete
public $matched_rule;
[66] Fix | Delete
[67] Fix | Delete
/**
[68] Fix | Delete
* Rewrite query the request matched.
[69] Fix | Delete
*
[70] Fix | Delete
* @since 2.0.0
[71] Fix | Delete
* @var string
[72] Fix | Delete
*/
[73] Fix | Delete
public $matched_query;
[74] Fix | Delete
[75] Fix | Delete
/**
[76] Fix | Delete
* Whether already did the permalink.
[77] Fix | Delete
*
[78] Fix | Delete
* @since 2.0.0
[79] Fix | Delete
* @var bool
[80] Fix | Delete
*/
[81] Fix | Delete
public $did_permalink = false;
[82] Fix | Delete
[83] Fix | Delete
/**
[84] Fix | Delete
* Adds a query variable to the list of public query variables.
[85] Fix | Delete
*
[86] Fix | Delete
* @since 2.1.0
[87] Fix | Delete
*
[88] Fix | Delete
* @param string $qv Query variable name.
[89] Fix | Delete
*/
[90] Fix | Delete
public function add_query_var( $qv ) {
[91] Fix | Delete
if ( ! in_array( $qv, $this->public_query_vars, true ) ) {
[92] Fix | Delete
$this->public_query_vars[] = $qv;
[93] Fix | Delete
}
[94] Fix | Delete
}
[95] Fix | Delete
[96] Fix | Delete
/**
[97] Fix | Delete
* Removes a query variable from a list of public query variables.
[98] Fix | Delete
*
[99] Fix | Delete
* @since 4.5.0
[100] Fix | Delete
*
[101] Fix | Delete
* @param string $name Query variable name.
[102] Fix | Delete
*/
[103] Fix | Delete
public function remove_query_var( $name ) {
[104] Fix | Delete
$this->public_query_vars = array_diff( $this->public_query_vars, array( $name ) );
[105] Fix | Delete
}
[106] Fix | Delete
[107] Fix | Delete
/**
[108] Fix | Delete
* Sets the value of a query variable.
[109] Fix | Delete
*
[110] Fix | Delete
* @since 2.3.0
[111] Fix | Delete
*
[112] Fix | Delete
* @param string $key Query variable name.
[113] Fix | Delete
* @param mixed $value Query variable value.
[114] Fix | Delete
*/
[115] Fix | Delete
public function set_query_var( $key, $value ) {
[116] Fix | Delete
$this->query_vars[ $key ] = $value;
[117] Fix | Delete
}
[118] Fix | Delete
[119] Fix | Delete
/**
[120] Fix | Delete
* Parses the request to find the correct WordPress query.
[121] Fix | Delete
*
[122] Fix | Delete
* Sets up the query variables based on the request. There are also many
[123] Fix | Delete
* filters and actions that can be used to further manipulate the result.
[124] Fix | Delete
*
[125] Fix | Delete
* @since 2.0.0
[126] Fix | Delete
*
[127] Fix | Delete
* @global WP_Rewrite $wp_rewrite WordPress rewrite component.
[128] Fix | Delete
*
[129] Fix | Delete
* @param array|string $extra_query_vars Set the extra query variables.
[130] Fix | Delete
*/
[131] Fix | Delete
public function parse_request( $extra_query_vars = '' ) {
[132] Fix | Delete
global $wp_rewrite;
[133] Fix | Delete
[134] Fix | Delete
/**
[135] Fix | Delete
* Filters whether to parse the request.
[136] Fix | Delete
*
[137] Fix | Delete
* @since 3.5.0
[138] Fix | Delete
*
[139] Fix | Delete
* @param bool $bool Whether or not to parse the request. Default true.
[140] Fix | Delete
* @param WP $this Current WordPress environment instance.
[141] Fix | Delete
* @param array|string $extra_query_vars Extra passed query variables.
[142] Fix | Delete
*/
[143] Fix | Delete
if ( ! apply_filters( 'do_parse_request', true, $this, $extra_query_vars ) ) {
[144] Fix | Delete
return;
[145] Fix | Delete
}
[146] Fix | Delete
[147] Fix | Delete
$this->query_vars = array();
[148] Fix | Delete
$post_type_query_vars = array();
[149] Fix | Delete
[150] Fix | Delete
if ( is_array( $extra_query_vars ) ) {
[151] Fix | Delete
$this->extra_query_vars = & $extra_query_vars;
[152] Fix | Delete
} elseif ( ! empty( $extra_query_vars ) ) {
[153] Fix | Delete
parse_str( $extra_query_vars, $this->extra_query_vars );
[154] Fix | Delete
}
[155] Fix | Delete
// Process PATH_INFO, REQUEST_URI, and 404 for permalinks.
[156] Fix | Delete
[157] Fix | Delete
// Fetch the rewrite rules.
[158] Fix | Delete
$rewrite = $wp_rewrite->wp_rewrite_rules();
[159] Fix | Delete
[160] Fix | Delete
if ( ! empty( $rewrite ) ) {
[161] Fix | Delete
// If we match a rewrite rule, this will be cleared.
[162] Fix | Delete
$error = '404';
[163] Fix | Delete
$this->did_permalink = true;
[164] Fix | Delete
[165] Fix | Delete
$pathinfo = isset( $_SERVER['PATH_INFO'] ) ? $_SERVER['PATH_INFO'] : '';
[166] Fix | Delete
list( $pathinfo ) = explode( '?', $pathinfo );
[167] Fix | Delete
$pathinfo = str_replace( '%', '%25', $pathinfo );
[168] Fix | Delete
[169] Fix | Delete
list( $req_uri ) = explode( '?', $_SERVER['REQUEST_URI'] );
[170] Fix | Delete
$self = $_SERVER['PHP_SELF'];
[171] Fix | Delete
$home_path = trim( parse_url( home_url(), PHP_URL_PATH ), '/' );
[172] Fix | Delete
$home_path_regex = sprintf( '|^%s|i', preg_quote( $home_path, '|' ) );
[173] Fix | Delete
[174] Fix | Delete
/*
[175] Fix | Delete
* Trim path info from the end and the leading home path from the front.
[176] Fix | Delete
* For path info requests, this leaves us with the requesting filename, if any.
[177] Fix | Delete
* For 404 requests, this leaves us with the requested permalink.
[178] Fix | Delete
*/
[179] Fix | Delete
$req_uri = str_replace( $pathinfo, '', $req_uri );
[180] Fix | Delete
$req_uri = trim( $req_uri, '/' );
[181] Fix | Delete
$req_uri = preg_replace( $home_path_regex, '', $req_uri );
[182] Fix | Delete
$req_uri = trim( $req_uri, '/' );
[183] Fix | Delete
$pathinfo = trim( $pathinfo, '/' );
[184] Fix | Delete
$pathinfo = preg_replace( $home_path_regex, '', $pathinfo );
[185] Fix | Delete
$pathinfo = trim( $pathinfo, '/' );
[186] Fix | Delete
$self = trim( $self, '/' );
[187] Fix | Delete
$self = preg_replace( $home_path_regex, '', $self );
[188] Fix | Delete
$self = trim( $self, '/' );
[189] Fix | Delete
[190] Fix | Delete
// The requested permalink is in $pathinfo for path info requests and
[191] Fix | Delete
// $req_uri for other requests.
[192] Fix | Delete
if ( ! empty( $pathinfo ) && ! preg_match( '|^.*' . $wp_rewrite->index . '$|', $pathinfo ) ) {
[193] Fix | Delete
$requested_path = $pathinfo;
[194] Fix | Delete
} else {
[195] Fix | Delete
// If the request uri is the index, blank it out so that we don't try to match it against a rule.
[196] Fix | Delete
if ( $req_uri == $wp_rewrite->index ) {
[197] Fix | Delete
$req_uri = '';
[198] Fix | Delete
}
[199] Fix | Delete
$requested_path = $req_uri;
[200] Fix | Delete
}
[201] Fix | Delete
$requested_file = $req_uri;
[202] Fix | Delete
[203] Fix | Delete
$this->request = $requested_path;
[204] Fix | Delete
[205] Fix | Delete
// Look for matches.
[206] Fix | Delete
$request_match = $requested_path;
[207] Fix | Delete
if ( empty( $request_match ) ) {
[208] Fix | Delete
// An empty request could only match against ^$ regex.
[209] Fix | Delete
if ( isset( $rewrite['$'] ) ) {
[210] Fix | Delete
$this->matched_rule = '$';
[211] Fix | Delete
$query = $rewrite['$'];
[212] Fix | Delete
$matches = array( '' );
[213] Fix | Delete
}
[214] Fix | Delete
} else {
[215] Fix | Delete
foreach ( (array) $rewrite as $match => $query ) {
[216] Fix | Delete
// If the requested file is the anchor of the match, prepend it to the path info.
[217] Fix | Delete
if ( ! empty( $requested_file ) && strpos( $match, $requested_file ) === 0 && $requested_file != $requested_path ) {
[218] Fix | Delete
$request_match = $requested_file . '/' . $requested_path;
[219] Fix | Delete
}
[220] Fix | Delete
[221] Fix | Delete
if ( preg_match( "#^$match#", $request_match, $matches ) ||
[222] Fix | Delete
preg_match( "#^$match#", urldecode( $request_match ), $matches ) ) {
[223] Fix | Delete
[224] Fix | Delete
if ( $wp_rewrite->use_verbose_page_rules && preg_match( '/pagename=\$matches\[([0-9]+)\]/', $query, $varmatch ) ) {
[225] Fix | Delete
// This is a verbose page match, let's check to be sure about it.
[226] Fix | Delete
$page = get_page_by_path( $matches[ $varmatch[1] ] );
[227] Fix | Delete
if ( ! $page ) {
[228] Fix | Delete
continue;
[229] Fix | Delete
}
[230] Fix | Delete
[231] Fix | Delete
$post_status_obj = get_post_status_object( $page->post_status );
[232] Fix | Delete
if ( ! $post_status_obj->public && ! $post_status_obj->protected
[233] Fix | Delete
&& ! $post_status_obj->private && $post_status_obj->exclude_from_search ) {
[234] Fix | Delete
continue;
[235] Fix | Delete
}
[236] Fix | Delete
}
[237] Fix | Delete
[238] Fix | Delete
// Got a match.
[239] Fix | Delete
$this->matched_rule = $match;
[240] Fix | Delete
break;
[241] Fix | Delete
}
[242] Fix | Delete
}
[243] Fix | Delete
}
[244] Fix | Delete
[245] Fix | Delete
if ( isset( $this->matched_rule ) ) {
[246] Fix | Delete
// Trim the query of everything up to the '?'.
[247] Fix | Delete
$query = preg_replace( '!^.+\?!', '', $query );
[248] Fix | Delete
[249] Fix | Delete
// Substitute the substring matches into the query.
[250] Fix | Delete
$query = addslashes( WP_MatchesMapRegex::apply( $query, $matches ) );
[251] Fix | Delete
[252] Fix | Delete
$this->matched_query = $query;
[253] Fix | Delete
[254] Fix | Delete
// Parse the query.
[255] Fix | Delete
parse_str( $query, $perma_query_vars );
[256] Fix | Delete
[257] Fix | Delete
// If we're processing a 404 request, clear the error var since we found something.
[258] Fix | Delete
if ( '404' == $error ) {
[259] Fix | Delete
unset( $error, $_GET['error'] );
[260] Fix | Delete
}
[261] Fix | Delete
}
[262] Fix | Delete
[263] Fix | Delete
// If req_uri is empty or if it is a request for ourself, unset error.
[264] Fix | Delete
if ( empty( $requested_path ) || $requested_file == $self || strpos( $_SERVER['PHP_SELF'], 'wp-admin/' ) !== false ) {
[265] Fix | Delete
unset( $error, $_GET['error'] );
[266] Fix | Delete
[267] Fix | Delete
if ( isset( $perma_query_vars ) && strpos( $_SERVER['PHP_SELF'], 'wp-admin/' ) !== false ) {
[268] Fix | Delete
unset( $perma_query_vars );
[269] Fix | Delete
}
[270] Fix | Delete
[271] Fix | Delete
$this->did_permalink = false;
[272] Fix | Delete
}
[273] Fix | Delete
}
[274] Fix | Delete
[275] Fix | Delete
/**
[276] Fix | Delete
* Filters the query variables allowed before processing.
[277] Fix | Delete
*
[278] Fix | Delete
* Allows (publicly allowed) query vars to be added, removed, or changed prior
[279] Fix | Delete
* to executing the query. Needed to allow custom rewrite rules using your own arguments
[280] Fix | Delete
* to work, or any other custom query variables you want to be publicly available.
[281] Fix | Delete
*
[282] Fix | Delete
* @since 1.5.0
[283] Fix | Delete
*
[284] Fix | Delete
* @param string[] $public_query_vars The array of allowed query variable names.
[285] Fix | Delete
*/
[286] Fix | Delete
$this->public_query_vars = apply_filters( 'query_vars', $this->public_query_vars );
[287] Fix | Delete
[288] Fix | Delete
foreach ( get_post_types( array(), 'objects' ) as $post_type => $t ) {
[289] Fix | Delete
if ( is_post_type_viewable( $t ) && $t->query_var ) {
[290] Fix | Delete
$post_type_query_vars[ $t->query_var ] = $post_type;
[291] Fix | Delete
}
[292] Fix | Delete
}
[293] Fix | Delete
[294] Fix | Delete
foreach ( $this->public_query_vars as $wpvar ) {
[295] Fix | Delete
if ( isset( $this->extra_query_vars[ $wpvar ] ) ) {
[296] Fix | Delete
$this->query_vars[ $wpvar ] = $this->extra_query_vars[ $wpvar ];
[297] Fix | Delete
} elseif ( isset( $_GET[ $wpvar ] ) && isset( $_POST[ $wpvar ] ) && $_GET[ $wpvar ] !== $_POST[ $wpvar ] ) {
[298] Fix | Delete
wp_die( __( 'A variable mismatch has been detected.' ), __( 'Sorry, you are not allowed to view this item.' ), 400 );
[299] Fix | Delete
} elseif ( isset( $_POST[ $wpvar ] ) ) {
[300] Fix | Delete
$this->query_vars[ $wpvar ] = $_POST[ $wpvar ];
[301] Fix | Delete
} elseif ( isset( $_GET[ $wpvar ] ) ) {
[302] Fix | Delete
$this->query_vars[ $wpvar ] = $_GET[ $wpvar ];
[303] Fix | Delete
} elseif ( isset( $perma_query_vars[ $wpvar ] ) ) {
[304] Fix | Delete
$this->query_vars[ $wpvar ] = $perma_query_vars[ $wpvar ];
[305] Fix | Delete
}
[306] Fix | Delete
[307] Fix | Delete
if ( ! empty( $this->query_vars[ $wpvar ] ) ) {
[308] Fix | Delete
if ( ! is_array( $this->query_vars[ $wpvar ] ) ) {
[309] Fix | Delete
$this->query_vars[ $wpvar ] = (string) $this->query_vars[ $wpvar ];
[310] Fix | Delete
} else {
[311] Fix | Delete
foreach ( $this->query_vars[ $wpvar ] as $vkey => $v ) {
[312] Fix | Delete
if ( is_scalar( $v ) ) {
[313] Fix | Delete
$this->query_vars[ $wpvar ][ $vkey ] = (string) $v;
[314] Fix | Delete
}
[315] Fix | Delete
}
[316] Fix | Delete
}
[317] Fix | Delete
[318] Fix | Delete
if ( isset( $post_type_query_vars[ $wpvar ] ) ) {
[319] Fix | Delete
$this->query_vars['post_type'] = $post_type_query_vars[ $wpvar ];
[320] Fix | Delete
$this->query_vars['name'] = $this->query_vars[ $wpvar ];
[321] Fix | Delete
}
[322] Fix | Delete
}
[323] Fix | Delete
}
[324] Fix | Delete
[325] Fix | Delete
// Convert urldecoded spaces back into '+'.
[326] Fix | Delete
foreach ( get_taxonomies( array(), 'objects' ) as $taxonomy => $t ) {
[327] Fix | Delete
if ( $t->query_var && isset( $this->query_vars[ $t->query_var ] ) ) {
[328] Fix | Delete
$this->query_vars[ $t->query_var ] = str_replace( ' ', '+', $this->query_vars[ $t->query_var ] );
[329] Fix | Delete
}
[330] Fix | Delete
}
[331] Fix | Delete
[332] Fix | Delete
// Don't allow non-publicly queryable taxonomies to be queried from the front end.
[333] Fix | Delete
if ( ! is_admin() ) {
[334] Fix | Delete
foreach ( get_taxonomies( array( 'publicly_queryable' => false ), 'objects' ) as $taxonomy => $t ) {
[335] Fix | Delete
/*
[336] Fix | Delete
* Disallow when set to the 'taxonomy' query var.
[337] Fix | Delete
* Non-publicly queryable taxonomies cannot register custom query vars. See register_taxonomy().
[338] Fix | Delete
*/
[339] Fix | Delete
if ( isset( $this->query_vars['taxonomy'] ) && $taxonomy === $this->query_vars['taxonomy'] ) {
[340] Fix | Delete
unset( $this->query_vars['taxonomy'], $this->query_vars['term'] );
[341] Fix | Delete
}
[342] Fix | Delete
}
[343] Fix | Delete
}
[344] Fix | Delete
[345] Fix | Delete
// Limit publicly queried post_types to those that are 'publicly_queryable'.
[346] Fix | Delete
if ( isset( $this->query_vars['post_type'] ) ) {
[347] Fix | Delete
$queryable_post_types = get_post_types( array( 'publicly_queryable' => true ) );
[348] Fix | Delete
if ( ! is_array( $this->query_vars['post_type'] ) ) {
[349] Fix | Delete
if ( ! in_array( $this->query_vars['post_type'], $queryable_post_types, true ) ) {
[350] Fix | Delete
unset( $this->query_vars['post_type'] );
[351] Fix | Delete
}
[352] Fix | Delete
} else {
[353] Fix | Delete
$this->query_vars['post_type'] = array_intersect( $this->query_vars['post_type'], $queryable_post_types );
[354] Fix | Delete
}
[355] Fix | Delete
}
[356] Fix | Delete
[357] Fix | Delete
// Resolve conflicts between posts with numeric slugs and date archive queries.
[358] Fix | Delete
$this->query_vars = wp_resolve_numeric_slug_conflicts( $this->query_vars );
[359] Fix | Delete
[360] Fix | Delete
foreach ( (array) $this->private_query_vars as $var ) {
[361] Fix | Delete
if ( isset( $this->extra_query_vars[ $var ] ) ) {
[362] Fix | Delete
$this->query_vars[ $var ] = $this->extra_query_vars[ $var ];
[363] Fix | Delete
}
[364] Fix | Delete
}
[365] Fix | Delete
[366] Fix | Delete
if ( isset( $error ) ) {
[367] Fix | Delete
$this->query_vars['error'] = $error;
[368] Fix | Delete
}
[369] Fix | Delete
[370] Fix | Delete
/**
[371] Fix | Delete
* Filters the array of parsed query variables.
[372] Fix | Delete
*
[373] Fix | Delete
* @since 2.1.0
[374] Fix | Delete
*
[375] Fix | Delete
* @param array $query_vars The array of requested query variables.
[376] Fix | Delete
*/
[377] Fix | Delete
$this->query_vars = apply_filters( 'request', $this->query_vars );
[378] Fix | Delete
[379] Fix | Delete
/**
[380] Fix | Delete
* Fires once all query variables for the current request have been parsed.
[381] Fix | Delete
*
[382] Fix | Delete
* @since 2.1.0
[383] Fix | Delete
*
[384] Fix | Delete
* @param WP $this Current WordPress environment instance (passed by reference).
[385] Fix | Delete
*/
[386] Fix | Delete
do_action_ref_array( 'parse_request', array( &$this ) );
[387] Fix | Delete
}
[388] Fix | Delete
[389] Fix | Delete
/**
[390] Fix | Delete
* Sends additional HTTP headers for caching, content type, etc.
[391] Fix | Delete
*
[392] Fix | Delete
* Sets the Content-Type header. Sets the 'error' status (if passed) and optionally exits.
[393] Fix | Delete
* If showing a feed, it will also send Last-Modified, ETag, and 304 status if needed.
[394] Fix | Delete
*
[395] Fix | Delete
* @since 2.0.0
[396] Fix | Delete
* @since 4.4.0 `X-Pingback` header is added conditionally after posts have been queried in handle_404().
[397] Fix | Delete
*/
[398] Fix | Delete
public function send_headers() {
[399] Fix | Delete
$headers = array();
[400] Fix | Delete
$status = null;
[401] Fix | Delete
$exit_required = false;
[402] Fix | Delete
[403] Fix | Delete
if ( is_user_logged_in() ) {
[404] Fix | Delete
$headers = array_merge( $headers, wp_get_nocache_headers() );
[405] Fix | Delete
} elseif ( ! empty( $_GET['unapproved'] ) && ! empty( $_GET['moderation-hash'] ) ) {
[406] Fix | Delete
// Unmoderated comments are only visible for 10 minutes via the moderation hash.
[407] Fix | Delete
$expires = 10 * MINUTE_IN_SECONDS;
[408] Fix | Delete
[409] Fix | Delete
$headers['Expires'] = gmdate( 'D, d M Y H:i:s', time() + $expires );
[410] Fix | Delete
$headers['Cache-Control'] = sprintf(
[411] Fix | Delete
'max-age=%d, must-revalidate',
[412] Fix | Delete
$expires
[413] Fix | Delete
);
[414] Fix | Delete
}
[415] Fix | Delete
if ( ! empty( $this->query_vars['error'] ) ) {
[416] Fix | Delete
$status = (int) $this->query_vars['error'];
[417] Fix | Delete
if ( 404 === $status ) {
[418] Fix | Delete
if ( ! is_user_logged_in() ) {
[419] Fix | Delete
$headers = array_merge( $headers, wp_get_nocache_headers() );
[420] Fix | Delete
}
[421] Fix | Delete
$headers['Content-Type'] = get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' );
[422] Fix | Delete
} elseif ( in_array( $status, array( 403, 500, 502, 503 ), true ) ) {
[423] Fix | Delete
$exit_required = true;
[424] Fix | Delete
}
[425] Fix | Delete
} elseif ( empty( $this->query_vars['feed'] ) ) {
[426] Fix | Delete
$headers['Content-Type'] = get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' );
[427] Fix | Delete
} else {
[428] Fix | Delete
// Set the correct content type for feeds.
[429] Fix | Delete
$type = $this->query_vars['feed'];
[430] Fix | Delete
if ( 'feed' === $this->query_vars['feed'] ) {
[431] Fix | Delete
$type = get_default_feed();
[432] Fix | Delete
}
[433] Fix | Delete
$headers['Content-Type'] = feed_content_type( $type ) . '; charset=' . get_option( 'blog_charset' );
[434] Fix | Delete
[435] Fix | Delete
// We're showing a feed, so WP is indeed the only thing that last changed.
[436] Fix | Delete
if ( ! empty( $this->query_vars['withcomments'] )
[437] Fix | Delete
|| false !== strpos( $this->query_vars['feed'], 'comments-' )
[438] Fix | Delete
|| ( empty( $this->query_vars['withoutcomments'] )
[439] Fix | Delete
&& ( ! empty( $this->query_vars['p'] )
[440] Fix | Delete
|| ! empty( $this->query_vars['name'] )
[441] Fix | Delete
|| ! empty( $this->query_vars['page_id'] )
[442] Fix | Delete
|| ! empty( $this->query_vars['pagename'] )
[443] Fix | Delete
|| ! empty( $this->query_vars['attachment'] )
[444] Fix | Delete
|| ! empty( $this->query_vars['attachment_id'] )
[445] Fix | Delete
)
[446] Fix | Delete
)
[447] Fix | Delete
) {
[448] Fix | Delete
$wp_last_modified = mysql2date( 'D, d M Y H:i:s', get_lastcommentmodified( 'GMT' ), false );
[449] Fix | Delete
} else {
[450] Fix | Delete
$wp_last_modified = mysql2date( 'D, d M Y H:i:s', get_lastpostmodified( 'GMT' ), false );
[451] Fix | Delete
}
[452] Fix | Delete
[453] Fix | Delete
if ( ! $wp_last_modified ) {
[454] Fix | Delete
$wp_last_modified = gmdate( 'D, d M Y H:i:s' );
[455] Fix | Delete
}
[456] Fix | Delete
[457] Fix | Delete
$wp_last_modified .= ' GMT';
[458] Fix | Delete
[459] Fix | Delete
$wp_etag = '"' . md5( $wp_last_modified ) . '"';
[460] Fix | Delete
$headers['Last-Modified'] = $wp_last_modified;
[461] Fix | Delete
$headers['ETag'] = $wp_etag;
[462] Fix | Delete
[463] Fix | Delete
// Support for conditional GET.
[464] Fix | Delete
if ( isset( $_SERVER['HTTP_IF_NONE_MATCH'] ) ) {
[465] Fix | Delete
$client_etag = wp_unslash( $_SERVER['HTTP_IF_NONE_MATCH'] );
[466] Fix | Delete
} else {
[467] Fix | Delete
$client_etag = false;
[468] Fix | Delete
}
[469] Fix | Delete
[470] Fix | Delete
$client_last_modified = empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ? '' : trim( $_SERVER['HTTP_IF_MODIFIED_SINCE'] );
[471] Fix | Delete
// If string is empty, return 0. If not, attempt to parse into a timestamp.
[472] Fix | Delete
$client_modified_timestamp = $client_last_modified ? strtotime( $client_last_modified ) : 0;
[473] Fix | Delete
[474] Fix | Delete
// Make a timestamp for our most recent modification..
[475] Fix | Delete
$wp_modified_timestamp = strtotime( $wp_last_modified );
[476] Fix | Delete
[477] Fix | Delete
if ( ( $client_last_modified && $client_etag ) ?
[478] Fix | Delete
( ( $client_modified_timestamp >= $wp_modified_timestamp ) && ( $client_etag == $wp_etag ) ) :
[479] Fix | Delete
( ( $client_modified_timestamp >= $wp_modified_timestamp ) || ( $client_etag == $wp_etag ) ) ) {
[480] Fix | Delete
$status = 304;
[481] Fix | Delete
$exit_required = true;
[482] Fix | Delete
}
[483] Fix | Delete
}
[484] Fix | Delete
[485] Fix | Delete
/**
[486] Fix | Delete
* Filters the HTTP headers before they're sent to the browser.
[487] Fix | Delete
*
[488] Fix | Delete
* @since 2.8.0
[489] Fix | Delete
*
[490] Fix | Delete
* @param string[] $headers Associative array of headers to be sent.
[491] Fix | Delete
* @param WP $wp Current WordPress environment instance.
[492] Fix | Delete
*/
[493] Fix | Delete
$headers = apply_filters( 'wp_headers', $headers, $this );
[494] Fix | Delete
[495] Fix | Delete
if ( ! empty( $status ) ) {
[496] Fix | Delete
status_header( $status );
[497] Fix | Delete
}
[498] Fix | Delete
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function