20 global $wp_rewrite; |
20 global $wp_rewrite; |
21 $wp_rewrite->add_rule($regex, $redirect, $after); |
21 $wp_rewrite->add_rule($regex, $redirect, $after); |
22 } |
22 } |
23 |
23 |
24 /** |
24 /** |
25 * Add a new tag (like %postname%). |
25 * Add a new rewrite tag (like %postname%). |
26 * |
26 * |
27 * Warning: you must call this on init or earlier, otherwise the query var |
27 * The $query parameter is optional. If it is omitted you must ensure that |
28 * addition stuff won't work. |
28 * you call this on, or before, the 'init' hook. This is because $query defaults |
29 * |
29 * to "$tag=", and for this to work a new query var has to be added. |
|
30 * |
|
31 * @see WP_Rewrite::add_rewrite_tag() |
30 * @since 2.1.0 |
32 * @since 2.1.0 |
31 * |
33 * |
32 * @param string $tagname |
34 * @param string $tag Name of the new rewrite tag. |
33 * @param string $regex |
35 * @param string $regex Regular expression to substitute the tag for in rewrite rules. |
34 */ |
36 * @param string $query String to append to the rewritten query. Must end in '='. Optional. |
35 function add_rewrite_tag($tagname, $regex) { |
37 */ |
36 //validation |
38 function add_rewrite_tag( $tag, $regex, $query = '' ) { |
37 if (strlen($tagname) < 3 || $tagname{0} != '%' || $tagname{strlen($tagname)-1} != '%') { |
39 // validate the tag's name |
|
40 if ( strlen( $tag ) < 3 || $tag[0] != '%' || $tag[ strlen($tag) - 1 ] != '%' ) |
38 return; |
41 return; |
39 } |
|
40 |
|
41 $qv = trim($tagname, '%'); |
|
42 |
42 |
43 global $wp_rewrite, $wp; |
43 global $wp_rewrite, $wp; |
44 $wp->add_query_var($qv); |
44 |
45 $wp_rewrite->add_rewrite_tag($tagname, $regex, $qv . '='); |
45 if ( empty( $query ) ) { |
|
46 $qv = trim( $tag, '%' ); |
|
47 $wp->add_query_var( $qv ); |
|
48 $query = $qv . '='; |
|
49 } |
|
50 |
|
51 $wp_rewrite->add_rewrite_tag( $tag, $regex, $query ); |
|
52 } |
|
53 |
|
54 /** |
|
55 * Add permalink structure. |
|
56 * |
|
57 * @see WP_Rewrite::add_permastruct() |
|
58 * @since 3.0.0 |
|
59 * |
|
60 * @param string $name Name for permalink structure. |
|
61 * @param string $struct Permalink structure. |
|
62 * @param array $args Optional configuration for building the rules from the permalink structure, |
|
63 * see {@link WP_Rewrite::add_permastruct()} for full details. |
|
64 */ |
|
65 function add_permastruct( $name, $struct, $args = array() ) { |
|
66 global $wp_rewrite; |
|
67 |
|
68 // backwards compatibility for the old parameters: $with_front and $ep_mask |
|
69 if ( ! is_array( $args ) ) |
|
70 $args = array( 'with_front' => $args ); |
|
71 if ( func_num_args() == 4 ) |
|
72 $args['ep_mask'] = func_get_arg( 3 ); |
|
73 |
|
74 return $wp_rewrite->add_permastruct( $name, $struct, $args ); |
46 } |
75 } |
47 |
76 |
48 /** |
77 /** |
49 * Add a new feed type like /atom1/. |
78 * Add a new feed type like /atom1/. |
50 * |
79 * |
54 * @param callback $function Callback to run on feed display. |
83 * @param callback $function Callback to run on feed display. |
55 * @return string Feed action name. |
84 * @return string Feed action name. |
56 */ |
85 */ |
57 function add_feed($feedname, $function) { |
86 function add_feed($feedname, $function) { |
58 global $wp_rewrite; |
87 global $wp_rewrite; |
59 if (!in_array($feedname, $wp_rewrite->feeds)) { //override the file if it is |
88 if ( ! in_array($feedname, $wp_rewrite->feeds) ) //override the file if it is |
60 $wp_rewrite->feeds[] = $feedname; |
89 $wp_rewrite->feeds[] = $feedname; |
61 } |
|
62 $hook = 'do_feed_' . $feedname; |
90 $hook = 'do_feed_' . $feedname; |
63 // Remove default function hook |
91 // Remove default function hook |
64 remove_action($hook, $hook, 10, 1); |
92 remove_action($hook, $hook, 10, 1); |
65 add_action($hook, $function, 10, 1); |
93 add_action($hook, $function, 10, 1); |
66 return $hook; |
94 return $hook; |
67 } |
95 } |
68 |
96 |
69 /** |
97 /** |
|
98 * Remove rewrite rules and then recreate rewrite rules. |
|
99 * |
|
100 * @see WP_Rewrite::flush_rules() |
|
101 * @since 3.0.0 |
|
102 * |
|
103 * @param bool $hard Whether to update .htaccess (hard flush) or just update |
|
104 * rewrite_rules transient (soft flush). Default is true (hard). |
|
105 */ |
|
106 function flush_rewrite_rules( $hard = true ) { |
|
107 global $wp_rewrite; |
|
108 $wp_rewrite->flush_rules( $hard ); |
|
109 } |
|
110 |
|
111 /** |
|
112 * Endpoint Mask for default, which is nothing. |
|
113 * |
|
114 * @since 2.1.0 |
|
115 */ |
|
116 define('EP_NONE', 0); |
|
117 |
|
118 /** |
70 * Endpoint Mask for Permalink. |
119 * Endpoint Mask for Permalink. |
71 * |
120 * |
72 * @since 2.1.0 |
121 * @since 2.1.0 |
73 */ |
122 */ |
74 define('EP_PERMALINK', 1); |
123 define('EP_PERMALINK', 1); |
155 * |
204 * |
156 * @since 2.1.0 |
205 * @since 2.1.0 |
157 */ |
206 */ |
158 define('EP_PAGES', 4096); |
207 define('EP_PAGES', 4096); |
159 |
208 |
160 //pseudo-places |
209 /** |
161 /** |
210 * Endpoint Mask for everything. |
162 * Endpoint Mask for default, which is nothing. |
|
163 * |
211 * |
164 * @since 2.1.0 |
212 * @since 2.1.0 |
165 */ |
213 */ |
166 define('EP_NONE', 0); |
214 define('EP_ALL', 8191); |
167 |
215 |
168 /** |
216 /** |
169 * Endpoint Mask for everything. |
217 * Add an endpoint, like /trackback/. |
|
218 * |
|
219 * Adding an endpoint creates extra rewrite rules for each of the matching |
|
220 * places specified by the provided bitmask. For example: |
|
221 * |
|
222 * <code> |
|
223 * add_rewrite_endpoint( 'json', EP_PERMALINK | EP_PAGES ); |
|
224 * </code> |
|
225 * |
|
226 * will add a new rewrite rule ending with "json(/(.*))?/?$" for every permastruct |
|
227 * that describes a permalink (post) or page. This is rewritten to "json=$match" |
|
228 * where $match is the part of the URL matched by the endpoint regex (e.g. "foo" in |
|
229 * "<permalink>/json/foo/"). |
|
230 * |
|
231 * A new query var with the same name as the endpoint will also be created. |
|
232 * |
|
233 * When specifying $places ensure that you are using the EP_* constants (or a |
|
234 * combination of them using the bitwise OR operator) as their values are not |
|
235 * guaranteed to remain static (especially EP_ALL). |
|
236 * |
|
237 * Be sure to flush the rewrite rules - flush_rewrite_rules() - when your plugin gets |
|
238 * activated and deactivated. |
170 * |
239 * |
171 * @since 2.1.0 |
240 * @since 2.1.0 |
172 */ |
241 * @see WP_Rewrite::add_endpoint() |
173 define('EP_ALL', 8191); |
242 * @global object $wp_rewrite |
174 |
243 * |
175 /** |
244 * @param string $name Name of the endpoint. |
176 * Add an endpoint, like /trackback/. |
245 * @param int $places Endpoint mask describing the places the endpoint should be added. |
177 * |
246 */ |
178 * The endpoints are added to the end of the request. So a request matching |
247 function add_rewrite_endpoint( $name, $places ) { |
179 * "/2008/10/14/my_post/myep/", the endpoint will be "/myep/". |
|
180 * |
|
181 * Be sure to flush the rewrite rules (wp_rewrite->flush()) when your plugin gets |
|
182 * activated (register_activation_hook()) and deactivated (register_deactivation_hook()) |
|
183 * |
|
184 * @since 2.1.0 |
|
185 * @see WP_Rewrite::add_endpoint() Parameters and more description. |
|
186 * @uses $wp_rewrite |
|
187 * |
|
188 * @param unknown_type $name |
|
189 * @param unknown_type $places |
|
190 */ |
|
191 function add_rewrite_endpoint($name, $places) { |
|
192 global $wp_rewrite; |
248 global $wp_rewrite; |
193 $wp_rewrite->add_endpoint($name, $places); |
249 $wp_rewrite->add_endpoint( $name, $places ); |
194 } |
250 } |
195 |
251 |
196 /** |
252 /** |
197 * Filter the URL base for taxonomies. |
253 * Filter the URL base for taxonomies. |
198 * |
254 * |
199 * To remove any manually prepended /index.php/. |
255 * To remove any manually prepended /index.php/. |
200 * |
256 * |
201 * @access private |
257 * @access private |
202 * @since 2.6.0 |
258 * @since 2.6.0 |
203 * @author Mark Jaquith |
|
204 * |
259 * |
205 * @param string $base The taxonomy base that we're going to filter |
260 * @param string $base The taxonomy base that we're going to filter |
206 * @return string |
261 * @return string |
207 */ |
262 */ |
208 function _wp_filter_taxonomy_base( $base ) { |
263 function _wp_filter_taxonomy_base( $base ) { |
229 $url = apply_filters('url_to_postid', $url); |
284 $url = apply_filters('url_to_postid', $url); |
230 |
285 |
231 // First, check to see if there is a 'p=N' or 'page_id=N' to match against |
286 // First, check to see if there is a 'p=N' or 'page_id=N' to match against |
232 if ( preg_match('#[?&](p|page_id|attachment_id)=(\d+)#', $url, $values) ) { |
287 if ( preg_match('#[?&](p|page_id|attachment_id)=(\d+)#', $url, $values) ) { |
233 $id = absint($values[2]); |
288 $id = absint($values[2]); |
234 if ($id) |
289 if ( $id ) |
235 return $id; |
290 return $id; |
236 } |
291 } |
237 |
292 |
238 // Check to see if we are using rewrite rules |
293 // Check to see if we are using rewrite rules |
239 $rewrite = $wp_rewrite->wp_rewrite_rules(); |
294 $rewrite = $wp_rewrite->wp_rewrite_rules(); |
240 |
295 |
241 // Not using rewrite rules, and 'p=N' and 'page_id=N' methods failed, so we're out of options |
296 // Not using rewrite rules, and 'p=N' and 'page_id=N' methods failed, so we're out of options |
242 if ( empty($rewrite) ) |
297 if ( empty($rewrite) ) |
243 return 0; |
298 return 0; |
244 |
299 |
245 // $url cleanup by Mark Jaquith |
|
246 // This fixes things like #anchors, ?query=strings, missing 'www.', |
|
247 // added 'www.', or added 'index.php/' that will mess up our WP_Query |
|
248 // and return a false negative |
|
249 |
|
250 // Get rid of the #anchor |
300 // Get rid of the #anchor |
251 $url_split = explode('#', $url); |
301 $url_split = explode('#', $url); |
252 $url = $url_split[0]; |
302 $url = $url_split[0]; |
253 |
303 |
254 // Get rid of URL ?query=string |
304 // Get rid of URL ?query=string |
255 $url_split = explode('?', $url); |
305 $url_split = explode('?', $url); |
256 $url = $url_split[0]; |
306 $url = $url_split[0]; |
257 |
307 |
258 // Add 'www.' if it is absent and should be there |
308 // Add 'www.' if it is absent and should be there |
259 if ( false !== strpos(get_option('home'), '://www.') && false === strpos($url, '://www.') ) |
309 if ( false !== strpos(home_url(), '://www.') && false === strpos($url, '://www.') ) |
260 $url = str_replace('://', '://www.', $url); |
310 $url = str_replace('://', '://www.', $url); |
261 |
311 |
262 // Strip 'www.' if it is present and shouldn't be |
312 // Strip 'www.' if it is present and shouldn't be |
263 if ( false === strpos(get_option('home'), '://www.') ) |
313 if ( false === strpos(home_url(), '://www.') ) |
264 $url = str_replace('://www.', '://', $url); |
314 $url = str_replace('://www.', '://', $url); |
265 |
315 |
266 // Strip 'index.php/' if we're not using path info permalinks |
316 // Strip 'index.php/' if we're not using path info permalinks |
267 if ( !$wp_rewrite->using_index_permalinks() ) |
317 if ( !$wp_rewrite->using_index_permalinks() ) |
268 $url = str_replace('index.php/', '', $url); |
318 $url = str_replace('index.php/', '', $url); |
269 |
319 |
270 if ( false !== strpos($url, get_option('home')) ) { |
320 if ( false !== strpos($url, home_url()) ) { |
271 // Chop off http://domain.com |
321 // Chop off http://domain.com |
272 $url = str_replace(get_option('home'), '', $url); |
322 $url = str_replace(home_url(), '', $url); |
273 } else { |
323 } else { |
274 // Chop off /path/to/blog |
324 // Chop off /path/to/blog |
275 $home_path = parse_url(get_option('home')); |
325 $home_path = parse_url(home_url()); |
276 $home_path = $home_path['path']; |
326 $home_path = isset( $home_path['path'] ) ? $home_path['path'] : '' ; |
277 $url = str_replace($home_path, '', $url); |
327 $url = str_replace($home_path, '', $url); |
278 } |
328 } |
279 |
329 |
280 // Trim leading and lagging slashes |
330 // Trim leading and lagging slashes |
281 $url = trim($url, '/'); |
331 $url = trim($url, '/'); |
282 |
332 |
283 $request = $url; |
333 $request = $url; |
284 |
334 |
285 // Done with cleanup |
|
286 |
|
287 // Look for matches. |
335 // Look for matches. |
288 $request_match = $request; |
336 $request_match = $request; |
289 foreach ($rewrite as $match => $query) { |
337 foreach ( (array)$rewrite as $match => $query) { |
|
338 |
290 // If the requesting file is the anchor of the match, prepend it |
339 // If the requesting file is the anchor of the match, prepend it |
291 // to the path info. |
340 // to the path info. |
292 if ( (! empty($url)) && (strpos($match, $url) === 0) && ($url != $request)) { |
341 if ( !empty($url) && ($url != $request) && (strpos($match, $url) === 0) ) |
293 $request_match = $url . '/' . $request; |
342 $request_match = $url . '/' . $request; |
294 } |
|
295 |
343 |
296 if ( preg_match("!^$match!", $request_match, $matches) ) { |
344 if ( preg_match("!^$match!", $request_match, $matches) ) { |
|
345 |
|
346 if ( $wp_rewrite->use_verbose_page_rules && preg_match( '/pagename=\$matches\[([0-9]+)\]/', $query, $varmatch ) ) { |
|
347 // this is a verbose page match, lets check to be sure about it |
|
348 if ( ! get_page_by_path( $matches[ $varmatch[1] ] ) ) |
|
349 continue; |
|
350 } |
|
351 |
297 // Got a match. |
352 // Got a match. |
298 // Trim the query of everything up to the '?'. |
353 // Trim the query of everything up to the '?'. |
299 $query = preg_replace("!^.+\?!", '', $query); |
354 $query = preg_replace("!^.+\?!", '', $query); |
300 |
355 |
301 // Substitute the substring matches into the query. |
356 // Substitute the substring matches into the query. |
302 $query = addslashes(WP_MatchesMapRegex::apply($query, $matches)); |
357 $query = addslashes(WP_MatchesMapRegex::apply($query, $matches)); |
|
358 |
303 // Filter out non-public query vars |
359 // Filter out non-public query vars |
304 global $wp; |
360 global $wp; |
305 parse_str($query, $query_vars); |
361 parse_str($query, $query_vars); |
306 $query = array(); |
362 $query = array(); |
307 foreach ( (array) $query_vars as $key => $value ) { |
363 foreach ( (array) $query_vars as $key => $value ) { |
308 if ( in_array($key, $wp->public_query_vars) ) |
364 if ( in_array($key, $wp->public_query_vars) ) |
309 $query[$key] = $value; |
365 $query[$key] = $value; |
310 } |
366 } |
|
367 |
311 // Do the query |
368 // Do the query |
312 $query = new WP_Query($query); |
369 $query = new WP_Query($query); |
313 if ( $query->is_single || $query->is_page ) |
370 if ( !empty($query->posts) && $query->is_singular ) |
314 return $query->post->ID; |
371 return $query->post->ID; |
315 else |
372 else |
316 return 0; |
373 return 0; |
317 } |
374 } |
318 } |
375 } |
352 * @var bool |
409 * @var bool |
353 */ |
410 */ |
354 var $use_trailing_slashes; |
411 var $use_trailing_slashes; |
355 |
412 |
356 /** |
413 /** |
357 * Customized or default category permalink base ( example.com/xx/tagname ). |
414 * Base for the author permalink structure (example.com/$author_base/authorname). |
358 * |
415 * |
359 * @since 1.5.0 |
416 * @since 1.5.0 |
360 * @access private |
417 * @access private |
361 * @var string |
418 * @var string |
362 */ |
419 */ |
363 var $category_base; |
420 var $author_base = 'author'; |
364 |
421 |
365 /** |
422 /** |
366 * Customized or default tag permalink base ( example.com/xx/tagname ). |
423 * Permalink structure for author archives. |
|
424 * |
|
425 * @since 1.5.0 |
|
426 * @access private |
|
427 * @var string |
|
428 */ |
|
429 var $author_structure; |
|
430 |
|
431 /** |
|
432 * Permalink structure for date archives. |
|
433 * |
|
434 * @since 1.5.0 |
|
435 * @access private |
|
436 * @var string |
|
437 */ |
|
438 var $date_structure; |
|
439 |
|
440 /** |
|
441 * Permalink structure for pages. |
|
442 * |
|
443 * @since 1.5.0 |
|
444 * @access private |
|
445 * @var string |
|
446 */ |
|
447 var $page_structure; |
|
448 |
|
449 /** |
|
450 * Base of the search permalink structure (example.com/$search_base/query). |
|
451 * |
|
452 * @since 1.5.0 |
|
453 * @access private |
|
454 * @var string |
|
455 */ |
|
456 var $search_base = 'search'; |
|
457 |
|
458 /** |
|
459 * Permalink structure for searches. |
|
460 * |
|
461 * @since 1.5.0 |
|
462 * @access private |
|
463 * @var string |
|
464 */ |
|
465 var $search_structure; |
|
466 |
|
467 /** |
|
468 * Comments permalink base. |
|
469 * |
|
470 * @since 1.5.0 |
|
471 * @access private |
|
472 * @var string |
|
473 */ |
|
474 var $comments_base = 'comments'; |
|
475 |
|
476 /** |
|
477 * Pagination permalink base. |
|
478 * |
|
479 * @since 3.1.0 |
|
480 * @access private |
|
481 * @var string |
|
482 */ |
|
483 var $pagination_base = 'page'; |
|
484 |
|
485 /** |
|
486 * Feed permalink base. |
|
487 * |
|
488 * @since 1.5.0 |
|
489 * @access private |
|
490 * @var string |
|
491 */ |
|
492 var $feed_base = 'feed'; |
|
493 |
|
494 /** |
|
495 * Comments feed permalink structure. |
|
496 * |
|
497 * @since 1.5.0 |
|
498 * @access private |
|
499 * @var string |
|
500 */ |
|
501 var $comments_feed_structure; |
|
502 |
|
503 /** |
|
504 * Feed request permalink structure. |
|
505 * |
|
506 * @since 1.5.0 |
|
507 * @access private |
|
508 * @var string |
|
509 */ |
|
510 var $feed_structure; |
|
511 |
|
512 /** |
|
513 * The static portion of the post permalink structure. |
|
514 * |
|
515 * If the permalink structure is "/archive/%post_id%" then the front |
|
516 * is "/archive/". If the permalink structure is "/%year%/%postname%/" |
|
517 * then the front is "/". |
|
518 * |
|
519 * @see WP_Rewrite::init() |
|
520 * @since 1.5.0 |
|
521 * @access private |
|
522 * @var string |
|
523 */ |
|
524 var $front; |
|
525 |
|
526 /** |
|
527 * The prefix for all permalink structures. |
|
528 * |
|
529 * If PATHINFO/index permalinks are in use then the root is the value of |
|
530 * {@link WP_Rewrite::$index} with a trailing slash appended. Otherwise |
|
531 * the root will be empty. |
|
532 * |
|
533 * @see WP_Rewrite::init() |
|
534 * @see WP_Rewrite::using_index_permalinks() |
|
535 * @since 1.5.0 |
|
536 * @access private |
|
537 * @var string |
|
538 */ |
|
539 var $root = ''; |
|
540 |
|
541 /** |
|
542 * The name of the index file which is the entry point to all requests. |
|
543 * |
|
544 * @since 1.5.0 |
|
545 * @access public |
|
546 * @var string |
|
547 */ |
|
548 var $index = 'index.php'; |
|
549 |
|
550 /** |
|
551 * Variable name to use for regex matches in the rewritten query. |
|
552 * |
|
553 * @since 1.5.0 |
|
554 * @access private |
|
555 * @var string |
|
556 */ |
|
557 var $matches = ''; |
|
558 |
|
559 /** |
|
560 * Rewrite rules to match against the request to find the redirect or query. |
|
561 * |
|
562 * @since 1.5.0 |
|
563 * @access private |
|
564 * @var array |
|
565 */ |
|
566 var $rules; |
|
567 |
|
568 /** |
|
569 * Additional rules added external to the rewrite class. |
|
570 * |
|
571 * Those not generated by the class, see add_rewrite_rule(). |
|
572 * |
|
573 * @since 2.1.0 |
|
574 * @access private |
|
575 * @var array |
|
576 */ |
|
577 var $extra_rules = array(); |
|
578 |
|
579 /** |
|
580 * Additional rules that belong at the beginning to match first. |
|
581 * |
|
582 * Those not generated by the class, see add_rewrite_rule(). |
367 * |
583 * |
368 * @since 2.3.0 |
584 * @since 2.3.0 |
369 * @access private |
585 * @access private |
370 * @var string |
|
371 */ |
|
372 var $tag_base; |
|
373 |
|
374 /** |
|
375 * Permalink request structure for categories. |
|
376 * |
|
377 * @since 1.5.0 |
|
378 * @access private |
|
379 * @var string |
|
380 */ |
|
381 var $category_structure; |
|
382 |
|
383 /** |
|
384 * Permalink request structure for tags. |
|
385 * |
|
386 * @since 2.3.0 |
|
387 * @access private |
|
388 * @var string |
|
389 */ |
|
390 var $tag_structure; |
|
391 |
|
392 /** |
|
393 * Permalink author request base ( example.com/author/authorname ). |
|
394 * |
|
395 * @since 1.5.0 |
|
396 * @access private |
|
397 * @var string |
|
398 */ |
|
399 var $author_base = 'author'; |
|
400 |
|
401 /** |
|
402 * Permalink request structure for author pages. |
|
403 * |
|
404 * @since 1.5.0 |
|
405 * @access private |
|
406 * @var string |
|
407 */ |
|
408 var $author_structure; |
|
409 |
|
410 /** |
|
411 * Permalink request structure for dates. |
|
412 * |
|
413 * @since 1.5.0 |
|
414 * @access private |
|
415 * @var string |
|
416 */ |
|
417 var $date_structure; |
|
418 |
|
419 /** |
|
420 * Permalink request structure for pages. |
|
421 * |
|
422 * @since 1.5.0 |
|
423 * @access private |
|
424 * @var string |
|
425 */ |
|
426 var $page_structure; |
|
427 |
|
428 /** |
|
429 * Search permalink base ( example.com/search/query ). |
|
430 * |
|
431 * @since 1.5.0 |
|
432 * @access private |
|
433 * @var string |
|
434 */ |
|
435 var $search_base = 'search'; |
|
436 |
|
437 /** |
|
438 * Permalink request structure for searches. |
|
439 * |
|
440 * @since 1.5.0 |
|
441 * @access private |
|
442 * @var string |
|
443 */ |
|
444 var $search_structure; |
|
445 |
|
446 /** |
|
447 * Comments permalink base. |
|
448 * |
|
449 * @since 1.5.0 |
|
450 * @access private |
|
451 * @var string |
|
452 */ |
|
453 var $comments_base = 'comments'; |
|
454 |
|
455 /** |
|
456 * Feed permalink base. |
|
457 * |
|
458 * @since 1.5.0 |
|
459 * @access private |
|
460 * @var string |
|
461 */ |
|
462 var $feed_base = 'feed'; |
|
463 |
|
464 /** |
|
465 * Comments feed request structure permalink. |
|
466 * |
|
467 * @since 1.5.0 |
|
468 * @access private |
|
469 * @var string |
|
470 */ |
|
471 var $comments_feed_structure; |
|
472 |
|
473 /** |
|
474 * Feed request structure permalink. |
|
475 * |
|
476 * @since 1.5.0 |
|
477 * @access private |
|
478 * @var string |
|
479 */ |
|
480 var $feed_structure; |
|
481 |
|
482 /** |
|
483 * Front URL path. |
|
484 * |
|
485 * The difference between the root property is that WordPress might be |
|
486 * located at example/WordPress/index.php, if permalinks are turned off. The |
|
487 * WordPress/index.php will be the front portion. If permalinks are turned |
|
488 * on, this will most likely be empty or not set. |
|
489 * |
|
490 * @since 1.5.0 |
|
491 * @access private |
|
492 * @var string |
|
493 */ |
|
494 var $front; |
|
495 |
|
496 /** |
|
497 * Root URL path to WordPress (without domain). |
|
498 * |
|
499 * The difference between front property is that WordPress might be located |
|
500 * at example.com/WordPress/. The root is the 'WordPress/' portion. |
|
501 * |
|
502 * @since 1.5.0 |
|
503 * @access private |
|
504 * @var string |
|
505 */ |
|
506 var $root = ''; |
|
507 |
|
508 /** |
|
509 * Permalink to the home page. |
|
510 * |
|
511 * @since 1.5.0 |
|
512 * @access public |
|
513 * @var string |
|
514 */ |
|
515 var $index = 'index.php'; |
|
516 |
|
517 /** |
|
518 * Request match string. |
|
519 * |
|
520 * @since 1.5.0 |
|
521 * @access private |
|
522 * @var string |
|
523 */ |
|
524 var $matches = ''; |
|
525 |
|
526 /** |
|
527 * Rewrite rules to match against the request to find the redirect or query. |
|
528 * |
|
529 * @since 1.5.0 |
|
530 * @access private |
|
531 * @var array |
586 * @var array |
532 */ |
587 */ |
533 var $rules; |
588 var $extra_rules_top = array(); |
534 |
589 |
535 /** |
590 /** |
536 * Additional rules added external to the rewrite class. |
591 * Rules that don't redirect to WordPress' index.php. |
537 * |
592 * |
538 * Those not generated by the class, see add_rewrite_rule(). |
593 * These rules are written to the mod_rewrite portion of the .htaccess, |
|
594 * and are added by {@link add_external_rule()}. |
539 * |
595 * |
540 * @since 2.1.0 |
596 * @since 2.1.0 |
541 * @access private |
597 * @access private |
542 * @var array |
598 * @var array |
543 */ |
599 */ |
544 var $extra_rules = array(); // |
600 var $non_wp_rules = array(); |
545 |
601 |
546 /** |
602 /** |
547 * Additional rules that belong at the beginning to match first. |
603 * Extra permalink structures, e.g. categories, added by {@link add_permastruct()}. |
548 * |
604 * |
549 * Those not generated by the class, see add_rewrite_rule(). |
605 * @since 2.1.0 |
550 * |
|
551 * @since 2.3.0 |
|
552 * @access private |
606 * @access private |
553 * @var array |
607 * @var array |
554 */ |
608 */ |
555 var $extra_rules_top = array(); // |
609 var $extra_permastructs = array(); |
556 |
610 |
557 /** |
611 /** |
558 * Rules that don't redirect to WP's index.php. |
612 * Endpoints (like /trackback/) added by {@link add_rewrite_endpoint()}. |
559 * |
|
560 * These rules are written to the mod_rewrite portion of the .htaccess. |
|
561 * |
613 * |
562 * @since 2.1.0 |
614 * @since 2.1.0 |
563 * @access private |
615 * @access private |
564 * @var array |
616 * @var array |
565 */ |
617 */ |
566 var $non_wp_rules = array(); // |
|
567 |
|
568 /** |
|
569 * Extra permalink structures. |
|
570 * |
|
571 * @since 2.1.0 |
|
572 * @access private |
|
573 * @var array |
|
574 */ |
|
575 var $extra_permastructs = array(); |
|
576 |
|
577 /** |
|
578 * Endpoints permalinks |
|
579 * |
|
580 * @since unknown |
|
581 * @access private |
|
582 * @var array |
|
583 */ |
|
584 var $endpoints; |
618 var $endpoints; |
585 |
619 |
586 /** |
620 /** |
587 * Whether to write every mod_rewrite rule for WordPress. |
621 * Whether to write every mod_rewrite rule for WordPress into the .htaccess file. |
588 * |
622 * |
589 * This is off by default, turning it on might print a lot of rewrite rules |
623 * This is off by default, turning it on might print a lot of rewrite rules |
590 * to the .htaccess file. |
624 * to the .htaccess file. |
591 * |
625 * |
|
626 * @see WP_Rewrite::mod_rewrite_rules() |
592 * @since 2.0.0 |
627 * @since 2.0.0 |
593 * @access public |
628 * @access public |
594 * @var bool |
629 * @var bool |
595 */ |
630 */ |
596 var $use_verbose_rules = false; |
631 var $use_verbose_rules = false; |
597 |
632 |
598 /** |
633 /** |
599 * Whether to write every mod_rewrite rule for WordPress pages. |
634 * Could post permalinks be confused with those of pages? |
600 * |
635 * |
|
636 * If the first rewrite tag in the post permalink structure is one that could |
|
637 * also match a page name (e.g. %postname% or %author%) then this flag is |
|
638 * set to true. Prior to WordPress 3.3 this flag indicated that every page |
|
639 * would have a set of rules added to the top of the rewrite rules array. |
|
640 * Now it tells {@link WP::parse_request()} to check if a URL matching the |
|
641 * page permastruct is actually a page before accepting it. |
|
642 * |
|
643 * @link http://core.trac.wordpress.org/ticket/16687 |
|
644 * @see WP_Rewrite::init() |
601 * @since 2.5.0 |
645 * @since 2.5.0 |
602 * @access public |
646 * @access public |
603 * @var bool |
647 * @var bool |
604 */ |
648 */ |
605 var $use_verbose_page_rules = true; |
649 var $use_verbose_page_rules = true; |
606 |
650 |
607 /** |
651 /** |
608 * Permalink structure search for preg_replace. |
652 * Rewrite tags that can be used in permalink structures. |
|
653 * |
|
654 * These are translated into the regular expressions stored in |
|
655 * {@link WP_Rewrite::$rewritereplace} and are rewritten to the |
|
656 * query variables listed in {@link WP_Rewrite::$queryreplace}. |
|
657 * |
|
658 * Additional tags can be added with {@link add_rewrite_tag()}. |
609 * |
659 * |
610 * @since 1.5.0 |
660 * @since 1.5.0 |
611 * @access private |
661 * @access private |
612 * @var array |
662 * @var array |
613 */ |
663 */ |
614 var $rewritecode = |
664 var $rewritecode = array( |
615 array( |
665 '%year%', |
616 '%year%', |
666 '%monthnum%', |
617 '%monthnum%', |
667 '%day%', |
618 '%day%', |
668 '%hour%', |
619 '%hour%', |
669 '%minute%', |
620 '%minute%', |
670 '%second%', |
621 '%second%', |
671 '%postname%', |
622 '%postname%', |
672 '%post_id%', |
623 '%post_id%', |
673 '%author%', |
624 '%category%', |
674 '%pagename%', |
625 '%tag%', |
675 '%search%' |
626 '%author%', |
676 ); |
627 '%pagename%', |
677 |
628 '%search%' |
678 /** |
629 ); |
679 * Regular expressions to be substituted into rewrite rules in place |
630 |
680 * of rewrite tags, see {@link WP_Rewrite::$rewritecode}. |
631 /** |
|
632 * Preg_replace values for the search, see {@link WP_Rewrite::$rewritecode}. |
|
633 * |
681 * |
634 * @since 1.5.0 |
682 * @since 1.5.0 |
635 * @access private |
683 * @access private |
636 * @var array |
684 * @var array |
637 */ |
685 */ |
638 var $rewritereplace = |
686 var $rewritereplace = array( |
639 array( |
687 '([0-9]{4})', |
640 '([0-9]{4})', |
688 '([0-9]{1,2})', |
641 '([0-9]{1,2})', |
689 '([0-9]{1,2})', |
642 '([0-9]{1,2})', |
690 '([0-9]{1,2})', |
643 '([0-9]{1,2})', |
691 '([0-9]{1,2})', |
644 '([0-9]{1,2})', |
692 '([0-9]{1,2})', |
645 '([0-9]{1,2})', |
693 '([^/]+)', |
646 '([^/]+)', |
694 '([0-9]+)', |
647 '([0-9]+)', |
695 '([^/]+)', |
648 '(.+?)', |
696 '([^/]+?)', |
649 '(.+?)', |
697 '(.+)' |
650 '([^/]+)', |
698 ); |
651 '([^/]+?)', |
699 |
652 '(.+)' |
700 /** |
653 ); |
701 * Query variables that rewrite tags map to, see {@link WP_Rewrite::$rewritecode}. |
654 |
|
655 /** |
|
656 * Search for the query to look for replacing. |
|
657 * |
702 * |
658 * @since 1.5.0 |
703 * @since 1.5.0 |
659 * @access private |
704 * @access private |
660 * @var array |
705 * @var array |
661 */ |
706 */ |
662 var $queryreplace = |
707 var $queryreplace = array( |
663 array ( |
708 'year=', |
664 'year=', |
709 'monthnum=', |
665 'monthnum=', |
710 'day=', |
666 'day=', |
711 'hour=', |
667 'hour=', |
712 'minute=', |
668 'minute=', |
713 'second=', |
669 'second=', |
714 'name=', |
670 'name=', |
715 'p=', |
671 'p=', |
716 'author_name=', |
672 'category_name=', |
717 'pagename=', |
673 'tag=', |
718 's=' |
674 'author_name=', |
719 ); |
675 'pagename=', |
|
676 's=' |
|
677 ); |
|
678 |
720 |
679 /** |
721 /** |
680 * Supported default feeds. |
722 * Supported default feeds. |
681 * |
723 * |
682 * @since 1.5.0 |
724 * @since 1.5.0 |
683 * @access private |
725 * @access private |
684 * @var array |
726 * @var array |
685 */ |
727 */ |
686 var $feeds = array ( 'feed', 'rdf', 'rss', 'rss2', 'atom' ); |
728 var $feeds = array( 'feed', 'rdf', 'rss', 'rss2', 'atom' ); |
687 |
729 |
688 /** |
730 /** |
689 * Whether permalinks are being used. |
731 * Whether permalinks are being used. |
690 * |
732 * |
691 * This can be either rewrite module or permalink in the HTTP query string. |
733 * This can be either rewrite module or permalink in the HTTP query string. |
694 * @access public |
736 * @access public |
695 * |
737 * |
696 * @return bool True, if permalinks are enabled. |
738 * @return bool True, if permalinks are enabled. |
697 */ |
739 */ |
698 function using_permalinks() { |
740 function using_permalinks() { |
699 if (empty($this->permalink_structure)) |
741 return ! empty($this->permalink_structure); |
|
742 } |
|
743 |
|
744 /** |
|
745 * Whether permalinks are being used and rewrite module is not enabled. |
|
746 * |
|
747 * Means that permalink links are enabled and index.php is in the URL. |
|
748 * |
|
749 * @since 1.5.0 |
|
750 * @access public |
|
751 * |
|
752 * @return bool |
|
753 */ |
|
754 function using_index_permalinks() { |
|
755 if ( empty($this->permalink_structure) ) |
700 return false; |
756 return false; |
701 else |
757 |
|
758 // If the index is not in the permalink, we're using mod_rewrite. |
|
759 if ( preg_match('#^/*' . $this->index . '#', $this->permalink_structure) ) |
702 return true; |
760 return true; |
703 } |
761 |
704 |
762 return false; |
705 /** |
763 } |
706 * Whether permalinks are being used and rewrite module is not enabled. |
764 |
707 * |
765 /** |
708 * Means that permalink links are enabled and index.php is in the URL. |
766 * Whether permalinks are being used and rewrite module is enabled. |
|
767 * |
|
768 * Using permalinks and index.php is not in the URL. |
709 * |
769 * |
710 * @since 1.5.0 |
770 * @since 1.5.0 |
711 * @access public |
771 * @access public |
712 * |
772 * |
713 * @return bool |
773 * @return bool |
714 */ |
774 */ |
715 function using_index_permalinks() { |
|
716 if (empty($this->permalink_structure)) { |
|
717 return false; |
|
718 } |
|
719 |
|
720 // If the index is not in the permalink, we're using mod_rewrite. |
|
721 if (preg_match('#^/*' . $this->index . '#', $this->permalink_structure)) { |
|
722 return true; |
|
723 } |
|
724 |
|
725 return false; |
|
726 } |
|
727 |
|
728 /** |
|
729 * Whether permalinks are being used and rewrite module is enabled. |
|
730 * |
|
731 * Using permalinks and index.php is not in the URL. |
|
732 * |
|
733 * @since 1.5.0 |
|
734 * @access public |
|
735 * |
|
736 * @return bool |
|
737 */ |
|
738 function using_mod_rewrite_permalinks() { |
775 function using_mod_rewrite_permalinks() { |
739 if ( $this->using_permalinks() && ! $this->using_index_permalinks()) |
776 if ( $this->using_permalinks() && ! $this->using_index_permalinks() ) |
740 return true; |
777 return true; |
741 else |
778 else |
742 return false; |
779 return false; |
743 } |
780 } |
744 |
781 |
783 */ |
820 */ |
784 function page_uri_index() { |
821 function page_uri_index() { |
785 global $wpdb; |
822 global $wpdb; |
786 |
823 |
787 //get pages in order of hierarchy, i.e. children after parents |
824 //get pages in order of hierarchy, i.e. children after parents |
788 $posts = get_page_hierarchy($wpdb->get_results("SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_type = 'page'")); |
825 $posts = get_page_hierarchy( $wpdb->get_results("SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_type = 'page' AND post_status != 'auto-draft'") ); |
|
826 |
|
827 // If we have no pages get out quick |
|
828 if ( !$posts ) |
|
829 return array( array(), array() ); |
|
830 |
789 //now reverse it, because we need parents after children for rewrite rules to work properly |
831 //now reverse it, because we need parents after children for rewrite rules to work properly |
790 $posts = array_reverse($posts, true); |
832 $posts = array_reverse($posts, true); |
791 |
833 |
792 $page_uris = array(); |
834 $page_uris = array(); |
793 $page_attachment_uris = array(); |
835 $page_attachment_uris = array(); |
794 |
836 |
795 if ( !$posts ) |
837 foreach ( $posts as $id => $post ) { |
796 return array( array(), array() ); |
|
797 |
|
798 foreach ($posts as $id => $post) { |
|
799 // URL => page name |
838 // URL => page name |
800 $uri = get_page_uri($id); |
839 $uri = get_page_uri($id); |
801 $attachments = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_type = 'attachment' AND post_parent = %d", $id )); |
840 $attachments = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_type = 'attachment' AND post_parent = %d", $id )); |
802 if ( $attachments ) { |
841 if ( !empty($attachments) ) { |
803 foreach ( $attachments as $attachment ) { |
842 foreach ( $attachments as $attachment ) { |
804 $attach_uri = get_page_uri($attachment->ID); |
843 $attach_uri = get_page_uri($attachment->ID); |
805 $page_attachment_uris[$attach_uri] = $attachment->ID; |
844 $page_attachment_uris[$attach_uri] = $attachment->ID; |
806 } |
845 } |
807 } |
846 } |
813 } |
852 } |
814 |
853 |
815 /** |
854 /** |
816 * Retrieve all of the rewrite rules for pages. |
855 * Retrieve all of the rewrite rules for pages. |
817 * |
856 * |
818 * If the 'use_verbose_page_rules' property is false, then there will only |
|
819 * be a single rewrite rule for pages for those matching '%pagename%'. With |
|
820 * the property set to true, the attachments and the pages will be added for |
|
821 * each individual attachment URI and page URI, respectively. |
|
822 * |
|
823 * @since 1.5.0 |
857 * @since 1.5.0 |
824 * @access public |
858 * @access public |
825 * |
859 * |
826 * @return array |
860 * @return array |
827 */ |
861 */ |
828 function page_rewrite_rules() { |
862 function page_rewrite_rules() { |
829 $rewrite_rules = array(); |
863 // the extra .? at the beginning prevents clashes with other regular expressions in the rules array |
830 $page_structure = $this->get_page_permastruct(); |
864 $this->add_rewrite_tag( '%pagename%', '(.?.+?)', 'pagename=' ); |
831 |
865 |
832 if ( ! $this->use_verbose_page_rules ) { |
866 return $this->generate_rewrite_rules( $this->get_page_permastruct(), EP_PAGES, true, true, false, false ); |
833 $this->add_rewrite_tag('%pagename%', "(.+?)", 'pagename='); |
|
834 $rewrite_rules = array_merge($rewrite_rules, $this->generate_rewrite_rules($page_structure, EP_PAGES)); |
|
835 return $rewrite_rules; |
|
836 } |
|
837 |
|
838 $page_uris = $this->page_uri_index(); |
|
839 $uris = $page_uris[0]; |
|
840 $attachment_uris = $page_uris[1]; |
|
841 |
|
842 if( is_array( $attachment_uris ) ) { |
|
843 foreach ($attachment_uris as $uri => $pagename) { |
|
844 $this->add_rewrite_tag('%pagename%', "($uri)", 'attachment='); |
|
845 $rewrite_rules = array_merge($rewrite_rules, $this->generate_rewrite_rules($page_structure, EP_PAGES)); |
|
846 } |
|
847 } |
|
848 if( is_array( $uris ) ) { |
|
849 foreach ($uris as $uri => $pagename) { |
|
850 $this->add_rewrite_tag('%pagename%', "($uri)", 'pagename='); |
|
851 $rewrite_rules = array_merge($rewrite_rules, $this->generate_rewrite_rules($page_structure, EP_PAGES)); |
|
852 } |
|
853 } |
|
854 |
|
855 return $rewrite_rules; |
|
856 } |
867 } |
857 |
868 |
858 /** |
869 /** |
859 * Retrieve date permalink structure, with year, month, and day. |
870 * Retrieve date permalink structure, with year, month, and day. |
860 * |
871 * |
1029 * @access public |
1021 * @access public |
1030 * |
1022 * |
1031 * @return bool|string False on failure. Tag permalink structure. |
1023 * @return bool|string False on failure. Tag permalink structure. |
1032 */ |
1024 */ |
1033 function get_tag_permastruct() { |
1025 function get_tag_permastruct() { |
1034 if (isset($this->tag_structure)) { |
1026 return $this->get_extra_permastruct('post_tag'); |
1035 return $this->tag_structure; |
|
1036 } |
|
1037 |
|
1038 if (empty($this->permalink_structure)) { |
|
1039 $this->tag_structure = ''; |
|
1040 return false; |
|
1041 } |
|
1042 |
|
1043 if (empty($this->tag_base)) |
|
1044 $this->tag_structure = trailingslashit( $this->front . 'tag' ); |
|
1045 else |
|
1046 $this->tag_structure = trailingslashit( '/' . $this->root . $this->tag_base ); |
|
1047 |
|
1048 $this->tag_structure .= '%tag%'; |
|
1049 |
|
1050 return $this->tag_structure; |
|
1051 } |
1027 } |
1052 |
1028 |
1053 /** |
1029 /** |
1054 * Retrieve extra permalink structure by name. |
1030 * Retrieve extra permalink structure by name. |
1055 * |
1031 * |
1056 * @since unknown |
1032 * @since 2.5.0 |
1057 * @access public |
1033 * @access public |
1058 * |
1034 * |
1059 * @param string $name Permalink structure name. |
1035 * @param string $name Permalink structure name. |
1060 * @return string|bool False if not found. Permalink structure string. |
1036 * @return string|bool False if not found. Permalink structure string. |
1061 */ |
1037 */ |
1062 function get_extra_permastruct($name) { |
1038 function get_extra_permastruct($name) { |
1063 if ( empty($this->permalink_structure) ) |
1039 if ( empty($this->permalink_structure) ) |
1064 return false; |
1040 return false; |
|
1041 |
1065 if ( isset($this->extra_permastructs[$name]) ) |
1042 if ( isset($this->extra_permastructs[$name]) ) |
1066 return $this->extra_permastructs[$name]; |
1043 return $this->extra_permastructs[$name]['struct']; |
|
1044 |
1067 return false; |
1045 return false; |
1068 } |
1046 } |
1069 |
1047 |
1070 /** |
1048 /** |
1071 * Retrieve the author permalink structure. |
1049 * Retrieve the author permalink structure. |
1201 |
1174 |
1202 return $this->comment_feed_structure; |
1175 return $this->comment_feed_structure; |
1203 } |
1176 } |
1204 |
1177 |
1205 /** |
1178 /** |
1206 * Append or update tag, pattern, and query for replacement. |
1179 * Add or update existing rewrite tags (e.g. %postname%). |
1207 * |
1180 * |
1208 * If the tag already exists, replace the existing pattern and query for |
1181 * If the tag already exists, replace the existing pattern and query for |
1209 * that tag, otherwise add the new tag, pattern, and query to the end of the |
1182 * that tag, otherwise add the new tag. |
1210 * arrays. |
1183 * |
1211 * |
1184 * @see WP_Rewrite::$rewritecode |
1212 * @internal What is the purpose of this function again? Need to finish long |
1185 * @see WP_Rewrite::$rewritereplace |
1213 * description. |
1186 * @see WP_Rewrite::$queryreplace |
1214 * |
1187 * @since 1.5.0 |
1215 * @since 1.5.0 |
1188 * @access public |
1216 * @access public |
1189 * |
1217 * |
1190 * @param string $tag Name of the rewrite tag to add or update. |
1218 * @param string $tag Append tag to rewritecode property array. |
1191 * @param string $regex Regular expression to substitute the tag for in rewrite rules. |
1219 * @param string $pattern Append pattern to rewritereplace property array. |
1192 * @param string $query String to append to the rewritten query. Must end in '='. |
1220 * @param string $query Append query to queryreplace property array. |
1193 */ |
1221 */ |
1194 function add_rewrite_tag( $tag, $regex, $query ) { |
1222 function add_rewrite_tag($tag, $pattern, $query) { |
1195 $position = array_search( $tag, $this->rewritecode ); |
1223 $position = array_search($tag, $this->rewritecode); |
|
1224 if ( false !== $position && null !== $position ) { |
1196 if ( false !== $position && null !== $position ) { |
1225 $this->rewritereplace[$position] = $pattern; |
1197 $this->rewritereplace[ $position ] = $regex; |
1226 $this->queryreplace[$position] = $query; |
1198 $this->queryreplace[ $position ] = $query; |
1227 } else { |
1199 } else { |
1228 $this->rewritecode[] = $tag; |
1200 $this->rewritecode[] = $tag; |
1229 $this->rewritereplace[] = $pattern; |
1201 $this->rewritereplace[] = $regex; |
1230 $this->queryreplace[] = $query; |
1202 $this->queryreplace[] = $query; |
1231 } |
1203 } |
1232 } |
1204 } |
1233 |
1205 |
1234 /** |
1206 /** |
1235 * Generate the rules from permalink structure. |
1207 * Generate rewrite rules from a permalink structure. |
1236 * |
1208 * |
1237 * The main WP_Rewrite function for building the rewrite rule list. The |
1209 * The main WP_Rewrite function for building the rewrite rule list. The |
1238 * contents of the function is a mix of black magic and regular expressions, |
1210 * contents of the function is a mix of black magic and regular expressions, |
1239 * so best just ignore the contents and move to the parameters. |
1211 * so best just ignore the contents and move to the parameters. |
1240 * |
1212 * |
1241 * @since 1.5.0 |
1213 * @since 1.5.0 |
1242 * @access public |
1214 * @access public |
1243 * |
1215 * |
1244 * @param string $permalink_structure The permalink structure. |
1216 * @param string $permalink_structure The permalink structure. |
1245 * @param int $ep_mask Optional, default is EP_NONE. Endpoint constant, see EP_* constants. |
1217 * @param int $ep_mask Endpoint mask defining what endpoints are added to the structure. Default is EP_NONE. |
1246 * @param bool $paged Optional, default is true. Whether permalink request is paged. |
1218 * @param bool $paged Should archive pagination rules be added for the structure? Default is true. |
1247 * @param bool $feed Optional, default is true. Whether for feed. |
1219 * @param bool $feed Should feed rewrite rules be added for the structure? Default is true. |
1248 * @param bool $forcomments Optional, default is false. Whether for comments. |
1220 * @param bool $forcomments Should the feed rules be a query for a comments feed? Default is false. |
1249 * @param bool $walk_dirs Optional, default is true. Whether to create list of directories to walk over. |
1221 * @param bool $walk_dirs Should the 'directories' making up the structure be walked over and rewrite rules |
1250 * @param bool $endpoints Optional, default is true. Whether endpoints are enabled. |
1222 * built for each in turn? Default is true. |
|
1223 * @param bool $endpoints Should endpoints be applied to the generated rewrite rules? Default is true. |
1251 * @return array Rewrite rule list. |
1224 * @return array Rewrite rule list. |
1252 */ |
1225 */ |
1253 function generate_rewrite_rules($permalink_structure, $ep_mask = EP_NONE, $paged = true, $feed = true, $forcomments = false, $walk_dirs = true, $endpoints = true) { |
1226 function generate_rewrite_rules($permalink_structure, $ep_mask = EP_NONE, $paged = true, $feed = true, $forcomments = false, $walk_dirs = true, $endpoints = true) { |
1254 //build a regex to match the feed section of URLs, something like (feed|atom|rss|rss2)/? |
1227 //build a regex to match the feed section of URLs, something like (feed|atom|rss|rss2)/? |
1255 $feedregex2 = ''; |
1228 $feedregex2 = ''; |
1256 foreach ( (array) $this->feeds as $feed_name) { |
1229 foreach ( (array) $this->feeds as $feed_name) |
1257 $feedregex2 .= $feed_name . '|'; |
1230 $feedregex2 .= $feed_name . '|'; |
1258 } |
1231 $feedregex2 = '(' . trim($feedregex2, '|') . ')/?$'; |
1259 $feedregex2 = '(' . trim($feedregex2, '|') . ')/?$'; |
1232 |
1260 //$feedregex is identical but with /feed/ added on as well, so URLs like <permalink>/feed/atom |
1233 //$feedregex is identical but with /feed/ added on as well, so URLs like <permalink>/feed/atom |
1261 //and <permalink>/atom are both possible |
1234 //and <permalink>/atom are both possible |
1262 $feedregex = $this->feed_base . '/' . $feedregex2; |
1235 $feedregex = $this->feed_base . '/' . $feedregex2; |
1263 |
1236 |
1264 //build a regex to match the trackback and page/xx parts of URLs |
1237 //build a regex to match the trackback and page/xx parts of URLs |
1265 $trackbackregex = 'trackback/?$'; |
1238 $trackbackregex = 'trackback/?$'; |
1266 $pageregex = 'page/?([0-9]{1,})/?$'; |
1239 $pageregex = $this->pagination_base . '/?([0-9]{1,})/?$'; |
1267 $commentregex = 'comment-page-([0-9]{1,})/?$'; |
1240 $commentregex = 'comment-page-([0-9]{1,})/?$'; |
1268 |
1241 |
1269 //build up an array of endpoint regexes to append => queries to append |
1242 //build up an array of endpoint regexes to append => queries to append |
1270 if ($endpoints) { |
1243 if ( $endpoints ) { |
1271 $ep_query_append = array (); |
1244 $ep_query_append = array (); |
1272 foreach ( (array) $this->endpoints as $endpoint) { |
1245 foreach ( (array) $this->endpoints as $endpoint) { |
1273 //match everything after the endpoint name, but allow for nothing to appear there |
1246 //match everything after the endpoint name, but allow for nothing to appear there |
1274 $epmatch = $endpoint[1] . '(/(.*))?/?$'; |
1247 $epmatch = $endpoint[1] . '(/(.*))?/?$'; |
1275 //this will be appended on to the rest of the query for each dir |
1248 //this will be appended on to the rest of the query for each dir |
1288 $index = $this->index; //probably 'index.php' |
1261 $index = $this->index; //probably 'index.php' |
1289 $feedindex = $index; |
1262 $feedindex = $index; |
1290 $trackbackindex = $index; |
1263 $trackbackindex = $index; |
1291 //build a list from the rewritecode and queryreplace arrays, that will look something like |
1264 //build a list from the rewritecode and queryreplace arrays, that will look something like |
1292 //tagname=$matches[i] where i is the current $i |
1265 //tagname=$matches[i] where i is the current $i |
1293 for ($i = 0; $i < $num_tokens; ++$i) { |
1266 for ( $i = 0; $i < $num_tokens; ++$i ) { |
1294 if (0 < $i) { |
1267 if ( 0 < $i ) |
1295 $queries[$i] = $queries[$i - 1] . '&'; |
1268 $queries[$i] = $queries[$i - 1] . '&'; |
1296 } else { |
1269 else |
1297 $queries[$i] = ''; |
1270 $queries[$i] = ''; |
1298 } |
|
1299 |
1271 |
1300 $query_token = str_replace($this->rewritecode, $this->queryreplace, $tokens[0][$i]) . $this->preg_index($i+1); |
1272 $query_token = str_replace($this->rewritecode, $this->queryreplace, $tokens[0][$i]) . $this->preg_index($i+1); |
1301 $queries[$i] .= $query_token; |
1273 $queries[$i] .= $query_token; |
1302 } |
1274 } |
1303 |
1275 |
1304 //get the structure, minus any cruft (stuff that isn't tags) at the front |
1276 //get the structure, minus any cruft (stuff that isn't tags) at the front |
1305 $structure = $permalink_structure; |
1277 $structure = $permalink_structure; |
1306 if ($front != '/') { |
1278 if ( $front != '/' ) |
1307 $structure = str_replace($front, '', $structure); |
1279 $structure = str_replace($front, '', $structure); |
1308 } |
1280 |
1309 //create a list of dirs to walk over, making rewrite rules for each level |
1281 //create a list of dirs to walk over, making rewrite rules for each level |
1310 //so for example, a $structure of /%year%/%month%/%postname% would create |
1282 //so for example, a $structure of /%year%/%monthnum%/%postname% would create |
1311 //rewrite rules for /%year%/, /%year%/%month%/ and /%year%/%month%/%postname% |
1283 //rewrite rules for /%year%/, /%year%/%monthnum%/ and /%year%/%monthnum%/%postname% |
1312 $structure = trim($structure, '/'); |
1284 $structure = trim($structure, '/'); |
1313 if ($walk_dirs) { |
1285 $dirs = $walk_dirs ? explode('/', $structure) : array( $structure ); |
1314 $dirs = explode('/', $structure); |
|
1315 } else { |
|
1316 $dirs[] = $structure; |
|
1317 } |
|
1318 $num_dirs = count($dirs); |
1286 $num_dirs = count($dirs); |
1319 |
1287 |
1320 //strip slashes from the front of $front |
1288 //strip slashes from the front of $front |
1321 $front = preg_replace('|^/+|', '', $front); |
1289 $front = preg_replace('|^/+|', '', $front); |
1322 |
1290 |
1323 //the main workhorse loop |
1291 //the main workhorse loop |
1324 $post_rewrite = array(); |
1292 $post_rewrite = array(); |
1325 $struct = $front; |
1293 $struct = $front; |
1326 for ($j = 0; $j < $num_dirs; ++$j) { |
1294 for ( $j = 0; $j < $num_dirs; ++$j ) { |
1327 //get the struct for this dir, and trim slashes off the front |
1295 //get the struct for this dir, and trim slashes off the front |
1328 $struct .= $dirs[$j] . '/'; //accumulate. see comment near explode('/', $structure) above |
1296 $struct .= $dirs[$j] . '/'; //accumulate. see comment near explode('/', $structure) above |
1329 $struct = ltrim($struct, '/'); |
1297 $struct = ltrim($struct, '/'); |
|
1298 |
1330 //replace tags with regexes |
1299 //replace tags with regexes |
1331 $match = str_replace($this->rewritecode, $this->rewritereplace, $struct); |
1300 $match = str_replace($this->rewritecode, $this->rewritereplace, $struct); |
|
1301 |
1332 //make a list of tags, and store how many there are in $num_toks |
1302 //make a list of tags, and store how many there are in $num_toks |
1333 $num_toks = preg_match_all('/%.+?%/', $struct, $toks); |
1303 $num_toks = preg_match_all('/%.+?%/', $struct, $toks); |
|
1304 |
1334 //get the 'tagname=$matches[i]' |
1305 //get the 'tagname=$matches[i]' |
1335 $query = ( isset($queries) && is_array($queries) ) ? $queries[$num_toks - 1] : ''; |
1306 $query = ( isset($queries) && is_array($queries) && !empty($num_toks) ) ? $queries[$num_toks - 1] : ''; |
1336 |
1307 |
1337 //set up $ep_mask_specific which is used to match more specific URL types |
1308 //set up $ep_mask_specific which is used to match more specific URL types |
1338 switch ($dirs[$j]) { |
1309 switch ( $dirs[$j] ) { |
1339 case '%year%': $ep_mask_specific = EP_YEAR; break; |
1310 case '%year%': |
1340 case '%monthnum%': $ep_mask_specific = EP_MONTH; break; |
1311 $ep_mask_specific = EP_YEAR; |
1341 case '%day%': $ep_mask_specific = EP_DAY; break; |
1312 break; |
|
1313 case '%monthnum%': |
|
1314 $ep_mask_specific = EP_MONTH; |
|
1315 break; |
|
1316 case '%day%': |
|
1317 $ep_mask_specific = EP_DAY; |
|
1318 break; |
|
1319 default: |
|
1320 $ep_mask_specific = EP_NONE; |
1342 } |
1321 } |
1343 |
1322 |
1344 //create query for /page/xx |
1323 //create query for /page/xx |
1345 $pagematch = $match . $pageregex; |
1324 $pagematch = $match . $pageregex; |
1346 $pagequery = $index . '?' . $query . '&paged=' . $this->preg_index($num_toks + 1); |
1325 $pagequery = $index . '?' . $query . '&paged=' . $this->preg_index($num_toks + 1); |
1362 //create query for /(feed|atom|rss|rss2|rdf) (see comment near creation of $feedregex) |
1341 //create query for /(feed|atom|rss|rss2|rdf) (see comment near creation of $feedregex) |
1363 $feedmatch2 = $match . $feedregex2; |
1342 $feedmatch2 = $match . $feedregex2; |
1364 $feedquery2 = $feedindex . '?' . $query . '&feed=' . $this->preg_index($num_toks + 1); |
1343 $feedquery2 = $feedindex . '?' . $query . '&feed=' . $this->preg_index($num_toks + 1); |
1365 |
1344 |
1366 //if asked to, turn the feed queries into comment feed ones |
1345 //if asked to, turn the feed queries into comment feed ones |
1367 if ($forcomments) { |
1346 if ( $forcomments ) { |
1368 $feedquery .= '&withcomments=1'; |
1347 $feedquery .= '&withcomments=1'; |
1369 $feedquery2 .= '&withcomments=1'; |
1348 $feedquery2 .= '&withcomments=1'; |
1370 } |
1349 } |
1371 |
1350 |
1372 //start creating the array of rewrites for this dir |
1351 //start creating the array of rewrites for this dir |
1373 $rewrite = array(); |
1352 $rewrite = array(); |
1374 if ($feed) //...adding on /feed/ regexes => queries |
1353 if ( $feed ) //...adding on /feed/ regexes => queries |
1375 $rewrite = array($feedmatch => $feedquery, $feedmatch2 => $feedquery2); |
1354 $rewrite = array($feedmatch => $feedquery, $feedmatch2 => $feedquery2); |
1376 if ($paged) //...and /page/xx ones |
1355 if ( $paged ) //...and /page/xx ones |
1377 $rewrite = array_merge($rewrite, array($pagematch => $pagequery)); |
1356 $rewrite = array_merge($rewrite, array($pagematch => $pagequery)); |
1378 |
1357 |
1379 //only on pages with comments add ../comment-page-xx/ |
1358 //only on pages with comments add ../comment-page-xx/ |
1380 if ( EP_PAGES & $ep_mask || EP_PERMALINK & $ep_mask || EP_NONE & $ep_mask ) |
1359 if ( EP_PAGES & $ep_mask || EP_PERMALINK & $ep_mask ) |
1381 $rewrite = array_merge($rewrite, array($commentmatch => $commentquery)); |
1360 $rewrite = array_merge($rewrite, array($commentmatch => $commentquery)); |
1382 else if ( EP_ROOT & $ep_mask && get_option('page_on_front') ) |
1361 else if ( EP_ROOT & $ep_mask && get_option('page_on_front') ) |
1383 $rewrite = array_merge($rewrite, array($rootcommentmatch => $rootcommentquery)); |
1362 $rewrite = array_merge($rewrite, array($rootcommentmatch => $rootcommentquery)); |
1384 |
1363 |
1385 //do endpoints |
1364 //do endpoints |
1386 if ($endpoints) { |
1365 if ( $endpoints ) { |
1387 foreach ( (array) $ep_query_append as $regex => $ep) { |
1366 foreach ( (array) $ep_query_append as $regex => $ep) { |
1388 //add the endpoints on if the mask fits |
1367 //add the endpoints on if the mask fits |
1389 if ($ep[0] & $ep_mask || $ep[0] & $ep_mask_specific) { |
1368 if ( $ep[0] & $ep_mask || $ep[0] & $ep_mask_specific ) |
1390 $rewrite[$match . $regex] = $index . '?' . $query . $ep[1] . $this->preg_index($num_toks + 2); |
1369 $rewrite[$match . $regex] = $index . '?' . $query . $ep[1] . $this->preg_index($num_toks + 2); |
1391 } |
|
1392 } |
1370 } |
1393 } |
1371 } |
1394 |
1372 |
1395 //if we've got some tags in this dir |
1373 //if we've got some tags in this dir |
1396 if ($num_toks) { |
1374 if ( $num_toks ) { |
1397 $post = false; |
1375 $post = false; |
1398 $page = false; |
1376 $page = false; |
1399 |
1377 |
1400 //check to see if this dir is permalink-level: i.e. the structure specifies an |
1378 //check to see if this dir is permalink-level: i.e. the structure specifies an |
1401 //individual post. Do this by checking it contains at least one of 1) post name, |
1379 //individual post. Do this by checking it contains at least one of 1) post name, |
1402 //2) post ID, 3) page name, 4) timestamp (year, month, day, hour, second and |
1380 //2) post ID, 3) page name, 4) timestamp (year, month, day, hour, second and |
1403 //minute all present). Set these flags now as we need them for the endpoints. |
1381 //minute all present). Set these flags now as we need them for the endpoints. |
1404 if (strpos($struct, '%postname%') !== false || strpos($struct, '%post_id%') !== false |
1382 if ( strpos($struct, '%postname%') !== false |
|
1383 || strpos($struct, '%post_id%') !== false |
1405 || strpos($struct, '%pagename%') !== false |
1384 || strpos($struct, '%pagename%') !== false |
1406 || (strpos($struct, '%year%') !== false && strpos($struct, '%monthnum%') !== false && strpos($struct, '%day%') !== false && strpos($struct, '%hour%') !== false && strpos($struct, '%minute%') !== false && strpos($struct, '%second%') !== false)) { |
1385 || (strpos($struct, '%year%') !== false && strpos($struct, '%monthnum%') !== false && strpos($struct, '%day%') !== false && strpos($struct, '%hour%') !== false && strpos($struct, '%minute%') !== false && strpos($struct, '%second%') !== false) |
|
1386 ) { |
1407 $post = true; |
1387 $post = true; |
1408 if (strpos($struct, '%pagename%') !== false) |
1388 if ( strpos($struct, '%pagename%') !== false ) |
1409 $page = true; |
1389 $page = true; |
1410 } |
1390 } |
1411 |
1391 |
|
1392 if ( ! $post ) { |
|
1393 // For custom post types, we need to add on endpoints as well. |
|
1394 foreach ( get_post_types( array('_builtin' => false ) ) as $ptype ) { |
|
1395 if ( strpos($struct, "%$ptype%") !== false ) { |
|
1396 $post = true; |
|
1397 $page = is_post_type_hierarchical( $ptype ); // This is for page style attachment url's |
|
1398 break; |
|
1399 } |
|
1400 } |
|
1401 } |
|
1402 |
1412 //if we're creating rules for a permalink, do all the endpoints like attachments etc |
1403 //if we're creating rules for a permalink, do all the endpoints like attachments etc |
1413 if ($post) { |
1404 if ( $post ) { |
1414 $post = true; |
|
1415 //create query and regex for trackback |
1405 //create query and regex for trackback |
1416 $trackbackmatch = $match . $trackbackregex; |
1406 $trackbackmatch = $match . $trackbackregex; |
1417 $trackbackquery = $trackbackindex . '?' . $query . '&tb=1'; |
1407 $trackbackquery = $trackbackindex . '?' . $query . '&tb=1'; |
1418 //trim slashes from the end of the regex for this dir |
1408 //trim slashes from the end of the regex for this dir |
1419 $match = rtrim($match, '/'); |
1409 $match = rtrim($match, '/'); |
1420 //get rid of brackets |
1410 //get rid of brackets |
1421 $submatchbase = str_replace(array('(',')'),'',$match); |
1411 $submatchbase = str_replace( array('(', ')'), '', $match); |
1422 |
1412 |
1423 //add a rule for at attachments, which take the form of <permalink>/some-text |
1413 //add a rule for at attachments, which take the form of <permalink>/some-text |
1424 $sub1 = $submatchbase . '/([^/]+)/'; |
1414 $sub1 = $submatchbase . '/([^/]+)/'; |
1425 $sub1tb = $sub1 . $trackbackregex; //add trackback regex <permalink>/trackback/... |
1415 $sub1tb = $sub1 . $trackbackregex; //add trackback regex <permalink>/trackback/... |
1426 $sub1feed = $sub1 . $feedregex; //and <permalink>/feed/(atom|...) |
1416 $sub1feed = $sub1 . $feedregex; //and <permalink>/feed/(atom|...) |
1427 $sub1feed2 = $sub1 . $feedregex2; //and <permalink>/(feed|atom...) |
1417 $sub1feed2 = $sub1 . $feedregex2; //and <permalink>/(feed|atom...) |
1428 $sub1comment = $sub1 . $commentregex; //and <permalink>/comment-page-xx |
1418 $sub1comment = $sub1 . $commentregex; //and <permalink>/comment-page-xx |
1429 //add an ? as we don't have to match that last slash, and finally a $ so we |
|
1430 //match to the end of the URL |
|
1431 |
1419 |
1432 //add another rule to match attachments in the explicit form: |
1420 //add another rule to match attachments in the explicit form: |
1433 //<permalink>/attachment/some-text |
1421 //<permalink>/attachment/some-text |
1434 $sub2 = $submatchbase . '/attachment/([^/]+)/'; |
1422 $sub2 = $submatchbase . '/attachment/([^/]+)/'; |
1435 $sub2tb = $sub2 . $trackbackregex; //and add trackbacks <permalink>/attachment/trackback |
1423 $sub2tb = $sub2 . $trackbackregex; //and add trackbacks <permalink>/attachment/trackback |
1442 $subtbquery = $subquery . '&tb=1'; |
1430 $subtbquery = $subquery . '&tb=1'; |
1443 $subfeedquery = $subquery . '&feed=' . $this->preg_index(2); |
1431 $subfeedquery = $subquery . '&feed=' . $this->preg_index(2); |
1444 $subcommentquery = $subquery . '&cpage=' . $this->preg_index(2); |
1432 $subcommentquery = $subquery . '&cpage=' . $this->preg_index(2); |
1445 |
1433 |
1446 //do endpoints for attachments |
1434 //do endpoints for attachments |
1447 if ( !empty($endpoints) ) { foreach ( (array) $ep_query_append as $regex => $ep ) { |
1435 if ( !empty($endpoints) ) { |
1448 if ($ep[0] & EP_ATTACHMENT) { |
1436 foreach ( (array) $ep_query_append as $regex => $ep ) { |
1449 $rewrite[$sub1 . $regex] = $subquery . $ep[1] . $this->preg_index(2); |
1437 if ( $ep[0] & EP_ATTACHMENT ) { |
1450 $rewrite[$sub2 . $regex] = $subquery . $ep[1] . $this->preg_index(2); |
1438 $rewrite[$sub1 . $regex] = $subquery . $ep[1] . $this->preg_index(2); |
|
1439 $rewrite[$sub2 . $regex] = $subquery . $ep[1] . $this->preg_index(2); |
|
1440 } |
1451 } |
1441 } |
1452 } } |
1442 } |
1453 |
1443 |
1454 //now we've finished with endpoints, finish off the $sub1 and $sub2 matches |
1444 //now we've finished with endpoints, finish off the $sub1 and $sub2 matches |
|
1445 //add a ? as we don't have to match that last slash, and finally a $ so we |
|
1446 //match to the end of the URL |
1455 $sub1 .= '?$'; |
1447 $sub1 .= '?$'; |
1456 $sub2 .= '?$'; |
1448 $sub2 .= '?$'; |
1457 |
1449 |
1458 //allow URLs like <permalink>/2 for <permalink>/page/2 |
1450 //post pagination, e.g. <permalink>/2/ |
1459 $match = $match . '(/[0-9]+)?/?$'; |
1451 $match = $match . '(/[0-9]+)?/?$'; |
1460 $query = $index . '?' . $query . '&page=' . $this->preg_index($num_toks + 1); |
1452 $query = $index . '?' . $query . '&page=' . $this->preg_index($num_toks + 1); |
1461 } else { //not matching a permalink so this is a lot simpler |
1453 } else { //not matching a permalink so this is a lot simpler |
1462 //close the match and finalise the query |
1454 //close the match and finalise the query |
1463 $match .= '?$'; |
1455 $match .= '?$'; |
1524 * @return array An associate array of matches and queries. |
1516 * @return array An associate array of matches and queries. |
1525 */ |
1517 */ |
1526 function rewrite_rules() { |
1518 function rewrite_rules() { |
1527 $rewrite = array(); |
1519 $rewrite = array(); |
1528 |
1520 |
1529 if (empty($this->permalink_structure)) { |
1521 if ( empty($this->permalink_structure) ) |
1530 return $rewrite; |
1522 return $rewrite; |
1531 } |
1523 |
1532 |
1524 // robots.txt -only if installed at the root |
1533 // robots.txt |
1525 $home_path = parse_url( home_url() ); |
1534 $robots_rewrite = array('robots\.txt$' => $this->index . '?robots=1'); |
1526 $robots_rewrite = ( empty( $home_path['path'] ) || '/' == $home_path['path'] ) ? array( 'robots\.txt$' => $this->index . '?robots=1' ) : array(); |
1535 |
1527 |
1536 //Default Feed rules - These are require to allow for the direct access files to work with permalink structure starting with %category% |
1528 // Old feed files |
1537 $default_feeds = array( '.*wp-atom.php$' => $this->index .'?feed=atom', |
1529 $old_feed_files = array( '.*wp-(atom|rdf|rss|rss2|feed|commentsrss2)\.php$' => $this->index . '?feed=old' ); |
1538 '.*wp-rdf.php$' => $this->index .'?feed=rdf', |
1530 |
1539 '.*wp-rss.php$' => $this->index .'?feed=rss', |
1531 // Registration rules |
1540 '.*wp-rss2.php$' => $this->index .'?feed=rss2', |
1532 $registration_pages = array(); |
1541 '.*wp-feed.php$' => $this->index .'?feed=feed', |
1533 if ( is_multisite() && is_main_site() ) { |
1542 '.*wp-commentsrss2.php$' => $this->index . '?feed=rss2&withcomments=1'); |
1534 $registration_pages['.*wp-signup.php$'] = $this->index . '?signup=true'; |
|
1535 $registration_pages['.*wp-activate.php$'] = $this->index . '?activate=true'; |
|
1536 } |
|
1537 $registration_pages['.*wp-register.php$'] = $this->index . '?register=true'; // Deprecated |
1543 |
1538 |
1544 // Post |
1539 // Post |
1545 $post_rewrite = $this->generate_rewrite_rules($this->permalink_structure, EP_PERMALINK); |
1540 $post_rewrite = $this->generate_rewrite_rules( $this->permalink_structure, EP_PERMALINK ); |
1546 $post_rewrite = apply_filters('post_rewrite_rules', $post_rewrite); |
1541 $post_rewrite = apply_filters('post_rewrite_rules', $post_rewrite); |
1547 |
1542 |
1548 // Date |
1543 // Date |
1549 $date_rewrite = $this->generate_rewrite_rules($this->get_date_permastruct(), EP_DATE); |
1544 $date_rewrite = $this->generate_rewrite_rules($this->get_date_permastruct(), EP_DATE); |
1550 $date_rewrite = apply_filters('date_rewrite_rules', $date_rewrite); |
1545 $date_rewrite = apply_filters('date_rewrite_rules', $date_rewrite); |
1560 // Search |
1555 // Search |
1561 $search_structure = $this->get_search_permastruct(); |
1556 $search_structure = $this->get_search_permastruct(); |
1562 $search_rewrite = $this->generate_rewrite_rules($search_structure, EP_SEARCH); |
1557 $search_rewrite = $this->generate_rewrite_rules($search_structure, EP_SEARCH); |
1563 $search_rewrite = apply_filters('search_rewrite_rules', $search_rewrite); |
1558 $search_rewrite = apply_filters('search_rewrite_rules', $search_rewrite); |
1564 |
1559 |
1565 // Categories |
|
1566 $category_rewrite = $this->generate_rewrite_rules($this->get_category_permastruct(), EP_CATEGORIES); |
|
1567 $category_rewrite = apply_filters('category_rewrite_rules', $category_rewrite); |
|
1568 |
|
1569 // Tags |
|
1570 $tag_rewrite = $this->generate_rewrite_rules($this->get_tag_permastruct(), EP_TAGS); |
|
1571 $tag_rewrite = apply_filters('tag_rewrite_rules', $tag_rewrite); |
|
1572 |
|
1573 // Authors |
1560 // Authors |
1574 $author_rewrite = $this->generate_rewrite_rules($this->get_author_permastruct(), EP_AUTHORS); |
1561 $author_rewrite = $this->generate_rewrite_rules($this->get_author_permastruct(), EP_AUTHORS); |
1575 $author_rewrite = apply_filters('author_rewrite_rules', $author_rewrite); |
1562 $author_rewrite = apply_filters('author_rewrite_rules', $author_rewrite); |
1576 |
1563 |
1577 // Pages |
1564 // Pages |
1578 $page_rewrite = $this->page_rewrite_rules(); |
1565 $page_rewrite = $this->page_rewrite_rules(); |
1579 $page_rewrite = apply_filters('page_rewrite_rules', $page_rewrite); |
1566 $page_rewrite = apply_filters('page_rewrite_rules', $page_rewrite); |
1580 |
1567 |
1581 // Extra permastructs |
1568 // Extra permastructs |
1582 foreach ( $this->extra_permastructs as $permastruct ) |
1569 foreach ( $this->extra_permastructs as $permastructname => $struct ) { |
1583 $this->extra_rules_top = array_merge($this->extra_rules_top, $this->generate_rewrite_rules($permastruct, EP_NONE)); |
1570 if ( is_array( $struct ) ) { |
|
1571 if ( count( $struct ) == 2 ) |
|
1572 $rules = $this->generate_rewrite_rules( $struct[0], $struct[1] ); |
|
1573 else |
|
1574 $rules = $this->generate_rewrite_rules( $struct['struct'], $struct['ep_mask'], $struct['paged'], $struct['feed'], $struct['forcomments'], $struct['walk_dirs'], $struct['endpoints'] ); |
|
1575 } else { |
|
1576 $rules = $this->generate_rewrite_rules( $struct ); |
|
1577 } |
|
1578 |
|
1579 $rules = apply_filters($permastructname . '_rewrite_rules', $rules); |
|
1580 if ( 'post_tag' == $permastructname ) |
|
1581 $rules = apply_filters('tag_rewrite_rules', $rules); |
|
1582 |
|
1583 $this->extra_rules_top = array_merge($this->extra_rules_top, $rules); |
|
1584 } |
1584 |
1585 |
1585 // Put them together. |
1586 // Put them together. |
1586 if ( $this->use_verbose_page_rules ) |
1587 if ( $this->use_verbose_page_rules ) |
1587 $this->rules = array_merge($this->extra_rules_top, $robots_rewrite, $default_feeds, $page_rewrite, $root_rewrite, $comments_rewrite, $search_rewrite, $category_rewrite, $tag_rewrite, $author_rewrite, $date_rewrite, $post_rewrite, $this->extra_rules); |
1588 $this->rules = array_merge($this->extra_rules_top, $robots_rewrite, $old_feed_files, $registration_pages, $root_rewrite, $comments_rewrite, $search_rewrite, $author_rewrite, $date_rewrite, $page_rewrite, $post_rewrite, $this->extra_rules); |
1588 else |
1589 else |
1589 $this->rules = array_merge($this->extra_rules_top, $robots_rewrite, $default_feeds, $root_rewrite, $comments_rewrite, $search_rewrite, $category_rewrite, $tag_rewrite, $author_rewrite, $date_rewrite, $post_rewrite, $page_rewrite, $this->extra_rules); |
1590 $this->rules = array_merge($this->extra_rules_top, $robots_rewrite, $old_feed_files, $registration_pages, $root_rewrite, $comments_rewrite, $search_rewrite, $author_rewrite, $date_rewrite, $post_rewrite, $page_rewrite, $this->extra_rules); |
1590 |
1591 |
1591 do_action_ref_array('generate_rewrite_rules', array(&$this)); |
1592 do_action_ref_array('generate_rewrite_rules', array(&$this)); |
1592 $this->rules = apply_filters('rewrite_rules_array', $this->rules); |
1593 $this->rules = apply_filters('rewrite_rules_array', $this->rules); |
1593 |
1594 |
1594 return $this->rules; |
1595 return $this->rules; |
1623 * Retrieve mod_rewrite formatted rewrite rules to write to .htaccess. |
1624 * Retrieve mod_rewrite formatted rewrite rules to write to .htaccess. |
1624 * |
1625 * |
1625 * Does not actually write to the .htaccess file, but creates the rules for |
1626 * Does not actually write to the .htaccess file, but creates the rules for |
1626 * the process that will. |
1627 * the process that will. |
1627 * |
1628 * |
1628 * Will add the non_wp_rules property rules to the .htaccess file before |
1629 * Will add the non_wp_rules property rules to the .htaccess file before |
1629 * the WordPress rewrite rules one. |
1630 * the WordPress rewrite rules one. |
1630 * |
1631 * |
1631 * @since 1.5.0 |
1632 * @since 1.5.0 |
1632 * @access public |
1633 * @access public |
1633 * |
1634 * |
1634 * @return string |
1635 * @return string |
1635 */ |
1636 */ |
1636 function mod_rewrite_rules() { |
1637 function mod_rewrite_rules() { |
1637 if ( ! $this->using_permalinks()) { |
1638 if ( ! $this->using_permalinks() ) |
1638 return ''; |
1639 return ''; |
1639 } |
|
1640 |
1640 |
1641 $site_root = parse_url(get_option('siteurl')); |
1641 $site_root = parse_url(get_option('siteurl')); |
1642 if ( isset( $site_root['path'] ) ) { |
1642 if ( isset( $site_root['path'] ) ) |
1643 $site_root = trailingslashit($site_root['path']); |
1643 $site_root = trailingslashit($site_root['path']); |
1644 } |
1644 |
1645 |
1645 $home_root = parse_url(home_url()); |
1646 $home_root = parse_url(get_option('home')); |
1646 if ( isset( $home_root['path'] ) ) |
1647 if ( isset( $home_root['path'] ) ) { |
|
1648 $home_root = trailingslashit($home_root['path']); |
1647 $home_root = trailingslashit($home_root['path']); |
1649 } else { |
1648 else |
1650 $home_root = '/'; |
1649 $home_root = '/'; |
1651 } |
|
1652 |
1650 |
1653 $rules = "<IfModule mod_rewrite.c>\n"; |
1651 $rules = "<IfModule mod_rewrite.c>\n"; |
1654 $rules .= "RewriteEngine On\n"; |
1652 $rules .= "RewriteEngine On\n"; |
1655 $rules .= "RewriteBase $home_root\n"; |
1653 $rules .= "RewriteBase $home_root\n"; |
|
1654 $rules .= "RewriteRule ^index\.php$ - [L]\n"; // Prevent -f checks on index.php. |
1656 |
1655 |
1657 //add in the rules that don't redirect to WP's index.php (and thus shouldn't be handled by WP at all) |
1656 //add in the rules that don't redirect to WP's index.php (and thus shouldn't be handled by WP at all) |
1658 foreach ( (array) $this->non_wp_rules as $match => $query) { |
1657 foreach ( (array) $this->non_wp_rules as $match => $query) { |
1659 // Apache 1.3 does not support the reluctant (non-greedy) modifier. |
1658 // Apache 1.3 does not support the reluctant (non-greedy) modifier. |
1660 $match = str_replace('.+?', '.+', $match); |
1659 $match = str_replace('.+?', '.+', $match); |
1661 |
1660 |
1662 // If the match is unanchored and greedy, prepend rewrite conditions |
1661 // If the match is unanchored and greedy, prepend rewrite conditions |
1663 // to avoid infinite redirects and eclipsing of real files. |
1662 // to avoid infinite redirects and eclipsing of real files. |
1664 if ($match == '(.+)/?$' || $match == '([^/]+)/?$' ) { |
1663 //if ($match == '(.+)/?$' || $match == '([^/]+)/?$' ) { |
1665 //nada. |
1664 //nada. |
1666 } |
1665 //} |
1667 |
1666 |
1668 $rules .= 'RewriteRule ^' . $match . ' ' . $home_root . $query . " [QSA,L]\n"; |
1667 $rules .= 'RewriteRule ^' . $match . ' ' . $home_root . $query . " [QSA,L]\n"; |
1669 } |
1668 } |
1670 |
1669 |
1671 if ($this->use_verbose_rules) { |
1670 if ( $this->use_verbose_rules ) { |
1672 $this->matches = ''; |
1671 $this->matches = ''; |
1673 $rewrite = $this->rewrite_rules(); |
1672 $rewrite = $this->rewrite_rules(); |
1674 $num_rules = count($rewrite); |
1673 $num_rules = count($rewrite); |
1675 $rules .= "RewriteCond %{REQUEST_FILENAME} -f [OR]\n" . |
1674 $rules .= "RewriteCond %{REQUEST_FILENAME} -f [OR]\n" . |
1676 "RewriteCond %{REQUEST_FILENAME} -d\n" . |
1675 "RewriteCond %{REQUEST_FILENAME} -d\n" . |
1680 // Apache 1.3 does not support the reluctant (non-greedy) modifier. |
1679 // Apache 1.3 does not support the reluctant (non-greedy) modifier. |
1681 $match = str_replace('.+?', '.+', $match); |
1680 $match = str_replace('.+?', '.+', $match); |
1682 |
1681 |
1683 // If the match is unanchored and greedy, prepend rewrite conditions |
1682 // If the match is unanchored and greedy, prepend rewrite conditions |
1684 // to avoid infinite redirects and eclipsing of real files. |
1683 // to avoid infinite redirects and eclipsing of real files. |
1685 if ($match == '(.+)/?$' || $match == '([^/]+)/?$' ) { |
1684 //if ($match == '(.+)/?$' || $match == '([^/]+)/?$' ) { |
1686 //nada. |
1685 //nada. |
1687 } |
1686 //} |
1688 |
1687 |
1689 if (strpos($query, $this->index) !== false) { |
1688 if ( strpos($query, $this->index) !== false ) |
1690 $rules .= 'RewriteRule ^' . $match . ' ' . $home_root . $query . " [QSA,L]\n"; |
1689 $rules .= 'RewriteRule ^' . $match . ' ' . $home_root . $query . " [QSA,L]\n"; |
1691 } else { |
1690 else |
1692 $rules .= 'RewriteRule ^' . $match . ' ' . $site_root . $query . " [QSA,L]\n"; |
1691 $rules .= 'RewriteRule ^' . $match . ' ' . $site_root . $query . " [QSA,L]\n"; |
1693 } |
|
1694 } |
1692 } |
1695 } else { |
1693 } else { |
1696 $rules .= "RewriteCond %{REQUEST_FILENAME} !-f\n" . |
1694 $rules .= "RewriteCond %{REQUEST_FILENAME} !-f\n" . |
1697 "RewriteCond %{REQUEST_FILENAME} !-d\n" . |
1695 "RewriteCond %{REQUEST_FILENAME} !-d\n" . |
1698 "RewriteRule . {$home_root}{$this->index} [L]\n"; |
1696 "RewriteRule . {$home_root}{$this->index} [L]\n"; |
1715 * @since 2.8.0 |
1713 * @since 2.8.0 |
1716 * @access public |
1714 * @access public |
1717 * |
1715 * |
1718 * @return string |
1716 * @return string |
1719 */ |
1717 */ |
1720 function iis7_url_rewrite_rules($add_parent_tags = false, $indent = " ", $end_of_line = "\n") { |
1718 function iis7_url_rewrite_rules( $add_parent_tags = false ) { |
1721 |
1719 |
1722 if ( ! $this->using_permalinks()) { |
1720 if ( ! $this->using_permalinks() ) |
1723 return ''; |
1721 return ''; |
1724 } |
|
1725 |
|
1726 $rules = ''; |
1722 $rules = ''; |
1727 $extra_indent = ''; |
|
1728 if ( $add_parent_tags ) { |
1723 if ( $add_parent_tags ) { |
1729 $rules .= "<configuration>".$end_of_line; |
1724 $rules .= '<configuration> |
1730 $rules .= $indent."<system.webServer>".$end_of_line; |
1725 <system.webServer> |
1731 $rules .= $indent.$indent."<rewrite>".$end_of_line; |
1726 <rewrite> |
1732 $rules .= $indent.$indent.$indent."<rules>".$end_of_line; |
1727 <rules>'; |
1733 $extra_indent = $indent.$indent.$indent.$indent; |
1728 } |
1734 } |
1729 if ( !is_multisite() ) { |
1735 |
1730 $rules .= ' |
1736 $rules .= $extra_indent."<rule name=\"wordpress\" patternSyntax=\"Wildcard\">".$end_of_line; |
1731 <rule name="wordpress" patternSyntax="Wildcard"> |
1737 $rules .= $extra_indent.$indent."<match url=\"*\" />".$end_of_line; |
1732 <match url="*" /> |
1738 $rules .= $extra_indent.$indent.$indent."<conditions>".$end_of_line; |
1733 <conditions> |
1739 $rules .= $extra_indent.$indent.$indent.$indent."<add input=\"{REQUEST_FILENAME}\" matchType=\"IsFile\" negate=\"true\" />".$end_of_line; |
1734 <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> |
1740 $rules .= $extra_indent.$indent.$indent.$indent."<add input=\"{REQUEST_FILENAME}\" matchType=\"IsDirectory\" negate=\"true\" />".$end_of_line; |
1735 <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> |
1741 $rules .= $extra_indent.$indent.$indent."</conditions>".$end_of_line; |
1736 </conditions> |
1742 $rules .= $extra_indent.$indent."<action type=\"Rewrite\" url=\"index.php\" />".$end_of_line; |
1737 <action type="Rewrite" url="index.php" /> |
1743 $rules .= $extra_indent."</rule>"; |
1738 </rule>'; |
1744 |
1739 } else { |
|
1740 if (is_subdomain_install()) { |
|
1741 $rules .= ' |
|
1742 <rule name="wordpress - Rule 1" stopProcessing="true"> |
|
1743 <match url="^index\.php$" ignoreCase="false" /> |
|
1744 <action type="None" /> |
|
1745 </rule> |
|
1746 <rule name="wordpress - Rule 2" stopProcessing="true"> |
|
1747 <match url="^files/(.+)" ignoreCase="false" /> |
|
1748 <action type="Rewrite" url="wp-includes/ms-files.php?file={R:1}" appendQueryString="false" /> |
|
1749 </rule> |
|
1750 <rule name="wordpress - Rule 3" stopProcessing="true"> |
|
1751 <match url="^" ignoreCase="false" /> |
|
1752 <conditions logicalGrouping="MatchAny"> |
|
1753 <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" /> |
|
1754 <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" /> |
|
1755 </conditions> |
|
1756 <action type="None" /> |
|
1757 </rule> |
|
1758 <rule name="wordpress - Rule 4" stopProcessing="true"> |
|
1759 <match url="." ignoreCase="false" /> |
|
1760 <action type="Rewrite" url="index.php" /> |
|
1761 </rule>'; |
|
1762 } else { |
|
1763 $rules .= ' |
|
1764 <rule name="wordpress - Rule 1" stopProcessing="true"> |
|
1765 <match url="^index\.php$" ignoreCase="false" /> |
|
1766 <action type="None" /> |
|
1767 </rule> |
|
1768 <rule name="wordpress - Rule 2" stopProcessing="true"> |
|
1769 <match url="^([_0-9a-zA-Z-]+/)?files/(.+)" ignoreCase="false" /> |
|
1770 <action type="Rewrite" url="wp-includes/ms-files.php?file={R:2}" appendQueryString="false" /> |
|
1771 </rule> |
|
1772 <rule name="wordpress - Rule 3" stopProcessing="true"> |
|
1773 <match url="^([_0-9a-zA-Z-]+/)?wp-admin$" ignoreCase="false" /> |
|
1774 <action type="Redirect" url="{R:1}wp-admin/" redirectType="Permanent" /> |
|
1775 </rule> |
|
1776 <rule name="wordpress - Rule 4" stopProcessing="true"> |
|
1777 <match url="^" ignoreCase="false" /> |
|
1778 <conditions logicalGrouping="MatchAny"> |
|
1779 <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" /> |
|
1780 <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" /> |
|
1781 </conditions> |
|
1782 <action type="None" /> |
|
1783 </rule> |
|
1784 <rule name="wordpress - Rule 5" stopProcessing="true"> |
|
1785 <match url="^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*)" ignoreCase="false" /> |
|
1786 <action type="Rewrite" url="{R:1}" /> |
|
1787 </rule> |
|
1788 <rule name="wordpress - Rule 6" stopProcessing="true"> |
|
1789 <match url="^([_0-9a-zA-Z-]+/)?(.*\.php)$" ignoreCase="false" /> |
|
1790 <action type="Rewrite" url="{R:2}" /> |
|
1791 </rule> |
|
1792 <rule name="wordpress - Rule 7" stopProcessing="true"> |
|
1793 <match url="." ignoreCase="false" /> |
|
1794 <action type="Rewrite" url="index.php" /> |
|
1795 </rule>'; |
|
1796 } |
|
1797 } |
1745 if ( $add_parent_tags ) { |
1798 if ( $add_parent_tags ) { |
1746 $rules .= $end_of_line.$indent.$indent.$indent."</rules>".$end_of_line; |
1799 $rules .= ' |
1747 $rules .= $indent.$indent."</rewrite>".$end_of_line; |
1800 </rules> |
1748 $rules .= $indent."</system.webServer>".$end_of_line; |
1801 </rewrite> |
1749 $rules .= "</configuration>"; |
1802 </system.webServer> |
|
1803 </configuration>'; |
1750 } |
1804 } |
1751 |
1805 |
1752 $rules = apply_filters('iis7_url_rewrite_rules', $rules); |
1806 $rules = apply_filters('iis7_url_rewrite_rules', $rules); |
1753 |
1807 |
1754 return $rules; |
1808 return $rules; |
1798 } |
1852 } |
1799 |
1853 |
1800 /** |
1854 /** |
1801 * Add an endpoint, like /trackback/. |
1855 * Add an endpoint, like /trackback/. |
1802 * |
1856 * |
1803 * To be inserted after certain URL types (specified in $places). |
1857 * See {@link add_rewrite_endpoint()} for full documentation. |
1804 * |
1858 * |
|
1859 * @see add_rewrite_endpoint() |
1805 * @since 2.1.0 |
1860 * @since 2.1.0 |
1806 * @access public |
1861 * @access public |
1807 * |
1862 * @uses WP::add_query_var() |
1808 * @param string $name Name of endpoint. |
1863 * |
1809 * @param array $places URL types that endpoint can be used. |
1864 * @param string $name Name of the endpoint. |
|
1865 * @param int $places Endpoint mask describing the places the endpoint should be added. |
1810 */ |
1866 */ |
1811 function add_endpoint($name, $places) { |
1867 function add_endpoint($name, $places) { |
1812 global $wp; |
1868 global $wp; |
1813 $this->endpoints[] = array ( $places, $name ); |
1869 $this->endpoints[] = array ( $places, $name ); |
1814 $wp->add_query_var($name); |
1870 $wp->add_query_var($name); |
1815 } |
1871 } |
1816 |
1872 |
1817 /** |
1873 /** |
1818 * Add permalink structure. |
1874 * Add a new permalink structure. |
1819 * |
1875 * |
1820 * These are added along with the extra rewrite rules that are merged to the |
1876 * A permalink structure (permastruct) is an abstract definition of a set of rewrite rules; it |
1821 * top. |
1877 * is an easy way of expressing a set of regular expressions that rewrite to a set of query strings. |
1822 * |
1878 * The new permastruct is added to the {@link WP_Rewrite::$extra_permastructs} array. When the |
1823 * @since unknown |
1879 * rewrite rules are built by {@link WP_Rewrite::rewrite_rules()} all of these extra permastructs |
|
1880 * are passed to {@link WP_Rewrite::generate_rewrite_rules()} which transforms them into the |
|
1881 * regular expressions that many love to hate. |
|
1882 * |
|
1883 * The $args parameter gives you control over how {@link WP_Rewrite::generate_rewrite_rules()} |
|
1884 * works on the new permastruct. |
|
1885 * |
|
1886 * @since 2.5.0 |
1824 * @access public |
1887 * @access public |
1825 * |
1888 * |
1826 * @param string $name Name for permalink structure. |
1889 * @param string $name Name for permalink structure. |
1827 * @param string $struct Permalink structure. |
1890 * @param string $struct Permalink structure (e.g. category/%category%) |
1828 * @param bool $with_front Prepend front base to permalink structure. |
1891 * @param array $args Optional configuration for building the rules from the permalink structure: |
1829 */ |
1892 * - with_front (bool) - Should the structure be prepended with WP_Rewrite::$front? Default is true. |
1830 function add_permastruct($name, $struct, $with_front = true) { |
1893 * - ep_mask (int) - Endpoint mask defining what endpoints are added to the structure. Default is EP_NONE. |
1831 if ( $with_front ) |
1894 * - paged (bool) - Should archive pagination rules be added for the structure? Default is true. |
|
1895 * - feed (bool) - Should feed rewrite rules be added for the structure? Default is true. |
|
1896 * - forcomments (bool) - Should the feed rules be a query for a comments feed? Default is false. |
|
1897 * - walk_dirs (bool) - Should the 'directories' making up the structure be walked over and rewrite |
|
1898 * rules built for each in turn? Default is true. |
|
1899 * - endpoints (bool) - Should endpoints be applied to the generated rewrite rules? Default is true. |
|
1900 */ |
|
1901 function add_permastruct( $name, $struct, $args = array() ) { |
|
1902 // backwards compatibility for the old parameters: $with_front and $ep_mask |
|
1903 if ( ! is_array( $args ) ) |
|
1904 $args = array( 'with_front' => $args ); |
|
1905 if ( func_num_args() == 4 ) |
|
1906 $args['ep_mask'] = func_get_arg( 3 ); |
|
1907 |
|
1908 $defaults = array( |
|
1909 'with_front' => true, |
|
1910 'ep_mask' => EP_NONE, |
|
1911 'paged' => true, |
|
1912 'feed' => true, |
|
1913 'forcomments' => false, |
|
1914 'walk_dirs' => true, |
|
1915 'endpoints' => true, |
|
1916 ); |
|
1917 $args = array_intersect_key( $args, $defaults ); |
|
1918 $args = wp_parse_args( $args, $defaults ); |
|
1919 |
|
1920 if ( $args['with_front'] ) |
1832 $struct = $this->front . $struct; |
1921 $struct = $this->front . $struct; |
1833 $this->extra_permastructs[$name] = $struct; |
1922 else |
|
1923 $struct = $this->root . $struct; |
|
1924 $args['struct'] = $struct; |
|
1925 |
|
1926 $this->extra_permastructs[ $name ] = $args; |
1834 } |
1927 } |
1835 |
1928 |
1836 /** |
1929 /** |
1837 * Remove rewrite rules and then recreate rewrite rules. |
1930 * Remove rewrite rules and then recreate rewrite rules. |
1838 * |
1931 * |
1866 function init() { |
1959 function init() { |
1867 $this->extra_rules = $this->non_wp_rules = $this->endpoints = array(); |
1960 $this->extra_rules = $this->non_wp_rules = $this->endpoints = array(); |
1868 $this->permalink_structure = get_option('permalink_structure'); |
1961 $this->permalink_structure = get_option('permalink_structure'); |
1869 $this->front = substr($this->permalink_structure, 0, strpos($this->permalink_structure, '%')); |
1962 $this->front = substr($this->permalink_structure, 0, strpos($this->permalink_structure, '%')); |
1870 $this->root = ''; |
1963 $this->root = ''; |
1871 if ($this->using_index_permalinks()) { |
1964 if ( $this->using_index_permalinks() ) |
1872 $this->root = $this->index . '/'; |
1965 $this->root = $this->index . '/'; |
1873 } |
|
1874 $this->category_base = get_option( 'category_base' ); |
|
1875 $this->tag_base = get_option( 'tag_base' ); |
|
1876 unset($this->category_structure); |
|
1877 unset($this->author_structure); |
1966 unset($this->author_structure); |
1878 unset($this->date_structure); |
1967 unset($this->date_structure); |
1879 unset($this->page_structure); |
1968 unset($this->page_structure); |
1880 unset($this->search_structure); |
1969 unset($this->search_structure); |
1881 unset($this->feed_structure); |
1970 unset($this->feed_structure); |
1882 unset($this->comment_feed_structure); |
1971 unset($this->comment_feed_structure); |
1883 $this->use_trailing_slashes = ( substr($this->permalink_structure, -1, 1) == '/' ) ? true : false; |
1972 $this->use_trailing_slashes = ( '/' == substr($this->permalink_structure, -1, 1) ); |
1884 |
1973 |
1885 // Enable generic rules for pages if permalink structure doesn't begin with a wildcard. |
1974 // Enable generic rules for pages if permalink structure doesn't begin with a wildcard. |
1886 if ( preg_match("/^[^%]*%(?:postname|category|tag|author)%/", $this->permalink_structure) ) |
1975 if ( preg_match("/^[^%]*%(?:postname|category|tag|author)%/", $this->permalink_structure) ) |
1887 $this->use_verbose_page_rules = true; |
1976 $this->use_verbose_page_rules = true; |
1888 else |
1977 else |