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