author | ymh <ymh.work@gmail.com> |
Mon, 14 Oct 2019 18:28:13 +0200 | |
changeset 9 | 177826044cd9 |
parent 7 | cf61fcea0001 |
child 13 | d255fe9cd479 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
3 |
* WordPress environment setup class. |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
* @since 2.0.0 |
|
7 |
*/ |
|
8 |
class WP { |
|
9 |
/** |
|
10 |
* Public query variables. |
|
11 |
* |
|
12 |
* Long list of public query variables. |
|
13 |
* |
|
14 |
* @since 2.0.0 |
|
9 | 15 |
* @var string[] |
0 | 16 |
*/ |
9 | 17 |
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', 'static', 'pagename', 'page_id', 'error', 'attachment', 'attachment_id', 'subpost', 'subpost_id', 'preview', 'robots', 'taxonomy', 'term', 'cpage', 'post_type', 'embed' ); |
0 | 18 |
|
19 |
/** |
|
20 |
* Private query variables. |
|
21 |
* |
|
22 |
* Long list of private query variables. |
|
23 |
* |
|
24 |
* @since 2.0.0 |
|
9 | 25 |
* @var string[] |
0 | 26 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
27 |
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' ); |
0 | 28 |
|
29 |
/** |
|
30 |
* Extra query variables set by the user. |
|
31 |
* |
|
32 |
* @since 2.1.0 |
|
33 |
* @var array |
|
34 |
*/ |
|
5 | 35 |
public $extra_query_vars = array(); |
0 | 36 |
|
37 |
/** |
|
38 |
* Query variables for setting up the WordPress Query Loop. |
|
39 |
* |
|
40 |
* @since 2.0.0 |
|
41 |
* @var array |
|
42 |
*/ |
|
5 | 43 |
public $query_vars; |
0 | 44 |
|
45 |
/** |
|
46 |
* String parsed to set the query variables. |
|
47 |
* |
|
48 |
* @since 2.0.0 |
|
49 |
* @var string |
|
50 |
*/ |
|
5 | 51 |
public $query_string; |
0 | 52 |
|
53 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
54 |
* The request path, e.g. 2015/05/06. |
0 | 55 |
* |
56 |
* @since 2.0.0 |
|
57 |
* @var string |
|
58 |
*/ |
|
5 | 59 |
public $request; |
0 | 60 |
|
61 |
/** |
|
62 |
* Rewrite rule the request matched. |
|
63 |
* |
|
64 |
* @since 2.0.0 |
|
65 |
* @var string |
|
66 |
*/ |
|
5 | 67 |
public $matched_rule; |
0 | 68 |
|
69 |
/** |
|
70 |
* Rewrite query the request matched. |
|
71 |
* |
|
72 |
* @since 2.0.0 |
|
73 |
* @var string |
|
74 |
*/ |
|
5 | 75 |
public $matched_query; |
0 | 76 |
|
77 |
/** |
|
78 |
* Whether already did the permalink. |
|
79 |
* |
|
80 |
* @since 2.0.0 |
|
81 |
* @var bool |
|
82 |
*/ |
|
5 | 83 |
public $did_permalink = false; |
0 | 84 |
|
85 |
/** |
|
86 |
* Add name to list of public query variables. |
|
87 |
* |
|
88 |
* @since 2.1.0 |
|
89 |
* |
|
90 |
* @param string $qv Query variable name. |
|
91 |
*/ |
|
9 | 92 |
public function add_query_var( $qv ) { |
93 |
if ( ! in_array( $qv, $this->public_query_vars ) ) { |
|
0 | 94 |
$this->public_query_vars[] = $qv; |
9 | 95 |
} |
0 | 96 |
} |
97 |
||
98 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
99 |
* Removes a query variable from a list of public query variables. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
100 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
101 |
* @since 4.5.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
102 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
103 |
* @param string $name Query variable name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
104 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
105 |
public function remove_query_var( $name ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
106 |
$this->public_query_vars = array_diff( $this->public_query_vars, array( $name ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
107 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
108 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
109 |
/** |
0 | 110 |
* Set the value of a query variable. |
111 |
* |
|
112 |
* @since 2.3.0 |
|
113 |
* |
|
114 |
* @param string $key Query variable name. |
|
115 |
* @param mixed $value Query variable value. |
|
116 |
*/ |
|
9 | 117 |
public function set_query_var( $key, $value ) { |
118 |
$this->query_vars[ $key ] = $value; |
|
0 | 119 |
} |
120 |
||
121 |
/** |
|
122 |
* Parse request to find correct WordPress query. |
|
123 |
* |
|
124 |
* Sets up the query variables based on the request. There are also many |
|
125 |
* filters and actions that can be used to further manipulate the result. |
|
126 |
* |
|
127 |
* @since 2.0.0 |
|
128 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
129 |
* @global WP_Rewrite $wp_rewrite |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
130 |
* |
0 | 131 |
* @param array|string $extra_query_vars Set the extra query variables. |
132 |
*/ |
|
9 | 133 |
public function parse_request( $extra_query_vars = '' ) { |
0 | 134 |
global $wp_rewrite; |
135 |
||
5 | 136 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
137 |
* Filters whether to parse the request. |
5 | 138 |
* |
139 |
* @since 3.5.0 |
|
140 |
* |
|
141 |
* @param bool $bool Whether or not to parse the request. Default true. |
|
142 |
* @param WP $this Current WordPress environment instance. |
|
143 |
* @param array|string $extra_query_vars Extra passed query variables. |
|
144 |
*/ |
|
9 | 145 |
if ( ! apply_filters( 'do_parse_request', true, $this, $extra_query_vars ) ) { |
0 | 146 |
return; |
9 | 147 |
} |
0 | 148 |
|
9 | 149 |
$this->query_vars = array(); |
0 | 150 |
$post_type_query_vars = array(); |
151 |
||
5 | 152 |
if ( is_array( $extra_query_vars ) ) { |
0 | 153 |
$this->extra_query_vars = & $extra_query_vars; |
5 | 154 |
} elseif ( ! empty( $extra_query_vars ) ) { |
155 |
parse_str( $extra_query_vars, $this->extra_query_vars ); |
|
156 |
} |
|
0 | 157 |
// Process PATH_INFO, REQUEST_URI, and 404 for permalinks. |
158 |
||
159 |
// Fetch the rewrite rules. |
|
160 |
$rewrite = $wp_rewrite->wp_rewrite_rules(); |
|
161 |
||
9 | 162 |
if ( ! empty( $rewrite ) ) { |
0 | 163 |
// If we match a rewrite rule, this will be cleared. |
9 | 164 |
$error = '404'; |
0 | 165 |
$this->did_permalink = true; |
166 |
||
9 | 167 |
$pathinfo = isset( $_SERVER['PATH_INFO'] ) ? $_SERVER['PATH_INFO'] : ''; |
0 | 168 |
list( $pathinfo ) = explode( '?', $pathinfo ); |
9 | 169 |
$pathinfo = str_replace( '%', '%25', $pathinfo ); |
0 | 170 |
|
171 |
list( $req_uri ) = explode( '?', $_SERVER['REQUEST_URI'] ); |
|
9 | 172 |
$self = $_SERVER['PHP_SELF']; |
173 |
$home_path = trim( parse_url( home_url(), PHP_URL_PATH ), '/' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
174 |
$home_path_regex = sprintf( '|^%s|i', preg_quote( $home_path, '|' ) ); |
0 | 175 |
|
176 |
// Trim path info from the end and the leading home path from the |
|
177 |
// front. For path info requests, this leaves us with the requesting |
|
178 |
// filename, if any. For 404 requests, this leaves us with the |
|
179 |
// requested permalink. |
|
9 | 180 |
$req_uri = str_replace( $pathinfo, '', $req_uri ); |
181 |
$req_uri = trim( $req_uri, '/' ); |
|
182 |
$req_uri = preg_replace( $home_path_regex, '', $req_uri ); |
|
183 |
$req_uri = trim( $req_uri, '/' ); |
|
184 |
$pathinfo = trim( $pathinfo, '/' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
185 |
$pathinfo = preg_replace( $home_path_regex, '', $pathinfo ); |
9 | 186 |
$pathinfo = trim( $pathinfo, '/' ); |
187 |
$self = trim( $self, '/' ); |
|
188 |
$self = preg_replace( $home_path_regex, '', $self ); |
|
189 |
$self = trim( $self, '/' ); |
|
0 | 190 |
|
191 |
// The requested permalink is in $pathinfo for path info requests and |
|
192 |
// $req_uri for other requests. |
|
9 | 193 |
if ( ! empty( $pathinfo ) && ! preg_match( '|^.*' . $wp_rewrite->index . '$|', $pathinfo ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
194 |
$requested_path = $pathinfo; |
0 | 195 |
} else { |
196 |
// If the request uri is the index, blank it out so that we don't try to match it against a rule. |
|
9 | 197 |
if ( $req_uri == $wp_rewrite->index ) { |
0 | 198 |
$req_uri = ''; |
9 | 199 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
200 |
$requested_path = $req_uri; |
0 | 201 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
202 |
$requested_file = $req_uri; |
0 | 203 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
204 |
$this->request = $requested_path; |
0 | 205 |
|
206 |
// Look for matches. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
207 |
$request_match = $requested_path; |
0 | 208 |
if ( empty( $request_match ) ) { |
209 |
// An empty request could only match against ^$ regex |
|
210 |
if ( isset( $rewrite['$'] ) ) { |
|
211 |
$this->matched_rule = '$'; |
|
9 | 212 |
$query = $rewrite['$']; |
213 |
$matches = array( '' ); |
|
0 | 214 |
} |
215 |
} else { |
|
216 |
foreach ( (array) $rewrite as $match => $query ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
217 |
// If the requested file is the anchor of the match, prepend it to the path info. |
9 | 218 |
if ( ! empty( $requested_file ) && strpos( $match, $requested_file ) === 0 && $requested_file != $requested_path ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
219 |
$request_match = $requested_file . '/' . $requested_path; |
9 | 220 |
} |
0 | 221 |
|
9 | 222 |
if ( preg_match( "#^$match#", $request_match, $matches ) || |
223 |
preg_match( "#^$match#", urldecode( $request_match ), $matches ) ) { |
|
0 | 224 |
|
225 |
if ( $wp_rewrite->use_verbose_page_rules && preg_match( '/pagename=\$matches\[([0-9]+)\]/', $query, $varmatch ) ) { |
|
5 | 226 |
// This is a verbose page match, let's check to be sure about it. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
227 |
$page = get_page_by_path( $matches[ $varmatch[1] ] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
228 |
if ( ! $page ) { |
9 | 229 |
continue; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
230 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
231 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
232 |
$post_status_obj = get_post_status_object( $page->post_status ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
233 |
if ( ! $post_status_obj->public && ! $post_status_obj->protected |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
234 |
&& ! $post_status_obj->private && $post_status_obj->exclude_from_search ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
235 |
continue; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
236 |
} |
0 | 237 |
} |
238 |
||
239 |
// Got a match. |
|
240 |
$this->matched_rule = $match; |
|
241 |
break; |
|
242 |
} |
|
243 |
} |
|
244 |
} |
|
245 |
||
246 |
if ( isset( $this->matched_rule ) ) { |
|
247 |
// Trim the query of everything up to the '?'. |
|
9 | 248 |
$query = preg_replace( '!^.+\?!', '', $query ); |
0 | 249 |
|
250 |
// Substitute the substring matches into the query. |
|
9 | 251 |
$query = addslashes( WP_MatchesMapRegex::apply( $query, $matches ) ); |
0 | 252 |
|
253 |
$this->matched_query = $query; |
|
254 |
||
255 |
// Parse the query. |
|
9 | 256 |
parse_str( $query, $perma_query_vars ); |
0 | 257 |
|
258 |
// If we're processing a 404 request, clear the error var since we found something. |
|
9 | 259 |
if ( '404' == $error ) { |
0 | 260 |
unset( $error, $_GET['error'] ); |
9 | 261 |
} |
0 | 262 |
} |
263 |
||
264 |
// If req_uri is empty or if it is a request for ourself, unset error. |
|
9 | 265 |
if ( empty( $requested_path ) || $requested_file == $self || strpos( $_SERVER['PHP_SELF'], 'wp-admin/' ) !== false ) { |
0 | 266 |
unset( $error, $_GET['error'] ); |
267 |
||
9 | 268 |
if ( isset( $perma_query_vars ) && strpos( $_SERVER['PHP_SELF'], 'wp-admin/' ) !== false ) { |
0 | 269 |
unset( $perma_query_vars ); |
9 | 270 |
} |
0 | 271 |
|
272 |
$this->did_permalink = false; |
|
273 |
} |
|
274 |
} |
|
275 |
||
5 | 276 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
277 |
* Filters the query variables whitelist before processing. |
5 | 278 |
* |
279 |
* Allows (publicly allowed) query vars to be added, removed, or changed prior |
|
280 |
* to executing the query. Needed to allow custom rewrite rules using your own arguments |
|
281 |
* to work, or any other custom query variables you want to be publicly available. |
|
282 |
* |
|
283 |
* @since 1.5.0 |
|
284 |
* |
|
9 | 285 |
* @param string[] $public_query_vars The array of whitelisted query variable names. |
5 | 286 |
*/ |
287 |
$this->public_query_vars = apply_filters( 'query_vars', $this->public_query_vars ); |
|
0 | 288 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
289 |
foreach ( get_post_types( array(), 'objects' ) as $post_type => $t ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
290 |
if ( is_post_type_viewable( $t ) && $t->query_var ) { |
9 | 291 |
$post_type_query_vars[ $t->query_var ] = $post_type; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
292 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
293 |
} |
0 | 294 |
|
295 |
foreach ( $this->public_query_vars as $wpvar ) { |
|
9 | 296 |
if ( isset( $this->extra_query_vars[ $wpvar ] ) ) { |
297 |
$this->query_vars[ $wpvar ] = $this->extra_query_vars[ $wpvar ]; |
|
298 |
} elseif ( isset( $_GET[ $wpvar ] ) && isset( $_POST[ $wpvar ] ) && $_GET[ $wpvar ] !== $_POST[ $wpvar ] ) { |
|
299 |
wp_die( __( 'A variable mismatch has been detected.' ), __( 'Sorry, you are not allowed to view this item.' ), 400 ); |
|
300 |
} elseif ( isset( $_POST[ $wpvar ] ) ) { |
|
301 |
$this->query_vars[ $wpvar ] = $_POST[ $wpvar ]; |
|
302 |
} elseif ( isset( $_GET[ $wpvar ] ) ) { |
|
303 |
$this->query_vars[ $wpvar ] = $_GET[ $wpvar ]; |
|
304 |
} elseif ( isset( $perma_query_vars[ $wpvar ] ) ) { |
|
305 |
$this->query_vars[ $wpvar ] = $perma_query_vars[ $wpvar ]; |
|
306 |
} |
|
0 | 307 |
|
9 | 308 |
if ( ! empty( $this->query_vars[ $wpvar ] ) ) { |
309 |
if ( ! is_array( $this->query_vars[ $wpvar ] ) ) { |
|
310 |
$this->query_vars[ $wpvar ] = (string) $this->query_vars[ $wpvar ]; |
|
0 | 311 |
} else { |
9 | 312 |
foreach ( $this->query_vars[ $wpvar ] as $vkey => $v ) { |
313 |
if ( is_scalar( $v ) ) { |
|
314 |
$this->query_vars[ $wpvar ][ $vkey ] = (string) $v; |
|
0 | 315 |
} |
316 |
} |
|
317 |
} |
|
318 |
||
9 | 319 |
if ( isset( $post_type_query_vars[ $wpvar ] ) ) { |
320 |
$this->query_vars['post_type'] = $post_type_query_vars[ $wpvar ]; |
|
321 |
$this->query_vars['name'] = $this->query_vars[ $wpvar ]; |
|
0 | 322 |
} |
323 |
} |
|
324 |
} |
|
325 |
||
326 |
// Convert urldecoded spaces back into + |
|
9 | 327 |
foreach ( get_taxonomies( array(), 'objects' ) as $taxonomy => $t ) { |
328 |
if ( $t->query_var && isset( $this->query_vars[ $t->query_var ] ) ) { |
|
329 |
$this->query_vars[ $t->query_var ] = str_replace( ' ', '+', $this->query_vars[ $t->query_var ] ); |
|
330 |
} |
|
331 |
} |
|
0 | 332 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
333 |
// Don't allow non-publicly queryable taxonomies to be queried from the front end. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
334 |
if ( ! is_admin() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
335 |
foreach ( get_taxonomies( array( 'publicly_queryable' => false ), 'objects' ) as $taxonomy => $t ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
336 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
337 |
* Disallow when set to the 'taxonomy' query var. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
338 |
* Non-publicly queryable taxonomies cannot register custom query vars. See register_taxonomy(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
339 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
340 |
if ( isset( $this->query_vars['taxonomy'] ) && $taxonomy === $this->query_vars['taxonomy'] ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
341 |
unset( $this->query_vars['taxonomy'], $this->query_vars['term'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
342 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
343 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
344 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
345 |
|
0 | 346 |
// Limit publicly queried post_types to those that are publicly_queryable |
9 | 347 |
if ( isset( $this->query_vars['post_type'] ) ) { |
348 |
$queryable_post_types = get_post_types( array( 'publicly_queryable' => true ) ); |
|
0 | 349 |
if ( ! is_array( $this->query_vars['post_type'] ) ) { |
9 | 350 |
if ( ! in_array( $this->query_vars['post_type'], $queryable_post_types ) ) { |
0 | 351 |
unset( $this->query_vars['post_type'] ); |
9 | 352 |
} |
0 | 353 |
} else { |
354 |
$this->query_vars['post_type'] = array_intersect( $this->query_vars['post_type'], $queryable_post_types ); |
|
355 |
} |
|
356 |
} |
|
357 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
358 |
// Resolve conflicts between posts with numeric slugs and date archive queries. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
359 |
$this->query_vars = wp_resolve_numeric_slug_conflicts( $this->query_vars ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
360 |
|
9 | 361 |
foreach ( (array) $this->private_query_vars as $var ) { |
362 |
if ( isset( $this->extra_query_vars[ $var ] ) ) { |
|
363 |
$this->query_vars[ $var ] = $this->extra_query_vars[ $var ]; |
|
364 |
} |
|
0 | 365 |
} |
366 |
||
9 | 367 |
if ( isset( $error ) ) { |
0 | 368 |
$this->query_vars['error'] = $error; |
9 | 369 |
} |
0 | 370 |
|
5 | 371 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
372 |
* Filters the array of parsed query variables. |
5 | 373 |
* |
374 |
* @since 2.1.0 |
|
375 |
* |
|
376 |
* @param array $query_vars The array of requested query variables. |
|
377 |
*/ |
|
378 |
$this->query_vars = apply_filters( 'request', $this->query_vars ); |
|
0 | 379 |
|
5 | 380 |
/** |
381 |
* Fires once all query variables for the current request have been parsed. |
|
382 |
* |
|
383 |
* @since 2.1.0 |
|
384 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
385 |
* @param WP $this Current WordPress environment instance (passed by reference). |
5 | 386 |
*/ |
387 |
do_action_ref_array( 'parse_request', array( &$this ) ); |
|
0 | 388 |
} |
389 |
||
390 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
391 |
* Sends additional HTTP headers for caching, content type, etc. |
0 | 392 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
393 |
* Sets the Content-Type header. Sets the 'error' status (if passed) and optionally exits. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
394 |
* If showing a feed, it will also send Last-Modified, ETag, and 304 status if needed. |
0 | 395 |
* |
396 |
* @since 2.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
397 |
* @since 4.4.0 `X-Pingback` header is added conditionally after posts have been queried in handle_404(). |
0 | 398 |
*/ |
5 | 399 |
public function send_headers() { |
9 | 400 |
$headers = array(); |
401 |
$status = null; |
|
0 | 402 |
$exit_required = false; |
403 |
||
9 | 404 |
if ( is_user_logged_in() ) { |
405 |
$headers = array_merge( $headers, wp_get_nocache_headers() ); |
|
406 |
} |
|
0 | 407 |
if ( ! empty( $this->query_vars['error'] ) ) { |
408 |
$status = (int) $this->query_vars['error']; |
|
409 |
if ( 404 === $status ) { |
|
9 | 410 |
if ( ! is_user_logged_in() ) { |
411 |
$headers = array_merge( $headers, wp_get_nocache_headers() ); |
|
412 |
} |
|
413 |
$headers['Content-Type'] = get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ); |
|
0 | 414 |
} elseif ( in_array( $status, array( 403, 500, 502, 503 ) ) ) { |
415 |
$exit_required = true; |
|
416 |
} |
|
5 | 417 |
} elseif ( empty( $this->query_vars['feed'] ) ) { |
9 | 418 |
$headers['Content-Type'] = get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ); |
0 | 419 |
} else { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
420 |
// Set the correct content type for feeds |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
421 |
$type = $this->query_vars['feed']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
422 |
if ( 'feed' == $this->query_vars['feed'] ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
423 |
$type = get_default_feed(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
424 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
425 |
$headers['Content-Type'] = feed_content_type( $type ) . '; charset=' . get_option( 'blog_charset' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
426 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
427 |
// We're showing a feed, so WP is indeed the only thing that last changed. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
428 |
if ( ! empty( $this->query_vars['withcomments'] ) |
9 | 429 |
|| false !== strpos( $this->query_vars['feed'], 'comments-' ) |
430 |
|| ( empty( $this->query_vars['withoutcomments'] ) |
|
431 |
&& ( ! empty( $this->query_vars['p'] ) |
|
432 |
|| ! empty( $this->query_vars['name'] ) |
|
433 |
|| ! empty( $this->query_vars['page_id'] ) |
|
434 |
|| ! empty( $this->query_vars['pagename'] ) |
|
435 |
|| ! empty( $this->query_vars['attachment'] ) |
|
436 |
|| ! empty( $this->query_vars['attachment_id'] ) |
|
437 |
) |
|
438 |
) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
439 |
) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
440 |
$wp_last_modified = mysql2date( 'D, d M Y H:i:s', get_lastcommentmodified( 'GMT' ), false ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
441 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
442 |
$wp_last_modified = mysql2date( 'D, d M Y H:i:s', get_lastpostmodified( 'GMT' ), false ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
443 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
444 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
445 |
if ( ! $wp_last_modified ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
446 |
$wp_last_modified = date( 'D, d M Y H:i:s' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
447 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
448 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
449 |
$wp_last_modified .= ' GMT'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
450 |
|
9 | 451 |
$wp_etag = '"' . md5( $wp_last_modified ) . '"'; |
0 | 452 |
$headers['Last-Modified'] = $wp_last_modified; |
9 | 453 |
$headers['ETag'] = $wp_etag; |
0 | 454 |
|
455 |
// Support for Conditional GET |
|
9 | 456 |
if ( isset( $_SERVER['HTTP_IF_NONE_MATCH'] ) ) { |
0 | 457 |
$client_etag = wp_unslash( $_SERVER['HTTP_IF_NONE_MATCH'] ); |
9 | 458 |
} else { |
459 |
$client_etag = false; |
|
460 |
} |
|
0 | 461 |
|
9 | 462 |
$client_last_modified = empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ? '' : trim( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ); |
0 | 463 |
// If string is empty, return 0. If not, attempt to parse into a timestamp |
9 | 464 |
$client_modified_timestamp = $client_last_modified ? strtotime( $client_last_modified ) : 0; |
0 | 465 |
|
466 |
// Make a timestamp for our most recent modification... |
|
9 | 467 |
$wp_modified_timestamp = strtotime( $wp_last_modified ); |
0 | 468 |
|
9 | 469 |
if ( ( $client_last_modified && $client_etag ) ? |
470 |
( ( $client_modified_timestamp >= $wp_modified_timestamp ) && ( $client_etag == $wp_etag ) ) : |
|
471 |
( ( $client_modified_timestamp >= $wp_modified_timestamp ) || ( $client_etag == $wp_etag ) ) ) { |
|
472 |
$status = 304; |
|
0 | 473 |
$exit_required = true; |
474 |
} |
|
475 |
} |
|
476 |
||
5 | 477 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
478 |
* Filters the HTTP headers before they're sent to the browser. |
5 | 479 |
* |
480 |
* @since 2.8.0 |
|
481 |
* |
|
9 | 482 |
* @param string[] $headers Associative array of headers to be sent. |
483 |
* @param WP $this Current WordPress environment instance. |
|
5 | 484 |
*/ |
485 |
$headers = apply_filters( 'wp_headers', $headers, $this ); |
|
0 | 486 |
|
9 | 487 |
if ( ! empty( $status ) ) { |
0 | 488 |
status_header( $status ); |
9 | 489 |
} |
0 | 490 |
|
491 |
// If Last-Modified is set to false, it should not be sent (no-cache situation). |
|
492 |
if ( isset( $headers['Last-Modified'] ) && false === $headers['Last-Modified'] ) { |
|
493 |
unset( $headers['Last-Modified'] ); |
|
494 |
||
495 |
// In PHP 5.3+, make sure we are not sending a Last-Modified header. |
|
496 |
if ( function_exists( 'header_remove' ) ) { |
|
497 |
@header_remove( 'Last-Modified' ); |
|
498 |
} else { |
|
499 |
// In PHP 5.2, send an empty Last-Modified header, but only as a |
|
500 |
// last resort to override a header already sent. #WP23021 |
|
501 |
foreach ( headers_list() as $header ) { |
|
502 |
if ( 0 === stripos( $header, 'Last-Modified' ) ) { |
|
503 |
$headers['Last-Modified'] = ''; |
|
504 |
break; |
|
505 |
} |
|
506 |
} |
|
507 |
} |
|
508 |
} |
|
509 |
||
9 | 510 |
foreach ( (array) $headers as $name => $field_value ) { |
511 |
@header( "{$name}: {$field_value}" ); |
|
512 |
} |
|
0 | 513 |
|
9 | 514 |
if ( $exit_required ) { |
0 | 515 |
exit(); |
9 | 516 |
} |
0 | 517 |
|
5 | 518 |
/** |
519 |
* Fires once the requested HTTP headers for caching, content type, etc. have been sent. |
|
520 |
* |
|
521 |
* @since 2.1.0 |
|
522 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
523 |
* @param WP $this Current WordPress environment instance (passed by reference). |
5 | 524 |
*/ |
525 |
do_action_ref_array( 'send_headers', array( &$this ) ); |
|
0 | 526 |
} |
527 |
||
528 |
/** |
|
529 |
* Sets the query string property based off of the query variable property. |
|
530 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
531 |
* The {@see 'query_string'} filter is deprecated, but still works. Plugins should |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
532 |
* use the {@see 'request'} filter instead. |
0 | 533 |
* |
534 |
* @since 2.0.0 |
|
535 |
*/ |
|
5 | 536 |
public function build_query_string() { |
0 | 537 |
$this->query_string = ''; |
9 | 538 |
foreach ( (array) array_keys( $this->query_vars ) as $wpvar ) { |
539 |
if ( '' != $this->query_vars[ $wpvar ] ) { |
|
540 |
$this->query_string .= ( strlen( $this->query_string ) < 1 ) ? '' : '&'; |
|
541 |
if ( ! is_scalar( $this->query_vars[ $wpvar ] ) ) { // Discard non-scalars. |
|
0 | 542 |
continue; |
9 | 543 |
} |
544 |
$this->query_string .= $wpvar . '=' . rawurlencode( $this->query_vars[ $wpvar ] ); |
|
0 | 545 |
} |
546 |
} |
|
547 |
||
5 | 548 |
if ( has_filter( 'query_string' ) ) { // Don't bother filtering and parsing if no plugins are hooked in. |
549 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
550 |
* Filters the query string before parsing. |
5 | 551 |
* |
552 |
* @since 1.5.0 |
|
553 |
* @deprecated 2.1.0 Use 'query_vars' or 'request' filters instead. |
|
554 |
* |
|
555 |
* @param string $query_string The query string to modify. |
|
556 |
*/ |
|
557 |
$this->query_string = apply_filters( 'query_string', $this->query_string ); |
|
9 | 558 |
parse_str( $this->query_string, $this->query_vars ); |
0 | 559 |
} |
560 |
} |
|
561 |
||
562 |
/** |
|
563 |
* Set up the WordPress Globals. |
|
564 |
* |
|
565 |
* The query_vars property will be extracted to the GLOBALS. So care should |
|
566 |
* be taken when naming global variables that might interfere with the |
|
567 |
* WordPress environment. |
|
568 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
569 |
* @since 2.0.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
570 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
571 |
* @global WP_Query $wp_query |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
572 |
* @global string $query_string Query string for the loop. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
573 |
* @global array $posts The found posts. |
0 | 574 |
* @global WP_Post|null $post The current post, if available. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
575 |
* @global string $request The SQL statement for the request. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
576 |
* @global int $more Only set, if single page or post. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
577 |
* @global int $single If single page or post. Only set, if single page or post. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
578 |
* @global WP_User $authordata Only set, if author archive. |
0 | 579 |
*/ |
5 | 580 |
public function register_globals() { |
0 | 581 |
global $wp_query; |
582 |
||
583 |
// Extract updated query vars back into global namespace. |
|
584 |
foreach ( (array) $wp_query->query_vars as $key => $value ) { |
|
585 |
$GLOBALS[ $key ] = $value; |
|
586 |
} |
|
587 |
||
588 |
$GLOBALS['query_string'] = $this->query_string; |
|
9 | 589 |
$GLOBALS['posts'] = & $wp_query->posts; |
590 |
$GLOBALS['post'] = isset( $wp_query->post ) ? $wp_query->post : null; |
|
591 |
$GLOBALS['request'] = $wp_query->request; |
|
0 | 592 |
|
593 |
if ( $wp_query->is_single() || $wp_query->is_page() ) { |
|
594 |
$GLOBALS['more'] = 1; |
|
595 |
$GLOBALS['single'] = 1; |
|
596 |
} |
|
597 |
||
9 | 598 |
if ( $wp_query->is_author() && isset( $wp_query->post ) ) { |
0 | 599 |
$GLOBALS['authordata'] = get_userdata( $wp_query->post->post_author ); |
9 | 600 |
} |
0 | 601 |
} |
602 |
||
603 |
/** |
|
604 |
* Set up the current user. |
|
605 |
* |
|
606 |
* @since 2.0.0 |
|
607 |
*/ |
|
5 | 608 |
public function init() { |
0 | 609 |
wp_get_current_user(); |
610 |
} |
|
611 |
||
612 |
/** |
|
613 |
* Set up the Loop based on the query variables. |
|
614 |
* |
|
615 |
* @since 2.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
616 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
617 |
* @global WP_Query $wp_the_query |
0 | 618 |
*/ |
5 | 619 |
public function query_posts() { |
0 | 620 |
global $wp_the_query; |
621 |
$this->build_query_string(); |
|
9 | 622 |
$wp_the_query->query( $this->query_vars ); |
623 |
} |
|
0 | 624 |
|
9 | 625 |
/** |
5 | 626 |
* Set the Headers for 404, if nothing is found for requested URL. |
0 | 627 |
* |
628 |
* Issue a 404 if a request doesn't match any posts and doesn't match |
|
629 |
* any object (e.g. an existing-but-empty category, tag, author) and a 404 was not already |
|
630 |
* issued, and if the request was not a search or the homepage. |
|
631 |
* |
|
632 |
* Otherwise, issue a 200. |
|
633 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
634 |
* This sets headers after posts have been queried. handle_404() really means "handle status." |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
635 |
* By inspecting the result of querying posts, seemingly successful requests can be switched to |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
636 |
* a 404 so that canonical redirection logic can kick in. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
637 |
* |
0 | 638 |
* @since 2.0.0 |
9 | 639 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
640 |
* @global WP_Query $wp_query |
9 | 641 |
*/ |
5 | 642 |
public function handle_404() { |
0 | 643 |
global $wp_query; |
644 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
645 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
646 |
* Filters whether to short-circuit default header status handling. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
647 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
648 |
* Returning a non-false value from the filter will short-circuit the handling |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
649 |
* and return early. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
650 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
651 |
* @since 4.5.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
652 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
653 |
* @param bool $preempt Whether to short-circuit default header status handling. Default false. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
654 |
* @param WP_Query $wp_query WordPress Query object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
655 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
656 |
if ( false !== apply_filters( 'pre_handle_404', false, $wp_query ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
657 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
658 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
659 |
|
0 | 660 |
// If we've already issued a 404, bail. |
9 | 661 |
if ( is_404() ) { |
0 | 662 |
return; |
9 | 663 |
} |
0 | 664 |
|
665 |
// Never 404 for the admin, robots, or if we found posts. |
|
666 |
if ( is_admin() || is_robots() || $wp_query->posts ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
667 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
668 |
$success = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
669 |
if ( is_singular() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
670 |
$p = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
671 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
672 |
if ( $wp_query->post instanceof WP_Post ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
673 |
$p = clone $wp_query->post; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
674 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
675 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
676 |
// Only set X-Pingback for single posts that allow pings. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
677 |
if ( $p && pings_open( $p ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
678 |
@header( 'X-Pingback: ' . get_bloginfo( 'pingback_url', 'display' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
679 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
680 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
681 |
// check for paged content that exceeds the max number of pages |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
682 |
$next = '<!--nextpage-->'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
683 |
if ( $p && false !== strpos( $p->post_content, $next ) && ! empty( $this->query_vars['page'] ) ) { |
9 | 684 |
$page = trim( $this->query_vars['page'], '/' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
685 |
$success = (int) $page <= ( substr_count( $p->post_content, $next ) + 1 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
686 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
687 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
688 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
689 |
if ( $success ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
690 |
status_header( 200 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
691 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
692 |
} |
0 | 693 |
} |
694 |
||
695 |
// We will 404 for paged queries, as no posts were found. |
|
696 |
if ( ! is_paged() ) { |
|
697 |
||
5 | 698 |
// Don't 404 for authors without posts as long as they matched an author on this site. |
699 |
$author = get_query_var( 'author' ); |
|
700 |
if ( is_author() && is_numeric( $author ) && $author > 0 && is_user_member_of_blog( $author ) ) { |
|
701 |
status_header( 200 ); |
|
702 |
return; |
|
703 |
} |
|
704 |
||
0 | 705 |
// Don't 404 for these queries if they matched an object. |
5 | 706 |
if ( ( is_tag() || is_category() || is_tax() || is_post_type_archive() ) && get_queried_object() ) { |
0 | 707 |
status_header( 200 ); |
708 |
return; |
|
709 |
} |
|
710 |
||
711 |
// Don't 404 for these queries either. |
|
5 | 712 |
if ( is_home() || is_search() || is_feed() ) { |
0 | 713 |
status_header( 200 ); |
714 |
return; |
|
715 |
} |
|
716 |
} |
|
717 |
||
718 |
// Guess it's time to 404. |
|
719 |
$wp_query->set_404(); |
|
720 |
status_header( 404 ); |
|
721 |
nocache_headers(); |
|
722 |
} |
|
723 |
||
724 |
/** |
|
725 |
* Sets up all of the variables required by the WordPress environment. |
|
726 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
727 |
* The action {@see 'wp'} has one parameter that references the WP object. It |
0 | 728 |
* allows for accessing the properties and methods to further manipulate the |
729 |
* object. |
|
730 |
* |
|
731 |
* @since 2.0.0 |
|
732 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
733 |
* @param string|array $query_args Passed to parse_request(). |
0 | 734 |
*/ |
9 | 735 |
public function main( $query_args = '' ) { |
0 | 736 |
$this->init(); |
9 | 737 |
$this->parse_request( $query_args ); |
0 | 738 |
$this->send_headers(); |
739 |
$this->query_posts(); |
|
740 |
$this->handle_404(); |
|
741 |
$this->register_globals(); |
|
5 | 742 |
|
743 |
/** |
|
744 |
* Fires once the WordPress environment has been set up. |
|
745 |
* |
|
746 |
* @since 2.1.0 |
|
747 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
748 |
* @param WP $this Current WordPress environment instance (passed by reference). |
5 | 749 |
*/ |
750 |
do_action_ref_array( 'wp', array( &$this ) ); |
|
0 | 751 |
} |
752 |
} |