author | ymh <ymh.work@gmail.com> |
Tue, 15 Dec 2020 13:49:49 +0100 | |
changeset 16 | a86126ab1dd4 |
parent 13 | d255fe9cd479 |
child 18 | be944660c56a |
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 |
*/ |
16 | 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', 'pagename', 'page_id', 'error', 'attachment', 'attachment_id', 'subpost', 'subpost_id', 'preview', 'robots', 'favicon', '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 ) { |
16 | 93 |
if ( ! in_array( $qv, $this->public_query_vars, true ) ) { |
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 |
* |
|
16 | 114 |
* @param string $key Query variable name. |
115 |
* @param mixed $value Query variable value. |
|
0 | 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 |
* |
|
16 | 129 |
* @global WP_Rewrite $wp_rewrite WordPress rewrite component. |
7
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 |
|
16 | 176 |
/* |
177 |
* Trim path info from the end and the leading home path from the front. |
|
178 |
* For path info requests, this leaves us with the requesting filename, if any. |
|
179 |
* For 404 requests, this leaves us with the requested permalink. |
|
180 |
*/ |
|
9 | 181 |
$req_uri = str_replace( $pathinfo, '', $req_uri ); |
182 |
$req_uri = trim( $req_uri, '/' ); |
|
183 |
$req_uri = preg_replace( $home_path_regex, '', $req_uri ); |
|
184 |
$req_uri = trim( $req_uri, '/' ); |
|
185 |
$pathinfo = trim( $pathinfo, '/' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
186 |
$pathinfo = preg_replace( $home_path_regex, '', $pathinfo ); |
9 | 187 |
$pathinfo = trim( $pathinfo, '/' ); |
188 |
$self = trim( $self, '/' ); |
|
189 |
$self = preg_replace( $home_path_regex, '', $self ); |
|
190 |
$self = trim( $self, '/' ); |
|
0 | 191 |
|
192 |
// The requested permalink is in $pathinfo for path info requests and |
|
16 | 193 |
// $req_uri for other requests. |
9 | 194 |
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
|
195 |
$requested_path = $pathinfo; |
0 | 196 |
} else { |
197 |
// If the request uri is the index, blank it out so that we don't try to match it against a rule. |
|
9 | 198 |
if ( $req_uri == $wp_rewrite->index ) { |
0 | 199 |
$req_uri = ''; |
9 | 200 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
201 |
$requested_path = $req_uri; |
0 | 202 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
203 |
$requested_file = $req_uri; |
0 | 204 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
205 |
$this->request = $requested_path; |
0 | 206 |
|
207 |
// Look for matches. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
208 |
$request_match = $requested_path; |
0 | 209 |
if ( empty( $request_match ) ) { |
16 | 210 |
// An empty request could only match against ^$ regex. |
0 | 211 |
if ( isset( $rewrite['$'] ) ) { |
212 |
$this->matched_rule = '$'; |
|
9 | 213 |
$query = $rewrite['$']; |
214 |
$matches = array( '' ); |
|
0 | 215 |
} |
216 |
} else { |
|
217 |
foreach ( (array) $rewrite as $match => $query ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
218 |
// If the requested file is the anchor of the match, prepend it to the path info. |
9 | 219 |
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
|
220 |
$request_match = $requested_file . '/' . $requested_path; |
9 | 221 |
} |
0 | 222 |
|
9 | 223 |
if ( preg_match( "#^$match#", $request_match, $matches ) || |
224 |
preg_match( "#^$match#", urldecode( $request_match ), $matches ) ) { |
|
0 | 225 |
|
226 |
if ( $wp_rewrite->use_verbose_page_rules && preg_match( '/pagename=\$matches\[([0-9]+)\]/', $query, $varmatch ) ) { |
|
5 | 227 |
// 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
|
228 |
$page = get_page_by_path( $matches[ $varmatch[1] ] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
229 |
if ( ! $page ) { |
9 | 230 |
continue; |
7
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 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
233 |
$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
|
234 |
if ( ! $post_status_obj->public && ! $post_status_obj->protected |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
235 |
&& ! $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
|
236 |
continue; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
237 |
} |
0 | 238 |
} |
239 |
||
240 |
// Got a match. |
|
241 |
$this->matched_rule = $match; |
|
242 |
break; |
|
243 |
} |
|
244 |
} |
|
245 |
} |
|
246 |
||
247 |
if ( isset( $this->matched_rule ) ) { |
|
248 |
// Trim the query of everything up to the '?'. |
|
9 | 249 |
$query = preg_replace( '!^.+\?!', '', $query ); |
0 | 250 |
|
251 |
// Substitute the substring matches into the query. |
|
9 | 252 |
$query = addslashes( WP_MatchesMapRegex::apply( $query, $matches ) ); |
0 | 253 |
|
254 |
$this->matched_query = $query; |
|
255 |
||
256 |
// Parse the query. |
|
9 | 257 |
parse_str( $query, $perma_query_vars ); |
0 | 258 |
|
259 |
// If we're processing a 404 request, clear the error var since we found something. |
|
9 | 260 |
if ( '404' == $error ) { |
0 | 261 |
unset( $error, $_GET['error'] ); |
9 | 262 |
} |
0 | 263 |
} |
264 |
||
265 |
// If req_uri is empty or if it is a request for ourself, unset error. |
|
9 | 266 |
if ( empty( $requested_path ) || $requested_file == $self || strpos( $_SERVER['PHP_SELF'], 'wp-admin/' ) !== false ) { |
0 | 267 |
unset( $error, $_GET['error'] ); |
268 |
||
9 | 269 |
if ( isset( $perma_query_vars ) && strpos( $_SERVER['PHP_SELF'], 'wp-admin/' ) !== false ) { |
0 | 270 |
unset( $perma_query_vars ); |
9 | 271 |
} |
0 | 272 |
|
273 |
$this->did_permalink = false; |
|
274 |
} |
|
275 |
} |
|
276 |
||
5 | 277 |
/** |
16 | 278 |
* Filters the query variables allowed before processing. |
5 | 279 |
* |
280 |
* Allows (publicly allowed) query vars to be added, removed, or changed prior |
|
281 |
* to executing the query. Needed to allow custom rewrite rules using your own arguments |
|
282 |
* to work, or any other custom query variables you want to be publicly available. |
|
283 |
* |
|
284 |
* @since 1.5.0 |
|
285 |
* |
|
16 | 286 |
* @param string[] $public_query_vars The array of allowed query variable names. |
5 | 287 |
*/ |
288 |
$this->public_query_vars = apply_filters( 'query_vars', $this->public_query_vars ); |
|
0 | 289 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
290 |
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
|
291 |
if ( is_post_type_viewable( $t ) && $t->query_var ) { |
9 | 292 |
$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
|
293 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
294 |
} |
0 | 295 |
|
296 |
foreach ( $this->public_query_vars as $wpvar ) { |
|
9 | 297 |
if ( isset( $this->extra_query_vars[ $wpvar ] ) ) { |
298 |
$this->query_vars[ $wpvar ] = $this->extra_query_vars[ $wpvar ]; |
|
299 |
} elseif ( isset( $_GET[ $wpvar ] ) && isset( $_POST[ $wpvar ] ) && $_GET[ $wpvar ] !== $_POST[ $wpvar ] ) { |
|
300 |
wp_die( __( 'A variable mismatch has been detected.' ), __( 'Sorry, you are not allowed to view this item.' ), 400 ); |
|
301 |
} elseif ( isset( $_POST[ $wpvar ] ) ) { |
|
302 |
$this->query_vars[ $wpvar ] = $_POST[ $wpvar ]; |
|
303 |
} elseif ( isset( $_GET[ $wpvar ] ) ) { |
|
304 |
$this->query_vars[ $wpvar ] = $_GET[ $wpvar ]; |
|
305 |
} elseif ( isset( $perma_query_vars[ $wpvar ] ) ) { |
|
306 |
$this->query_vars[ $wpvar ] = $perma_query_vars[ $wpvar ]; |
|
307 |
} |
|
0 | 308 |
|
9 | 309 |
if ( ! empty( $this->query_vars[ $wpvar ] ) ) { |
310 |
if ( ! is_array( $this->query_vars[ $wpvar ] ) ) { |
|
311 |
$this->query_vars[ $wpvar ] = (string) $this->query_vars[ $wpvar ]; |
|
0 | 312 |
} else { |
9 | 313 |
foreach ( $this->query_vars[ $wpvar ] as $vkey => $v ) { |
314 |
if ( is_scalar( $v ) ) { |
|
315 |
$this->query_vars[ $wpvar ][ $vkey ] = (string) $v; |
|
0 | 316 |
} |
317 |
} |
|
318 |
} |
|
319 |
||
9 | 320 |
if ( isset( $post_type_query_vars[ $wpvar ] ) ) { |
321 |
$this->query_vars['post_type'] = $post_type_query_vars[ $wpvar ]; |
|
322 |
$this->query_vars['name'] = $this->query_vars[ $wpvar ]; |
|
0 | 323 |
} |
324 |
} |
|
325 |
} |
|
326 |
||
16 | 327 |
// Convert urldecoded spaces back into '+'. |
9 | 328 |
foreach ( get_taxonomies( array(), 'objects' ) as $taxonomy => $t ) { |
329 |
if ( $t->query_var && isset( $this->query_vars[ $t->query_var ] ) ) { |
|
330 |
$this->query_vars[ $t->query_var ] = str_replace( ' ', '+', $this->query_vars[ $t->query_var ] ); |
|
331 |
} |
|
332 |
} |
|
0 | 333 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
334 |
// 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
|
335 |
if ( ! is_admin() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
336 |
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
|
337 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
338 |
* Disallow when set to the 'taxonomy' query var. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
339 |
* 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
|
340 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
341 |
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
|
342 |
unset( $this->query_vars['taxonomy'], $this->query_vars['term'] ); |
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 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
346 |
|
16 | 347 |
// Limit publicly queried post_types to those that are 'publicly_queryable'. |
9 | 348 |
if ( isset( $this->query_vars['post_type'] ) ) { |
349 |
$queryable_post_types = get_post_types( array( 'publicly_queryable' => true ) ); |
|
0 | 350 |
if ( ! is_array( $this->query_vars['post_type'] ) ) { |
16 | 351 |
if ( ! in_array( $this->query_vars['post_type'], $queryable_post_types, true ) ) { |
0 | 352 |
unset( $this->query_vars['post_type'] ); |
9 | 353 |
} |
0 | 354 |
} else { |
355 |
$this->query_vars['post_type'] = array_intersect( $this->query_vars['post_type'], $queryable_post_types ); |
|
356 |
} |
|
357 |
} |
|
358 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
359 |
// 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
|
360 |
$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
|
361 |
|
9 | 362 |
foreach ( (array) $this->private_query_vars as $var ) { |
363 |
if ( isset( $this->extra_query_vars[ $var ] ) ) { |
|
364 |
$this->query_vars[ $var ] = $this->extra_query_vars[ $var ]; |
|
365 |
} |
|
0 | 366 |
} |
367 |
||
9 | 368 |
if ( isset( $error ) ) { |
0 | 369 |
$this->query_vars['error'] = $error; |
9 | 370 |
} |
0 | 371 |
|
5 | 372 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
373 |
* Filters the array of parsed query variables. |
5 | 374 |
* |
375 |
* @since 2.1.0 |
|
376 |
* |
|
377 |
* @param array $query_vars The array of requested query variables. |
|
378 |
*/ |
|
379 |
$this->query_vars = apply_filters( 'request', $this->query_vars ); |
|
0 | 380 |
|
5 | 381 |
/** |
382 |
* Fires once all query variables for the current request have been parsed. |
|
383 |
* |
|
384 |
* @since 2.1.0 |
|
385 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
386 |
* @param WP $this Current WordPress environment instance (passed by reference). |
5 | 387 |
*/ |
388 |
do_action_ref_array( 'parse_request', array( &$this ) ); |
|
0 | 389 |
} |
390 |
||
391 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
392 |
* Sends additional HTTP headers for caching, content type, etc. |
0 | 393 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
394 |
* 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
|
395 |
* If showing a feed, it will also send Last-Modified, ETag, and 304 status if needed. |
0 | 396 |
* |
397 |
* @since 2.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
398 |
* @since 4.4.0 `X-Pingback` header is added conditionally after posts have been queried in handle_404(). |
0 | 399 |
*/ |
5 | 400 |
public function send_headers() { |
9 | 401 |
$headers = array(); |
402 |
$status = null; |
|
0 | 403 |
$exit_required = false; |
404 |
||
9 | 405 |
if ( is_user_logged_in() ) { |
406 |
$headers = array_merge( $headers, wp_get_nocache_headers() ); |
|
16 | 407 |
} elseif ( ! empty( $_GET['unapproved'] ) && ! empty( $_GET['moderation-hash'] ) ) { |
408 |
// Unmoderated comments are only visible for one minute via the moderation hash. |
|
409 |
$headers['Expires'] = gmdate( 'D, d M Y H:i:s', time() + MINUTE_IN_SECONDS ); |
|
410 |
$headers['Cache-Control'] = 'max-age=60, must-revalidate'; |
|
9 | 411 |
} |
0 | 412 |
if ( ! empty( $this->query_vars['error'] ) ) { |
413 |
$status = (int) $this->query_vars['error']; |
|
414 |
if ( 404 === $status ) { |
|
9 | 415 |
if ( ! is_user_logged_in() ) { |
416 |
$headers = array_merge( $headers, wp_get_nocache_headers() ); |
|
417 |
} |
|
418 |
$headers['Content-Type'] = get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ); |
|
16 | 419 |
} elseif ( in_array( $status, array( 403, 500, 502, 503 ), true ) ) { |
0 | 420 |
$exit_required = true; |
421 |
} |
|
5 | 422 |
} elseif ( empty( $this->query_vars['feed'] ) ) { |
9 | 423 |
$headers['Content-Type'] = get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ); |
0 | 424 |
} else { |
16 | 425 |
// Set the correct content type for feeds. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
426 |
$type = $this->query_vars['feed']; |
16 | 427 |
if ( 'feed' === $this->query_vars['feed'] ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
428 |
$type = get_default_feed(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
429 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
430 |
$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
|
431 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
432 |
// 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
|
433 |
if ( ! empty( $this->query_vars['withcomments'] ) |
9 | 434 |
|| false !== strpos( $this->query_vars['feed'], 'comments-' ) |
435 |
|| ( empty( $this->query_vars['withoutcomments'] ) |
|
436 |
&& ( ! empty( $this->query_vars['p'] ) |
|
437 |
|| ! empty( $this->query_vars['name'] ) |
|
438 |
|| ! empty( $this->query_vars['page_id'] ) |
|
439 |
|| ! empty( $this->query_vars['pagename'] ) |
|
440 |
|| ! empty( $this->query_vars['attachment'] ) |
|
441 |
|| ! empty( $this->query_vars['attachment_id'] ) |
|
442 |
) |
|
443 |
) |
|
7
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 |
$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
|
446 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
447 |
$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
|
448 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
449 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
450 |
if ( ! $wp_last_modified ) { |
16 | 451 |
$wp_last_modified = gmdate( 'D, d M Y H:i:s' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
452 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
453 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
454 |
$wp_last_modified .= ' GMT'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
455 |
|
9 | 456 |
$wp_etag = '"' . md5( $wp_last_modified ) . '"'; |
0 | 457 |
$headers['Last-Modified'] = $wp_last_modified; |
9 | 458 |
$headers['ETag'] = $wp_etag; |
0 | 459 |
|
16 | 460 |
// Support for conditional GET. |
9 | 461 |
if ( isset( $_SERVER['HTTP_IF_NONE_MATCH'] ) ) { |
0 | 462 |
$client_etag = wp_unslash( $_SERVER['HTTP_IF_NONE_MATCH'] ); |
9 | 463 |
} else { |
464 |
$client_etag = false; |
|
465 |
} |
|
0 | 466 |
|
9 | 467 |
$client_last_modified = empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ? '' : trim( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ); |
16 | 468 |
// If string is empty, return 0. If not, attempt to parse into a timestamp. |
9 | 469 |
$client_modified_timestamp = $client_last_modified ? strtotime( $client_last_modified ) : 0; |
0 | 470 |
|
16 | 471 |
// Make a timestamp for our most recent modification.. |
9 | 472 |
$wp_modified_timestamp = strtotime( $wp_last_modified ); |
0 | 473 |
|
9 | 474 |
if ( ( $client_last_modified && $client_etag ) ? |
475 |
( ( $client_modified_timestamp >= $wp_modified_timestamp ) && ( $client_etag == $wp_etag ) ) : |
|
476 |
( ( $client_modified_timestamp >= $wp_modified_timestamp ) || ( $client_etag == $wp_etag ) ) ) { |
|
477 |
$status = 304; |
|
0 | 478 |
$exit_required = true; |
479 |
} |
|
480 |
} |
|
481 |
||
5 | 482 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
483 |
* Filters the HTTP headers before they're sent to the browser. |
5 | 484 |
* |
485 |
* @since 2.8.0 |
|
486 |
* |
|
9 | 487 |
* @param string[] $headers Associative array of headers to be sent. |
488 |
* @param WP $this Current WordPress environment instance. |
|
5 | 489 |
*/ |
490 |
$headers = apply_filters( 'wp_headers', $headers, $this ); |
|
0 | 491 |
|
9 | 492 |
if ( ! empty( $status ) ) { |
0 | 493 |
status_header( $status ); |
9 | 494 |
} |
0 | 495 |
|
496 |
// If Last-Modified is set to false, it should not be sent (no-cache situation). |
|
497 |
if ( isset( $headers['Last-Modified'] ) && false === $headers['Last-Modified'] ) { |
|
498 |
unset( $headers['Last-Modified'] ); |
|
499 |
||
16 | 500 |
if ( ! headers_sent() ) { |
501 |
header_remove( 'Last-Modified' ); |
|
0 | 502 |
} |
503 |
} |
|
504 |
||
16 | 505 |
if ( ! headers_sent() ) { |
506 |
foreach ( (array) $headers as $name => $field_value ) { |
|
507 |
header( "{$name}: {$field_value}" ); |
|
508 |
} |
|
9 | 509 |
} |
0 | 510 |
|
9 | 511 |
if ( $exit_required ) { |
16 | 512 |
exit; |
9 | 513 |
} |
0 | 514 |
|
5 | 515 |
/** |
516 |
* Fires once the requested HTTP headers for caching, content type, etc. have been sent. |
|
517 |
* |
|
518 |
* @since 2.1.0 |
|
519 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
520 |
* @param WP $this Current WordPress environment instance (passed by reference). |
5 | 521 |
*/ |
522 |
do_action_ref_array( 'send_headers', array( &$this ) ); |
|
0 | 523 |
} |
524 |
||
525 |
/** |
|
526 |
* Sets the query string property based off of the query variable property. |
|
527 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
528 |
* 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
|
529 |
* use the {@see 'request'} filter instead. |
0 | 530 |
* |
531 |
* @since 2.0.0 |
|
532 |
*/ |
|
5 | 533 |
public function build_query_string() { |
0 | 534 |
$this->query_string = ''; |
9 | 535 |
foreach ( (array) array_keys( $this->query_vars ) as $wpvar ) { |
536 |
if ( '' != $this->query_vars[ $wpvar ] ) { |
|
537 |
$this->query_string .= ( strlen( $this->query_string ) < 1 ) ? '' : '&'; |
|
538 |
if ( ! is_scalar( $this->query_vars[ $wpvar ] ) ) { // Discard non-scalars. |
|
0 | 539 |
continue; |
9 | 540 |
} |
541 |
$this->query_string .= $wpvar . '=' . rawurlencode( $this->query_vars[ $wpvar ] ); |
|
0 | 542 |
} |
543 |
} |
|
544 |
||
5 | 545 |
if ( has_filter( 'query_string' ) ) { // Don't bother filtering and parsing if no plugins are hooked in. |
546 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
547 |
* Filters the query string before parsing. |
5 | 548 |
* |
549 |
* @since 1.5.0 |
|
16 | 550 |
* @deprecated 2.1.0 Use {@see 'query_vars'} or {@see 'request'} filters instead. |
5 | 551 |
* |
552 |
* @param string $query_string The query string to modify. |
|
553 |
*/ |
|
16 | 554 |
$this->query_string = apply_filters_deprecated( |
555 |
'query_string', |
|
556 |
array( $this->query_string ), |
|
557 |
'2.1.0', |
|
558 |
'query_vars, request' |
|
559 |
); |
|
9 | 560 |
parse_str( $this->query_string, $this->query_vars ); |
0 | 561 |
} |
562 |
} |
|
563 |
||
564 |
/** |
|
565 |
* Set up the WordPress Globals. |
|
566 |
* |
|
567 |
* The query_vars property will be extracted to the GLOBALS. So care should |
|
568 |
* be taken when naming global variables that might interfere with the |
|
569 |
* WordPress environment. |
|
570 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
571 |
* @since 2.0.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
572 |
* |
16 | 573 |
* @global WP_Query $wp_query WordPress Query object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
574 |
* @global string $query_string Query string for the loop. |
16 | 575 |
* @global array $posts The found posts. |
576 |
* @global WP_Post|null $post The current post, if available. |
|
577 |
* @global string $request The SQL statement for the request. |
|
578 |
* @global int $more Only set, if single page or post. |
|
579 |
* @global int $single If single page or post. Only set, if single page or post. |
|
580 |
* @global WP_User $authordata Only set, if author archive. |
|
0 | 581 |
*/ |
5 | 582 |
public function register_globals() { |
0 | 583 |
global $wp_query; |
584 |
||
585 |
// Extract updated query vars back into global namespace. |
|
586 |
foreach ( (array) $wp_query->query_vars as $key => $value ) { |
|
587 |
$GLOBALS[ $key ] = $value; |
|
588 |
} |
|
589 |
||
590 |
$GLOBALS['query_string'] = $this->query_string; |
|
9 | 591 |
$GLOBALS['posts'] = & $wp_query->posts; |
592 |
$GLOBALS['post'] = isset( $wp_query->post ) ? $wp_query->post : null; |
|
593 |
$GLOBALS['request'] = $wp_query->request; |
|
0 | 594 |
|
595 |
if ( $wp_query->is_single() || $wp_query->is_page() ) { |
|
596 |
$GLOBALS['more'] = 1; |
|
597 |
$GLOBALS['single'] = 1; |
|
598 |
} |
|
599 |
||
9 | 600 |
if ( $wp_query->is_author() && isset( $wp_query->post ) ) { |
0 | 601 |
$GLOBALS['authordata'] = get_userdata( $wp_query->post->post_author ); |
9 | 602 |
} |
0 | 603 |
} |
604 |
||
605 |
/** |
|
606 |
* Set up the current user. |
|
607 |
* |
|
608 |
* @since 2.0.0 |
|
609 |
*/ |
|
5 | 610 |
public function init() { |
0 | 611 |
wp_get_current_user(); |
612 |
} |
|
613 |
||
614 |
/** |
|
615 |
* Set up the Loop based on the query variables. |
|
616 |
* |
|
617 |
* @since 2.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
618 |
* |
16 | 619 |
* @global WP_Query $wp_the_query WordPress Query object. |
0 | 620 |
*/ |
5 | 621 |
public function query_posts() { |
0 | 622 |
global $wp_the_query; |
623 |
$this->build_query_string(); |
|
9 | 624 |
$wp_the_query->query( $this->query_vars ); |
625 |
} |
|
0 | 626 |
|
9 | 627 |
/** |
5 | 628 |
* Set the Headers for 404, if nothing is found for requested URL. |
0 | 629 |
* |
16 | 630 |
* Issue a 404 if a request doesn't match any posts and doesn't match any object |
631 |
* (e.g. an existing-but-empty category, tag, author) and a 404 was not already issued, |
|
632 |
* and if the request was not a search or the homepage. |
|
0 | 633 |
* |
634 |
* Otherwise, issue a 200. |
|
635 |
* |
|
16 | 636 |
* This sets headers after posts have been queried. handle_404() really means "handle status". |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
637 |
* 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
|
638 |
* 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
|
639 |
* |
0 | 640 |
* @since 2.0.0 |
9 | 641 |
* |
16 | 642 |
* @global WP_Query $wp_query WordPress Query object. |
9 | 643 |
*/ |
5 | 644 |
public function handle_404() { |
0 | 645 |
global $wp_query; |
646 |
||
7
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 |
* Filters whether to short-circuit default header status handling. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
649 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
650 |
* 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
|
651 |
* and return early. |
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 |
* @since 4.5.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
654 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
655 |
* @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
|
656 |
* @param WP_Query $wp_query WordPress Query object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
657 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
658 |
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
|
659 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
660 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
661 |
|
0 | 662 |
// If we've already issued a 404, bail. |
9 | 663 |
if ( is_404() ) { |
0 | 664 |
return; |
9 | 665 |
} |
0 | 666 |
|
16 | 667 |
$set_404 = true; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
668 |
|
16 | 669 |
// Never 404 for the admin, robots, or favicon. |
670 |
if ( is_admin() || is_robots() || is_favicon() ) { |
|
671 |
$set_404 = false; |
|
672 |
||
673 |
// If posts were found, check for paged content. |
|
674 |
} elseif ( $wp_query->posts ) { |
|
675 |
$content_found = true; |
|
676 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
677 |
if ( is_singular() ) { |
16 | 678 |
$post = isset( $wp_query->post ) ? $wp_query->post : null; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
679 |
|
16 | 680 |
// Only set X-Pingback for single posts that allow pings. |
681 |
if ( $post && pings_open( $post ) && ! headers_sent() ) { |
|
682 |
header( 'X-Pingback: ' . get_bloginfo( 'pingback_url', 'display' ) ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
683 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
684 |
|
16 | 685 |
// Check for paged content that exceeds the max number of pages. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
686 |
$next = '<!--nextpage-->'; |
16 | 687 |
if ( $post && ! empty( $this->query_vars['page'] ) ) { |
688 |
// Check if content is actually intended to be paged. |
|
689 |
if ( false !== strpos( $post->post_content, $next ) ) { |
|
690 |
$page = trim( $this->query_vars['page'], '/' ); |
|
691 |
$content_found = (int) $page <= ( substr_count( $post->post_content, $next ) + 1 ); |
|
692 |
} else { |
|
693 |
$content_found = false; |
|
694 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
695 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
696 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
697 |
|
16 | 698 |
// The posts page does not support the <!--nextpage--> pagination. |
699 |
if ( $wp_query->is_posts_page && ! empty( $this->query_vars['page'] ) ) { |
|
700 |
$content_found = false; |
|
701 |
} |
|
702 |
||
703 |
if ( $content_found ) { |
|
704 |
$set_404 = false; |
|
705 |
} |
|
706 |
||
707 |
// We will 404 for paged queries, as no posts were found. |
|
708 |
} elseif ( ! is_paged() ) { |
|
709 |
$author = get_query_var( 'author' ); |
|
710 |
||
711 |
// Don't 404 for authors without posts as long as they matched an author on this site. |
|
712 |
if ( is_author() && is_numeric( $author ) && $author > 0 && is_user_member_of_blog( $author ) |
|
713 |
// Don't 404 for these queries if they matched an object. |
|
714 |
|| ( is_tag() || is_category() || is_tax() || is_post_type_archive() ) && get_queried_object() |
|
715 |
// Don't 404 for these queries either. |
|
716 |
|| is_home() || is_search() || is_feed() |
|
717 |
) { |
|
718 |
$set_404 = false; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
719 |
} |
0 | 720 |
} |
721 |
||
16 | 722 |
if ( $set_404 ) { |
723 |
// Guess it's time to 404. |
|
724 |
$wp_query->set_404(); |
|
725 |
status_header( 404 ); |
|
726 |
nocache_headers(); |
|
727 |
} else { |
|
728 |
status_header( 200 ); |
|
0 | 729 |
} |
730 |
} |
|
731 |
||
732 |
/** |
|
733 |
* Sets up all of the variables required by the WordPress environment. |
|
734 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
735 |
* The action {@see 'wp'} has one parameter that references the WP object. It |
0 | 736 |
* allows for accessing the properties and methods to further manipulate the |
737 |
* object. |
|
738 |
* |
|
739 |
* @since 2.0.0 |
|
740 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
741 |
* @param string|array $query_args Passed to parse_request(). |
0 | 742 |
*/ |
9 | 743 |
public function main( $query_args = '' ) { |
0 | 744 |
$this->init(); |
9 | 745 |
$this->parse_request( $query_args ); |
0 | 746 |
$this->send_headers(); |
747 |
$this->query_posts(); |
|
748 |
$this->handle_404(); |
|
749 |
$this->register_globals(); |
|
5 | 750 |
|
751 |
/** |
|
752 |
* Fires once the WordPress environment has been set up. |
|
753 |
* |
|
754 |
* @since 2.1.0 |
|
755 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
756 |
* @param WP $this Current WordPress environment instance (passed by reference). |
5 | 757 |
*/ |
758 |
do_action_ref_array( 'wp', array( &$this ) ); |
|
0 | 759 |
} |
760 |
} |