raw
mp-wp_genesis           1 <?php
mp-wp_genesis 2 /**
mp-wp_genesis 3 * WordPress Rewrite API
mp-wp_genesis 4 *
mp-wp_genesis 5 * @package WordPress
mp-wp_genesis 6 * @subpackage Rewrite
mp-wp_genesis 7 */
mp-wp_genesis 8
mp-wp_genesis 9 /**
mp-wp_genesis 10 * Add a straight rewrite rule.
mp-wp_genesis 11 *
mp-wp_genesis 12 * @see WP_Rewrite::add_rule() for long description.
mp-wp_genesis 13 * @since 2.1.0
mp-wp_genesis 14 *
mp-wp_genesis 15 * @param string $regex Regular Expression to match request against.
mp-wp_genesis 16 * @param string $redirect Page to redirect to.
mp-wp_genesis 17 * @param string $after Optional, default is 'bottom'. Where to add rule, can also be 'top'.
mp-wp_genesis 18 */
mp-wp_genesis 19 function add_rewrite_rule($regex, $redirect, $after = 'bottom') {
mp-wp_genesis 20 global $wp_rewrite;
mp-wp_genesis 21 $wp_rewrite->add_rule($regex, $redirect, $after);
mp-wp_genesis 22 }
mp-wp_genesis 23
mp-wp_genesis 24 /**
mp-wp_genesis 25 * Add a new tag (like %postname%).
mp-wp_genesis 26 *
mp-wp_genesis 27 * Warning: you must call this on init or earlier, otherwise the query var
mp-wp_genesis 28 * addition stuff won't work.
mp-wp_genesis 29 *
mp-wp_genesis 30 * @since 2.1.0
mp-wp_genesis 31 *
mp-wp_genesis 32 * @param string $tagname
mp-wp_genesis 33 * @param string $regex
mp-wp_genesis 34 */
mp-wp_genesis 35 function add_rewrite_tag($tagname, $regex) {
mp-wp_genesis 36 //validation
mp-wp_genesis 37 if (strlen($tagname) < 3 || $tagname{0} != '%' || $tagname{strlen($tagname)-1} != '%') {
mp-wp_genesis 38 return;
mp-wp_genesis 39 }
mp-wp_genesis 40
mp-wp_genesis 41 $qv = trim($tagname, '%');
mp-wp_genesis 42
mp-wp_genesis 43 global $wp_rewrite, $wp;
mp-wp_genesis 44 $wp->add_query_var($qv);
mp-wp_genesis 45 $wp_rewrite->add_rewrite_tag($tagname, $regex, $qv . '=');
mp-wp_genesis 46 }
mp-wp_genesis 47
mp-wp_genesis 48 /**
mp-wp_genesis 49 * Add a new feed type like /atom1/.
mp-wp_genesis 50 *
mp-wp_genesis 51 * @since 2.1.0
mp-wp_genesis 52 *
mp-wp_genesis 53 * @param string $feedname
mp-wp_genesis 54 * @param callback $function Callback to run on feed display.
mp-wp_genesis 55 * @return string Feed action name.
mp-wp_genesis 56 */
mp-wp_genesis 57 function add_feed($feedname, $function) {
mp-wp_genesis 58 global $wp_rewrite;
mp-wp_genesis 59 if (!in_array($feedname, $wp_rewrite->feeds)) { //override the file if it is
mp-wp_genesis 60 $wp_rewrite->feeds[] = $feedname;
mp-wp_genesis 61 }
mp-wp_genesis 62 $hook = 'do_feed_' . $feedname;
mp-wp_genesis 63 // Remove default function hook
mp-wp_genesis 64 remove_action($hook, $hook, 10, 1);
mp-wp_genesis 65 add_action($hook, $function, 10, 1);
mp-wp_genesis 66 return $hook;
mp-wp_genesis 67 }
mp-wp_genesis 68
mp-wp_genesis 69 /**
mp-wp_genesis 70 * Endpoint Mask for Permalink.
mp-wp_genesis 71 *
mp-wp_genesis 72 * @since 2.1.0
mp-wp_genesis 73 */
mp-wp_genesis 74 define('EP_PERMALINK', 1);
mp-wp_genesis 75
mp-wp_genesis 76 /**
mp-wp_genesis 77 * Endpoint Mask for Attachment.
mp-wp_genesis 78 *
mp-wp_genesis 79 * @since 2.1.0
mp-wp_genesis 80 */
mp-wp_genesis 81 define('EP_ATTACHMENT', 2);
mp-wp_genesis 82
mp-wp_genesis 83 /**
mp-wp_genesis 84 * Endpoint Mask for date.
mp-wp_genesis 85 *
mp-wp_genesis 86 * @since 2.1.0
mp-wp_genesis 87 */
mp-wp_genesis 88 define('EP_DATE', 4);
mp-wp_genesis 89
mp-wp_genesis 90 /**
mp-wp_genesis 91 * Endpoint Mask for year
mp-wp_genesis 92 *
mp-wp_genesis 93 * @since 2.1.0
mp-wp_genesis 94 */
mp-wp_genesis 95 define('EP_YEAR', 8);
mp-wp_genesis 96
mp-wp_genesis 97 /**
mp-wp_genesis 98 * Endpoint Mask for month.
mp-wp_genesis 99 *
mp-wp_genesis 100 * @since 2.1.0
mp-wp_genesis 101 */
mp-wp_genesis 102 define('EP_MONTH', 16);
mp-wp_genesis 103
mp-wp_genesis 104 /**
mp-wp_genesis 105 * Endpoint Mask for day.
mp-wp_genesis 106 *
mp-wp_genesis 107 * @since 2.1.0
mp-wp_genesis 108 */
mp-wp_genesis 109 define('EP_DAY', 32);
mp-wp_genesis 110
mp-wp_genesis 111 /**
mp-wp_genesis 112 * Endpoint Mask for root.
mp-wp_genesis 113 *
mp-wp_genesis 114 * @since 2.1.0
mp-wp_genesis 115 */
mp-wp_genesis 116 define('EP_ROOT', 64);
mp-wp_genesis 117
mp-wp_genesis 118 /**
mp-wp_genesis 119 * Endpoint Mask for comments.
mp-wp_genesis 120 *
mp-wp_genesis 121 * @since 2.1.0
mp-wp_genesis 122 */
mp-wp_genesis 123 define('EP_COMMENTS', 128);
mp-wp_genesis 124
mp-wp_genesis 125 /**
mp-wp_genesis 126 * Endpoint Mask for searches.
mp-wp_genesis 127 *
mp-wp_genesis 128 * @since 2.1.0
mp-wp_genesis 129 */
mp-wp_genesis 130 define('EP_SEARCH', 256);
mp-wp_genesis 131
mp-wp_genesis 132 /**
mp-wp_genesis 133 * Endpoint Mask for categories.
mp-wp_genesis 134 *
mp-wp_genesis 135 * @since 2.1.0
mp-wp_genesis 136 */
mp-wp_genesis 137 define('EP_CATEGORIES', 512);
mp-wp_genesis 138
mp-wp_genesis 139 /**
mp-wp_genesis 140 * Endpoint Mask for tags.
mp-wp_genesis 141 *
mp-wp_genesis 142 * @since 2.3.0
mp-wp_genesis 143 */
mp-wp_genesis 144 define('EP_TAGS', 1024);
mp-wp_genesis 145
mp-wp_genesis 146 /**
mp-wp_genesis 147 * Endpoint Mask for authors.
mp-wp_genesis 148 *
mp-wp_genesis 149 * @since 2.1.0
mp-wp_genesis 150 */
mp-wp_genesis 151 define('EP_AUTHORS', 2048);
mp-wp_genesis 152
mp-wp_genesis 153 /**
mp-wp_genesis 154 * Endpoint Mask for pages.
mp-wp_genesis 155 *
mp-wp_genesis 156 * @since 2.1.0
mp-wp_genesis 157 */
mp-wp_genesis 158 define('EP_PAGES', 4096);
mp-wp_genesis 159
mp-wp_genesis 160 //pseudo-places
mp-wp_genesis 161 /**
mp-wp_genesis 162 * Endpoint Mask for default, which is nothing.
mp-wp_genesis 163 *
mp-wp_genesis 164 * @since 2.1.0
mp-wp_genesis 165 */
mp-wp_genesis 166 define('EP_NONE', 0);
mp-wp_genesis 167
mp-wp_genesis 168 /**
mp-wp_genesis 169 * Endpoint Mask for everything.
mp-wp_genesis 170 *
mp-wp_genesis 171 * @since 2.1.0
mp-wp_genesis 172 */
mp-wp_genesis 173 define('EP_ALL', 8191);
mp-wp_genesis 174
mp-wp_genesis 175 /**
mp-wp_genesis 176 * Add an endpoint, like /trackback/.
mp-wp_genesis 177 *
mp-wp_genesis 178 * The endpoints are added to the end of the request. So a request matching
mp-wp_genesis 179 * "/2008/10/14/my_post/myep/", the endpoint will be "/myep/".
mp-wp_genesis 180 *
mp-wp_genesis 181 * @since 2.1.0
mp-wp_genesis 182 * @see WP_Rewrite::add_endpoint() Parameters and more description.
mp-wp_genesis 183 * @uses $wp_rewrite
mp-wp_genesis 184 *
mp-wp_genesis 185 * @param unknown_type $name
mp-wp_genesis 186 * @param unknown_type $places
mp-wp_genesis 187 */
mp-wp_genesis 188 function add_rewrite_endpoint($name, $places) {
mp-wp_genesis 189 global $wp_rewrite;
mp-wp_genesis 190 $wp_rewrite->add_endpoint($name, $places);
mp-wp_genesis 191 }
mp-wp_genesis 192
mp-wp_genesis 193 /**
mp-wp_genesis 194 * Filter the URL base for taxonomies.
mp-wp_genesis 195 *
mp-wp_genesis 196 * To remove any manually prepended /index.php/.
mp-wp_genesis 197 *
mp-wp_genesis 198 * @access private
mp-wp_genesis 199 * @since 2.6.0
mp-wp_genesis 200 * @author Mark Jaquith
mp-wp_genesis 201 *
mp-wp_genesis 202 * @param string $base The taxonomy base that we're going to filter
mp-wp_genesis 203 * @return string
mp-wp_genesis 204 */
mp-wp_genesis 205 function _wp_filter_taxonomy_base( $base ) {
mp-wp_genesis 206 if ( !empty( $base ) ) {
mp-wp_genesis 207 $base = preg_replace( '|^/index\.php/|', '', $base );
mp-wp_genesis 208 $base = trim( $base, '/' );
mp-wp_genesis 209 }
mp-wp_genesis 210 return $base;
mp-wp_genesis 211 }
mp-wp_genesis 212
mp-wp_genesis 213 /**
mp-wp_genesis 214 * Examine a url and try to determine the post ID it represents.
mp-wp_genesis 215 *
mp-wp_genesis 216 * Checks are supposedly from the hosted site blog.
mp-wp_genesis 217 *
mp-wp_genesis 218 * @since 1.0.0
mp-wp_genesis 219 *
mp-wp_genesis 220 * @param string $url Permalink to check.
mp-wp_genesis 221 * @return int Post ID, or 0 on failure.
mp-wp_genesis 222 */
mp-wp_genesis 223 function url_to_postid($url) {
mp-wp_genesis 224 global $wp_rewrite;
mp-wp_genesis 225
mp-wp_genesis 226 $url = apply_filters('url_to_postid', $url);
mp-wp_genesis 227
mp-wp_genesis 228 // First, check to see if there is a 'p=N' or 'page_id=N' to match against
mp-wp_genesis 229 if ( preg_match('#[?&](p|page_id|attachment_id)=(\d+)#', $url, $values) ) {
mp-wp_genesis 230 $id = absint($values[2]);
mp-wp_genesis 231 if ($id)
mp-wp_genesis 232 return $id;
mp-wp_genesis 233 }
mp-wp_genesis 234
mp-wp_genesis 235 // Check to see if we are using rewrite rules
mp-wp_genesis 236 $rewrite = $wp_rewrite->wp_rewrite_rules();
mp-wp_genesis 237
mp-wp_genesis 238 // Not using rewrite rules, and 'p=N' and 'page_id=N' methods failed, so we're out of options
mp-wp_genesis 239 if ( empty($rewrite) )
mp-wp_genesis 240 return 0;
mp-wp_genesis 241
mp-wp_genesis 242 // $url cleanup by Mark Jaquith
mp-wp_genesis 243 // This fixes things like #anchors, ?query=strings, missing 'www.',
mp-wp_genesis 244 // added 'www.', or added 'index.php/' that will mess up our WP_Query
mp-wp_genesis 245 // and return a false negative
mp-wp_genesis 246
mp-wp_genesis 247 // Get rid of the #anchor
mp-wp_genesis 248 $url_split = explode('#', $url);
mp-wp_genesis 249 $url = $url_split[0];
mp-wp_genesis 250
mp-wp_genesis 251 // Get rid of URL ?query=string
mp-wp_genesis 252 $url_split = explode('?', $url);
mp-wp_genesis 253 $url = $url_split[0];
mp-wp_genesis 254
mp-wp_genesis 255 // Add 'www.' if it is absent and should be there
mp-wp_genesis 256 if ( false !== strpos(get_option('home'), '://www.') && false === strpos($url, '://www.') )
mp-wp_genesis 257 $url = str_replace('://', '://www.', $url);
mp-wp_genesis 258
mp-wp_genesis 259 // Strip 'www.' if it is present and shouldn't be
mp-wp_genesis 260 if ( false === strpos(get_option('home'), '://www.') )
mp-wp_genesis 261 $url = str_replace('://www.', '://', $url);
mp-wp_genesis 262
mp-wp_genesis 263 // Strip 'index.php/' if we're not using path info permalinks
mp-wp_genesis 264 if ( !$wp_rewrite->using_index_permalinks() )
mp-wp_genesis 265 $url = str_replace('index.php/', '', $url);
mp-wp_genesis 266
mp-wp_genesis 267 if ( false !== strpos($url, get_option('home')) ) {
mp-wp_genesis 268 // Chop off http://domain.com
mp-wp_genesis 269 $url = str_replace(get_option('home'), '', $url);
mp-wp_genesis 270 } else {
mp-wp_genesis 271 // Chop off /path/to/blog
mp-wp_genesis 272 $home_path = parse_url(get_option('home'));
mp-wp_genesis 273 $home_path = $home_path['path'];
mp-wp_genesis 274 $url = str_replace($home_path, '', $url);
mp-wp_genesis 275 }
mp-wp_genesis 276
mp-wp_genesis 277 // Trim leading and lagging slashes
mp-wp_genesis 278 $url = trim($url, '/');
mp-wp_genesis 279
mp-wp_genesis 280 $request = $url;
mp-wp_genesis 281
mp-wp_genesis 282 // Done with cleanup
mp-wp_genesis 283
mp-wp_genesis 284 // Look for matches.
mp-wp_genesis 285 $request_match = $request;
mp-wp_genesis 286 foreach ($rewrite as $match => $query) {
mp-wp_genesis 287 // If the requesting file is the anchor of the match, prepend it
mp-wp_genesis 288 // to the path info.
mp-wp_genesis 289 if ( (! empty($url)) && (strpos($match, $url) === 0) && ($url != $request)) {
mp-wp_genesis 290 $request_match = $url . '/' . $request;
mp-wp_genesis 291 }
mp-wp_genesis 292
mp-wp_genesis 293 if ( preg_match("!^$match!", $request_match, $matches) ) {
mp-wp_genesis 294 // Got a match.
mp-wp_genesis 295 // Trim the query of everything up to the '?'.
mp-wp_genesis 296 $query = preg_replace("!^.+\?!", '', $query);
mp-wp_genesis 297
mp-wp_genesis 298 // Substitute the substring matches into the query.
mp-wp_genesis 299 eval("\$query = \"" . addslashes($query) . "\";");
mp-wp_genesis 300 // Filter out non-public query vars
mp-wp_genesis 301 global $wp;
mp-wp_genesis 302 parse_str($query, $query_vars);
mp-wp_genesis 303 $query = array();
mp-wp_genesis 304 foreach ( (array) $query_vars as $key => $value ) {
mp-wp_genesis 305 if ( in_array($key, $wp->public_query_vars) )
mp-wp_genesis 306 $query[$key] = $value;
mp-wp_genesis 307 }
mp-wp_genesis 308 // Do the query
mp-wp_genesis 309 $query = new WP_Query($query);
mp-wp_genesis 310 if ( $query->is_single || $query->is_page )
mp-wp_genesis 311 return $query->post->ID;
mp-wp_genesis 312 else
mp-wp_genesis 313 return 0;
mp-wp_genesis 314 }
mp-wp_genesis 315 }
mp-wp_genesis 316 return 0;
mp-wp_genesis 317 }
mp-wp_genesis 318
mp-wp_genesis 319 /**
mp-wp_genesis 320 * WordPress Rewrite Component.
mp-wp_genesis 321 *
mp-wp_genesis 322 * The WordPress Rewrite class writes the rewrite module rules to the .htaccess
mp-wp_genesis 323 * file. It also handles parsing the request to get the correct setup for the
mp-wp_genesis 324 * WordPress Query class.
mp-wp_genesis 325 *
mp-wp_genesis 326 * The Rewrite along with WP class function as a front controller for WordPress.
mp-wp_genesis 327 * You can add rules to trigger your page view and processing using this
mp-wp_genesis 328 * component. The full functionality of a front controller does not exist,
mp-wp_genesis 329 * meaning you can't define how the template files load based on the rewrite
mp-wp_genesis 330 * rules.
mp-wp_genesis 331 *
mp-wp_genesis 332 * @since 1.5.0
mp-wp_genesis 333 */
mp-wp_genesis 334 class WP_Rewrite {
mp-wp_genesis 335 /**
mp-wp_genesis 336 * Default permalink structure for WordPress.
mp-wp_genesis 337 *
mp-wp_genesis 338 * @since 1.5.0
mp-wp_genesis 339 * @access private
mp-wp_genesis 340 * @var string
mp-wp_genesis 341 */
mp-wp_genesis 342 var $permalink_structure;
mp-wp_genesis 343
mp-wp_genesis 344 /**
mp-wp_genesis 345 * Whether to add trailing slashes.
mp-wp_genesis 346 *
mp-wp_genesis 347 * @since 2.2.0
mp-wp_genesis 348 * @access private
mp-wp_genesis 349 * @var bool
mp-wp_genesis 350 */
mp-wp_genesis 351 var $use_trailing_slashes;
mp-wp_genesis 352
mp-wp_genesis 353 /**
mp-wp_genesis 354 * Customized or default category permalink base ( example.com/xx/tagname ).
mp-wp_genesis 355 *
mp-wp_genesis 356 * @since 1.5.0
mp-wp_genesis 357 * @access private
mp-wp_genesis 358 * @var string
mp-wp_genesis 359 */
mp-wp_genesis 360 var $category_base;
mp-wp_genesis 361
mp-wp_genesis 362 /**
mp-wp_genesis 363 * Customized or default tag permalink base ( example.com/xx/tagname ).
mp-wp_genesis 364 *
mp-wp_genesis 365 * @since 2.3.0
mp-wp_genesis 366 * @access private
mp-wp_genesis 367 * @var string
mp-wp_genesis 368 */
mp-wp_genesis 369 var $tag_base;
mp-wp_genesis 370
mp-wp_genesis 371 /**
mp-wp_genesis 372 * Permalink request structure for categories.
mp-wp_genesis 373 *
mp-wp_genesis 374 * @since 1.5.0
mp-wp_genesis 375 * @access private
mp-wp_genesis 376 * @var string
mp-wp_genesis 377 */
mp-wp_genesis 378 var $category_structure;
mp-wp_genesis 379
mp-wp_genesis 380 /**
mp-wp_genesis 381 * Permalink request structure for tags.
mp-wp_genesis 382 *
mp-wp_genesis 383 * @since 2.3.0
mp-wp_genesis 384 * @access private
mp-wp_genesis 385 * @var string
mp-wp_genesis 386 */
mp-wp_genesis 387 var $tag_structure;
mp-wp_genesis 388
mp-wp_genesis 389 /**
mp-wp_genesis 390 * Permalink author request base ( example.com/author/authorname ).
mp-wp_genesis 391 *
mp-wp_genesis 392 * @since 1.5.0
mp-wp_genesis 393 * @access private
mp-wp_genesis 394 * @var string
mp-wp_genesis 395 */
mp-wp_genesis 396 var $author_base = 'author';
mp-wp_genesis 397
mp-wp_genesis 398 /**
mp-wp_genesis 399 * Permalink request structure for author pages.
mp-wp_genesis 400 *
mp-wp_genesis 401 * @since 1.5.0
mp-wp_genesis 402 * @access private
mp-wp_genesis 403 * @var string
mp-wp_genesis 404 */
mp-wp_genesis 405 var $author_structure;
mp-wp_genesis 406
mp-wp_genesis 407 /**
mp-wp_genesis 408 * Permalink request structure for dates.
mp-wp_genesis 409 *
mp-wp_genesis 410 * @since 1.5.0
mp-wp_genesis 411 * @access private
mp-wp_genesis 412 * @var string
mp-wp_genesis 413 */
mp-wp_genesis 414 var $date_structure;
mp-wp_genesis 415
mp-wp_genesis 416 /**
mp-wp_genesis 417 * Permalink request structure for pages.
mp-wp_genesis 418 *
mp-wp_genesis 419 * @since 1.5.0
mp-wp_genesis 420 * @access private
mp-wp_genesis 421 * @var string
mp-wp_genesis 422 */
mp-wp_genesis 423 var $page_structure;
mp-wp_genesis 424
mp-wp_genesis 425 /**
mp-wp_genesis 426 * Search permalink base ( example.com/search/query ).
mp-wp_genesis 427 *
mp-wp_genesis 428 * @since 1.5.0
mp-wp_genesis 429 * @access private
mp-wp_genesis 430 * @var string
mp-wp_genesis 431 */
mp-wp_genesis 432 var $search_base = 'search';
mp-wp_genesis 433
mp-wp_genesis 434 /**
mp-wp_genesis 435 * Permalink request structure for searches.
mp-wp_genesis 436 *
mp-wp_genesis 437 * @since 1.5.0
mp-wp_genesis 438 * @access private
mp-wp_genesis 439 * @var string
mp-wp_genesis 440 */
mp-wp_genesis 441 var $search_structure;
mp-wp_genesis 442
mp-wp_genesis 443 /**
mp-wp_genesis 444 * Comments permalink base.
mp-wp_genesis 445 *
mp-wp_genesis 446 * @since 1.5.0
mp-wp_genesis 447 * @access private
mp-wp_genesis 448 * @var string
mp-wp_genesis 449 */
mp-wp_genesis 450 var $comments_base = 'comments';
mp-wp_genesis 451
mp-wp_genesis 452 /**
mp-wp_genesis 453 * Feed permalink base.
mp-wp_genesis 454 *
mp-wp_genesis 455 * @since 1.5.0
mp-wp_genesis 456 * @access private
mp-wp_genesis 457 * @var string
mp-wp_genesis 458 */
mp-wp_genesis 459 var $feed_base = 'feed';
mp-wp_genesis 460
mp-wp_genesis 461 /**
mp-wp_genesis 462 * Comments feed request structure permalink.
mp-wp_genesis 463 *
mp-wp_genesis 464 * @since 1.5.0
mp-wp_genesis 465 * @access private
mp-wp_genesis 466 * @var string
mp-wp_genesis 467 */
mp-wp_genesis 468 var $comments_feed_structure;
mp-wp_genesis 469
mp-wp_genesis 470 /**
mp-wp_genesis 471 * Feed request structure permalink.
mp-wp_genesis 472 *
mp-wp_genesis 473 * @since 1.5.0
mp-wp_genesis 474 * @access private
mp-wp_genesis 475 * @var string
mp-wp_genesis 476 */
mp-wp_genesis 477 var $feed_structure;
mp-wp_genesis 478
mp-wp_genesis 479 /**
mp-wp_genesis 480 * Front URL path.
mp-wp_genesis 481 *
mp-wp_genesis 482 * The difference between the root property is that WordPress might be
mp-wp_genesis 483 * located at example/WordPress/index.php, if permalinks are turned off. The
mp-wp_genesis 484 * WordPress/index.php will be the front portion. If permalinks are turned
mp-wp_genesis 485 * on, this will most likely be empty or not set.
mp-wp_genesis 486 *
mp-wp_genesis 487 * @since 1.5.0
mp-wp_genesis 488 * @access private
mp-wp_genesis 489 * @var string
mp-wp_genesis 490 */
mp-wp_genesis 491 var $front;
mp-wp_genesis 492
mp-wp_genesis 493 /**
mp-wp_genesis 494 * Root URL path to WordPress (without domain).
mp-wp_genesis 495 *
mp-wp_genesis 496 * The difference between front property is that WordPress might be located
mp-wp_genesis 497 * at example.com/WordPress/. The root is the 'WordPress/' portion.
mp-wp_genesis 498 *
mp-wp_genesis 499 * @since 1.5.0
mp-wp_genesis 500 * @access private
mp-wp_genesis 501 * @var string
mp-wp_genesis 502 */
mp-wp_genesis 503 var $root = '';
mp-wp_genesis 504
mp-wp_genesis 505 /**
mp-wp_genesis 506 * Permalink to the home page.
mp-wp_genesis 507 *
mp-wp_genesis 508 * @since 1.5.0
mp-wp_genesis 509 * @access public
mp-wp_genesis 510 * @var string
mp-wp_genesis 511 */
mp-wp_genesis 512 var $index = 'index.php';
mp-wp_genesis 513
mp-wp_genesis 514 /**
mp-wp_genesis 515 * Request match string.
mp-wp_genesis 516 *
mp-wp_genesis 517 * @since 1.5.0
mp-wp_genesis 518 * @access private
mp-wp_genesis 519 * @var string
mp-wp_genesis 520 */
mp-wp_genesis 521 var $matches = '';
mp-wp_genesis 522
mp-wp_genesis 523 /**
mp-wp_genesis 524 * Rewrite rules to match against the request to find the redirect or query.
mp-wp_genesis 525 *
mp-wp_genesis 526 * @since 1.5.0
mp-wp_genesis 527 * @access private
mp-wp_genesis 528 * @var array
mp-wp_genesis 529 */
mp-wp_genesis 530 var $rules;
mp-wp_genesis 531
mp-wp_genesis 532 /**
mp-wp_genesis 533 * Additional rules added external to the rewrite class.
mp-wp_genesis 534 *
mp-wp_genesis 535 * Those not generated by the class, see add_rewrite_rule().
mp-wp_genesis 536 *
mp-wp_genesis 537 * @since 2.1.0
mp-wp_genesis 538 * @access private
mp-wp_genesis 539 * @var array
mp-wp_genesis 540 */
mp-wp_genesis 541 var $extra_rules = array(); //
mp-wp_genesis 542
mp-wp_genesis 543 /**
mp-wp_genesis 544 * Additional rules that belong at the beginning to match first.
mp-wp_genesis 545 *
mp-wp_genesis 546 * Those not generated by the class, see add_rewrite_rule().
mp-wp_genesis 547 *
mp-wp_genesis 548 * @since 2.3.0
mp-wp_genesis 549 * @access private
mp-wp_genesis 550 * @var array
mp-wp_genesis 551 */
mp-wp_genesis 552 var $extra_rules_top = array(); //
mp-wp_genesis 553
mp-wp_genesis 554 /**
mp-wp_genesis 555 * Rules that don't redirect to WP's index.php.
mp-wp_genesis 556 *
mp-wp_genesis 557 * These rules are written to the mod_rewrite portion of the .htaccess.
mp-wp_genesis 558 *
mp-wp_genesis 559 * @since 2.1.0
mp-wp_genesis 560 * @access private
mp-wp_genesis 561 * @var array
mp-wp_genesis 562 */
mp-wp_genesis 563 var $non_wp_rules = array(); //
mp-wp_genesis 564
mp-wp_genesis 565 /**
mp-wp_genesis 566 * Extra permalink structures.
mp-wp_genesis 567 *
mp-wp_genesis 568 * @since 2.1.0
mp-wp_genesis 569 * @access private
mp-wp_genesis 570 * @var array
mp-wp_genesis 571 */
mp-wp_genesis 572 var $extra_permastructs = array();
mp-wp_genesis 573
mp-wp_genesis 574 /**
mp-wp_genesis 575 * Endpoints permalinks
mp-wp_genesis 576 *
mp-wp_genesis 577 * @since unknown
mp-wp_genesis 578 * @access private
mp-wp_genesis 579 * @var array
mp-wp_genesis 580 */
mp-wp_genesis 581 var $endpoints;
mp-wp_genesis 582
mp-wp_genesis 583 /**
mp-wp_genesis 584 * Whether to write every mod_rewrite rule for WordPress.
mp-wp_genesis 585 *
mp-wp_genesis 586 * This is off by default, turning it on might print a lot of rewrite rules
mp-wp_genesis 587 * to the .htaccess file.
mp-wp_genesis 588 *
mp-wp_genesis 589 * @since 2.0.0
mp-wp_genesis 590 * @access public
mp-wp_genesis 591 * @var bool
mp-wp_genesis 592 */
mp-wp_genesis 593 var $use_verbose_rules = false;
mp-wp_genesis 594
mp-wp_genesis 595 /**
mp-wp_genesis 596 * Whether to write every mod_rewrite rule for WordPress pages.
mp-wp_genesis 597 *
mp-wp_genesis 598 * @since 2.5.0
mp-wp_genesis 599 * @access public
mp-wp_genesis 600 * @var bool
mp-wp_genesis 601 */
mp-wp_genesis 602 var $use_verbose_page_rules = true;
mp-wp_genesis 603
mp-wp_genesis 604 /**
mp-wp_genesis 605 * Permalink structure search for preg_replace.
mp-wp_genesis 606 *
mp-wp_genesis 607 * @since 1.5.0
mp-wp_genesis 608 * @access private
mp-wp_genesis 609 * @var array
mp-wp_genesis 610 */
mp-wp_genesis 611 var $rewritecode =
mp-wp_genesis 612 array(
mp-wp_genesis 613 '%year%',
mp-wp_genesis 614 '%monthnum%',
mp-wp_genesis 615 '%day%',
mp-wp_genesis 616 '%hour%',
mp-wp_genesis 617 '%minute%',
mp-wp_genesis 618 '%second%',
mp-wp_genesis 619 '%postname%',
mp-wp_genesis 620 '%post_id%',
mp-wp_genesis 621 '%category%',
mp-wp_genesis 622 '%tag%',
mp-wp_genesis 623 '%author%',
mp-wp_genesis 624 '%pagename%',
mp-wp_genesis 625 '%search%'
mp-wp_genesis 626 );
mp-wp_genesis 627
mp-wp_genesis 628 /**
mp-wp_genesis 629 * Preg_replace values for the search, see {@link WP_Rewrite::$rewritecode}.
mp-wp_genesis 630 *
mp-wp_genesis 631 * @since 1.5.0
mp-wp_genesis 632 * @access private
mp-wp_genesis 633 * @var array
mp-wp_genesis 634 */
mp-wp_genesis 635 var $rewritereplace =
mp-wp_genesis 636 array(
mp-wp_genesis 637 '([0-9]{4})',
mp-wp_genesis 638 '([0-9]{1,2})',
mp-wp_genesis 639 '([0-9]{1,2})',
mp-wp_genesis 640 '([0-9]{1,2})',
mp-wp_genesis 641 '([0-9]{1,2})',
mp-wp_genesis 642 '([0-9]{1,2})',
mp-wp_genesis 643 '([^/]+)',
mp-wp_genesis 644 '([0-9]+)',
mp-wp_genesis 645 '(.+?)',
mp-wp_genesis 646 '(.+?)',
mp-wp_genesis 647 '([^/]+)',
mp-wp_genesis 648 '([^/]+?)',
mp-wp_genesis 649 '(.+)'
mp-wp_genesis 650 );
mp-wp_genesis 651
mp-wp_genesis 652 /**
mp-wp_genesis 653 * Search for the query to look for replacing.
mp-wp_genesis 654 *
mp-wp_genesis 655 * @since 1.5.0
mp-wp_genesis 656 * @access private
mp-wp_genesis 657 * @var array
mp-wp_genesis 658 */
mp-wp_genesis 659 var $queryreplace =
mp-wp_genesis 660 array (
mp-wp_genesis 661 'year=',
mp-wp_genesis 662 'monthnum=',
mp-wp_genesis 663 'day=',
mp-wp_genesis 664 'hour=',
mp-wp_genesis 665 'minute=',
mp-wp_genesis 666 'second=',
mp-wp_genesis 667 'name=',
mp-wp_genesis 668 'p=',
mp-wp_genesis 669 'category_name=',
mp-wp_genesis 670 'tag=',
mp-wp_genesis 671 'author_name=',
mp-wp_genesis 672 'pagename=',
mp-wp_genesis 673 's='
mp-wp_genesis 674 );
mp-wp_genesis 675
mp-wp_genesis 676 /**
mp-wp_genesis 677 * Supported default feeds.
mp-wp_genesis 678 *
mp-wp_genesis 679 * @since 1.5.0
mp-wp_genesis 680 * @access private
mp-wp_genesis 681 * @var array
mp-wp_genesis 682 */
mp-wp_genesis 683 var $feeds = array ( 'feed', 'rdf', 'rss', 'rss2', 'atom' );
mp-wp_genesis 684
mp-wp_genesis 685 /**
mp-wp_genesis 686 * Whether permalinks are being used.
mp-wp_genesis 687 *
mp-wp_genesis 688 * This can be either rewrite module or permalink in the HTTP query string.
mp-wp_genesis 689 *
mp-wp_genesis 690 * @since 1.5.0
mp-wp_genesis 691 * @access public
mp-wp_genesis 692 *
mp-wp_genesis 693 * @return bool True, if permalinks are enabled.
mp-wp_genesis 694 */
mp-wp_genesis 695 function using_permalinks() {
mp-wp_genesis 696 if (empty($this->permalink_structure))
mp-wp_genesis 697 return false;
mp-wp_genesis 698 else
mp-wp_genesis 699 return true;
mp-wp_genesis 700 }
mp-wp_genesis 701
mp-wp_genesis 702 /**
mp-wp_genesis 703 * Whether permalinks are being used and rewrite module is not enabled.
mp-wp_genesis 704 *
mp-wp_genesis 705 * Means that permalink links are enabled and index.php is in the URL.
mp-wp_genesis 706 *
mp-wp_genesis 707 * @since 1.5.0
mp-wp_genesis 708 * @access public
mp-wp_genesis 709 *
mp-wp_genesis 710 * @return bool
mp-wp_genesis 711 */
mp-wp_genesis 712 function using_index_permalinks() {
mp-wp_genesis 713 if (empty($this->permalink_structure)) {
mp-wp_genesis 714 return false;
mp-wp_genesis 715 }
mp-wp_genesis 716
mp-wp_genesis 717 // If the index is not in the permalink, we're using mod_rewrite.
mp-wp_genesis 718 if (preg_match('#^/*' . $this->index . '#', $this->permalink_structure)) {
mp-wp_genesis 719 return true;
mp-wp_genesis 720 }
mp-wp_genesis 721
mp-wp_genesis 722 return false;
mp-wp_genesis 723 }
mp-wp_genesis 724
mp-wp_genesis 725 /**
mp-wp_genesis 726 * Whether permalinks are being used and rewrite module is enabled.
mp-wp_genesis 727 *
mp-wp_genesis 728 * Using permalinks and index.php is not in the URL.
mp-wp_genesis 729 *
mp-wp_genesis 730 * @since 1.5.0
mp-wp_genesis 731 * @access public
mp-wp_genesis 732 *
mp-wp_genesis 733 * @return bool
mp-wp_genesis 734 */
mp-wp_genesis 735 function using_mod_rewrite_permalinks() {
mp-wp_genesis 736 if ( $this->using_permalinks() && ! $this->using_index_permalinks())
mp-wp_genesis 737 return true;
mp-wp_genesis 738 else
mp-wp_genesis 739 return false;
mp-wp_genesis 740 }
mp-wp_genesis 741
mp-wp_genesis 742 /**
mp-wp_genesis 743 * Index for matches for usage in preg_*() functions.
mp-wp_genesis 744 *
mp-wp_genesis 745 * The format of the string is, with empty matches property value, '$NUM'.
mp-wp_genesis 746 * The 'NUM' will be replaced with the value in the $number parameter. With
mp-wp_genesis 747 * the matches property not empty, the value of the returned string will
mp-wp_genesis 748 * contain that value of the matches property. The format then will be
mp-wp_genesis 749 * '$MATCHES[NUM]', with MATCHES as the value in the property and NUM the
mp-wp_genesis 750 * value of the $number parameter.
mp-wp_genesis 751 *
mp-wp_genesis 752 * @since 1.5.0
mp-wp_genesis 753 * @access public
mp-wp_genesis 754 *
mp-wp_genesis 755 * @param int $number Index number.
mp-wp_genesis 756 * @return string
mp-wp_genesis 757 */
mp-wp_genesis 758 function preg_index($number) {
mp-wp_genesis 759 $match_prefix = '$';
mp-wp_genesis 760 $match_suffix = '';
mp-wp_genesis 761
mp-wp_genesis 762 if ( ! empty($this->matches) ) {
mp-wp_genesis 763 $match_prefix = '$' . $this->matches . '[';
mp-wp_genesis 764 $match_suffix = ']';
mp-wp_genesis 765 }
mp-wp_genesis 766
mp-wp_genesis 767 return "$match_prefix$number$match_suffix";
mp-wp_genesis 768 }
mp-wp_genesis 769
mp-wp_genesis 770 /**
mp-wp_genesis 771 * Retrieve all page and attachments for pages URIs.
mp-wp_genesis 772 *
mp-wp_genesis 773 * The attachments are for those that have pages as parents and will be
mp-wp_genesis 774 * retrieved.
mp-wp_genesis 775 *
mp-wp_genesis 776 * @since 2.5.0
mp-wp_genesis 777 * @access public
mp-wp_genesis 778 *
mp-wp_genesis 779 * @return array Array of page URIs as first element and attachment URIs as second element.
mp-wp_genesis 780 */
mp-wp_genesis 781 function page_uri_index() {
mp-wp_genesis 782 global $wpdb;
mp-wp_genesis 783
mp-wp_genesis 784 //get pages in order of hierarchy, i.e. children after parents
mp-wp_genesis 785 $posts = get_page_hierarchy($wpdb->get_results("SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_type = 'page'"));
mp-wp_genesis 786 //now reverse it, because we need parents after children for rewrite rules to work properly
mp-wp_genesis 787 $posts = array_reverse($posts, true);
mp-wp_genesis 788
mp-wp_genesis 789 $page_uris = array();
mp-wp_genesis 790 $page_attachment_uris = array();
mp-wp_genesis 791
mp-wp_genesis 792 if ( !$posts )
mp-wp_genesis 793 return array( array(), array() );
mp-wp_genesis 794
mp-wp_genesis 795 foreach ($posts as $id => $post) {
mp-wp_genesis 796 // URL => page name
mp-wp_genesis 797 $uri = get_page_uri($id);
mp-wp_genesis 798 $attachments = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_type = 'attachment' AND post_parent = %d", $id ));
mp-wp_genesis 799 if ( $attachments ) {
mp-wp_genesis 800 foreach ( $attachments as $attachment ) {
mp-wp_genesis 801 $attach_uri = get_page_uri($attachment->ID);
mp-wp_genesis 802 $page_attachment_uris[$attach_uri] = $attachment->ID;
mp-wp_genesis 803 }
mp-wp_genesis 804 }
mp-wp_genesis 805
mp-wp_genesis 806 $page_uris[$uri] = $id;
mp-wp_genesis 807 }
mp-wp_genesis 808
mp-wp_genesis 809 return array( $page_uris, $page_attachment_uris );
mp-wp_genesis 810 }
mp-wp_genesis 811
mp-wp_genesis 812 /**
mp-wp_genesis 813 * Retrieve all of the rewrite rules for pages.
mp-wp_genesis 814 *
mp-wp_genesis 815 * If the 'use_verbose_page_rules' property is false, then there will only
mp-wp_genesis 816 * be a single rewrite rule for pages for those matching '%pagename%'. With
mp-wp_genesis 817 * the property set to true, the attachments and the pages will be added for
mp-wp_genesis 818 * each individual attachment URI and page URI, respectively.
mp-wp_genesis 819 *
mp-wp_genesis 820 * @since 1.5.0
mp-wp_genesis 821 * @access public
mp-wp_genesis 822 *
mp-wp_genesis 823 * @return array
mp-wp_genesis 824 */
mp-wp_genesis 825 function page_rewrite_rules() {
mp-wp_genesis 826 $rewrite_rules = array();
mp-wp_genesis 827 $page_structure = $this->get_page_permastruct();
mp-wp_genesis 828
mp-wp_genesis 829 if ( ! $this->use_verbose_page_rules ) {
mp-wp_genesis 830 $this->add_rewrite_tag('%pagename%', "(.+?)", 'pagename=');
mp-wp_genesis 831 $rewrite_rules = array_merge($rewrite_rules, $this->generate_rewrite_rules($page_structure, EP_PAGES));
mp-wp_genesis 832 return $rewrite_rules;
mp-wp_genesis 833 }
mp-wp_genesis 834
mp-wp_genesis 835 $page_uris = $this->page_uri_index();
mp-wp_genesis 836 $uris = $page_uris[0];
mp-wp_genesis 837 $attachment_uris = $page_uris[1];
mp-wp_genesis 838
mp-wp_genesis 839 if( is_array( $attachment_uris ) ) {
mp-wp_genesis 840 foreach ($attachment_uris as $uri => $pagename) {
mp-wp_genesis 841 $this->add_rewrite_tag('%pagename%', "($uri)", 'attachment=');
mp-wp_genesis 842 $rewrite_rules = array_merge($rewrite_rules, $this->generate_rewrite_rules($page_structure, EP_PAGES));
mp-wp_genesis 843 }
mp-wp_genesis 844 }
mp-wp_genesis 845 if( is_array( $uris ) ) {
mp-wp_genesis 846 foreach ($uris as $uri => $pagename) {
mp-wp_genesis 847 $this->add_rewrite_tag('%pagename%', "($uri)", 'pagename=');
mp-wp_genesis 848 $rewrite_rules = array_merge($rewrite_rules, $this->generate_rewrite_rules($page_structure, EP_PAGES));
mp-wp_genesis 849 }
mp-wp_genesis 850 }
mp-wp_genesis 851
mp-wp_genesis 852 return $rewrite_rules;
mp-wp_genesis 853 }
mp-wp_genesis 854
mp-wp_genesis 855 /**
mp-wp_genesis 856 * Retrieve date permalink structure, with year, month, and day.
mp-wp_genesis 857 *
mp-wp_genesis 858 * The permalink structure for the date, if not set already depends on the
mp-wp_genesis 859 * permalink structure. It can be one of three formats. The first is year,
mp-wp_genesis 860 * month, day; the second is day, month, year; and the last format is month,
mp-wp_genesis 861 * day, year. These are matched against the permalink structure for which
mp-wp_genesis 862 * one is used. If none matches, then the default will be used, which is
mp-wp_genesis 863 * year, month, day.
mp-wp_genesis 864 *
mp-wp_genesis 865 * Prevents post ID and date permalinks from overlapping. In the case of
mp-wp_genesis 866 * post_id, the date permalink will be prepended with front permalink with
mp-wp_genesis 867 * 'date/' before the actual permalink to form the complete date permalink
mp-wp_genesis 868 * structure.
mp-wp_genesis 869 *
mp-wp_genesis 870 * @since 1.5.0
mp-wp_genesis 871 * @access public
mp-wp_genesis 872 *
mp-wp_genesis 873 * @return bool|string False on no permalink structure. Date permalink structure.
mp-wp_genesis 874 */
mp-wp_genesis 875 function get_date_permastruct() {
mp-wp_genesis 876 if (isset($this->date_structure)) {
mp-wp_genesis 877 return $this->date_structure;
mp-wp_genesis 878 }
mp-wp_genesis 879
mp-wp_genesis 880 if (empty($this->permalink_structure)) {
mp-wp_genesis 881 $this->date_structure = '';
mp-wp_genesis 882 return false;
mp-wp_genesis 883 }
mp-wp_genesis 884
mp-wp_genesis 885 // The date permalink must have year, month, and day separated by slashes.
mp-wp_genesis 886 $endians = array('%year%/%monthnum%/%day%', '%day%/%monthnum%/%year%', '%monthnum%/%day%/%year%');
mp-wp_genesis 887
mp-wp_genesis 888 $this->date_structure = '';
mp-wp_genesis 889 $date_endian = '';
mp-wp_genesis 890
mp-wp_genesis 891 foreach ($endians as $endian) {
mp-wp_genesis 892 if (false !== strpos($this->permalink_structure, $endian)) {
mp-wp_genesis 893 $date_endian= $endian;
mp-wp_genesis 894 break;
mp-wp_genesis 895 }
mp-wp_genesis 896 }
mp-wp_genesis 897
mp-wp_genesis 898 if ( empty($date_endian) )
mp-wp_genesis 899 $date_endian = '%year%/%monthnum%/%day%';
mp-wp_genesis 900
mp-wp_genesis 901 // Do not allow the date tags and %post_id% to overlap in the permalink
mp-wp_genesis 902 // structure. If they do, move the date tags to $front/date/.
mp-wp_genesis 903 $front = $this->front;
mp-wp_genesis 904 preg_match_all('/%.+?%/', $this->permalink_structure, $tokens);
mp-wp_genesis 905 $tok_index = 1;
mp-wp_genesis 906 foreach ( (array) $tokens[0] as $token) {
mp-wp_genesis 907 if ( ($token == '%post_id%') && ($tok_index <= 3) ) {
mp-wp_genesis 908 $front = $front . 'date/';
mp-wp_genesis 909 break;
mp-wp_genesis 910 }
mp-wp_genesis 911 $tok_index++;
mp-wp_genesis 912 }
mp-wp_genesis 913
mp-wp_genesis 914 $this->date_structure = $front . $date_endian;
mp-wp_genesis 915
mp-wp_genesis 916 return $this->date_structure;
mp-wp_genesis 917 }
mp-wp_genesis 918
mp-wp_genesis 919 /**
mp-wp_genesis 920 * Retrieve the year permalink structure without month and day.
mp-wp_genesis 921 *
mp-wp_genesis 922 * Gets the date permalink structure and strips out the month and day
mp-wp_genesis 923 * permalink structures.
mp-wp_genesis 924 *
mp-wp_genesis 925 * @since 1.5.0
mp-wp_genesis 926 * @access public
mp-wp_genesis 927 *
mp-wp_genesis 928 * @return bool|string False on failure. Year structure on success.
mp-wp_genesis 929 */
mp-wp_genesis 930 function get_year_permastruct() {
mp-wp_genesis 931 $structure = $this->get_date_permastruct($this->permalink_structure);
mp-wp_genesis 932
mp-wp_genesis 933 if (empty($structure)) {
mp-wp_genesis 934 return false;
mp-wp_genesis 935 }
mp-wp_genesis 936
mp-wp_genesis 937 $structure = str_replace('%monthnum%', '', $structure);
mp-wp_genesis 938 $structure = str_replace('%day%', '', $structure);
mp-wp_genesis 939
mp-wp_genesis 940 $structure = preg_replace('#/+#', '/', $structure);
mp-wp_genesis 941
mp-wp_genesis 942 return $structure;
mp-wp_genesis 943 }
mp-wp_genesis 944
mp-wp_genesis 945 /**
mp-wp_genesis 946 * Retrieve the month permalink structure without day and with year.
mp-wp_genesis 947 *
mp-wp_genesis 948 * Gets the date permalink structure and strips out the day permalink
mp-wp_genesis 949 * structures. Keeps the year permalink structure.
mp-wp_genesis 950 *
mp-wp_genesis 951 * @since 1.5.0
mp-wp_genesis 952 * @access public
mp-wp_genesis 953 *
mp-wp_genesis 954 * @return bool|string False on failure. Year/Month structure on success.
mp-wp_genesis 955 */
mp-wp_genesis 956 function get_month_permastruct() {
mp-wp_genesis 957 $structure = $this->get_date_permastruct($this->permalink_structure);
mp-wp_genesis 958
mp-wp_genesis 959 if (empty($structure)) {
mp-wp_genesis 960 return false;
mp-wp_genesis 961 }
mp-wp_genesis 962
mp-wp_genesis 963 $structure = str_replace('%day%', '', $structure);
mp-wp_genesis 964
mp-wp_genesis 965 $structure = preg_replace('#/+#', '/', $structure);
mp-wp_genesis 966
mp-wp_genesis 967 return $structure;
mp-wp_genesis 968 }
mp-wp_genesis 969
mp-wp_genesis 970 /**
mp-wp_genesis 971 * Retrieve the day permalink structure with month and year.
mp-wp_genesis 972 *
mp-wp_genesis 973 * Keeps date permalink structure with all year, month, and day.
mp-wp_genesis 974 *
mp-wp_genesis 975 * @since 1.5.0
mp-wp_genesis 976 * @access public
mp-wp_genesis 977 *
mp-wp_genesis 978 * @return bool|string False on failure. Year/Month/Day structure on success.
mp-wp_genesis 979 */
mp-wp_genesis 980 function get_day_permastruct() {
mp-wp_genesis 981 return $this->get_date_permastruct($this->permalink_structure);
mp-wp_genesis 982 }
mp-wp_genesis 983
mp-wp_genesis 984 /**
mp-wp_genesis 985 * Retrieve the permalink structure for categories.
mp-wp_genesis 986 *
mp-wp_genesis 987 * If the category_base property has no value, then the category structure
mp-wp_genesis 988 * will have the front property value, followed by 'category', and finally
mp-wp_genesis 989 * '%category%'. If it does, then the root property will be used, along with
mp-wp_genesis 990 * the category_base property value.
mp-wp_genesis 991 *
mp-wp_genesis 992 * @since 1.5.0
mp-wp_genesis 993 * @access public
mp-wp_genesis 994 *
mp-wp_genesis 995 * @return bool|string False on failure. Category permalink structure.
mp-wp_genesis 996 */
mp-wp_genesis 997 function get_category_permastruct() {
mp-wp_genesis 998 if (isset($this->category_structure)) {
mp-wp_genesis 999 return $this->category_structure;
mp-wp_genesis 1000 }
mp-wp_genesis 1001
mp-wp_genesis 1002 if (empty($this->permalink_structure)) {
mp-wp_genesis 1003 $this->category_structure = '';
mp-wp_genesis 1004 return false;
mp-wp_genesis 1005 }
mp-wp_genesis 1006
mp-wp_genesis 1007 if (empty($this->category_base))
mp-wp_genesis 1008 $this->category_structure = trailingslashit( $this->front . 'category' );
mp-wp_genesis 1009 else
mp-wp_genesis 1010 $this->category_structure = trailingslashit( '/' . $this->root . $this->category_base );
mp-wp_genesis 1011
mp-wp_genesis 1012 $this->category_structure .= '%category%';
mp-wp_genesis 1013
mp-wp_genesis 1014 return $this->category_structure;
mp-wp_genesis 1015 }
mp-wp_genesis 1016
mp-wp_genesis 1017 /**
mp-wp_genesis 1018 * Retrieve the permalink structure for tags.
mp-wp_genesis 1019 *
mp-wp_genesis 1020 * If the tag_base property has no value, then the tag structure will have
mp-wp_genesis 1021 * the front property value, followed by 'tag', and finally '%tag%'. If it
mp-wp_genesis 1022 * does, then the root property will be used, along with the tag_base
mp-wp_genesis 1023 * property value.
mp-wp_genesis 1024 *
mp-wp_genesis 1025 * @since 2.3.0
mp-wp_genesis 1026 * @access public
mp-wp_genesis 1027 *
mp-wp_genesis 1028 * @return bool|string False on failure. Tag permalink structure.
mp-wp_genesis 1029 */
mp-wp_genesis 1030 function get_tag_permastruct() {
mp-wp_genesis 1031 if (isset($this->tag_structure)) {
mp-wp_genesis 1032 return $this->tag_structure;
mp-wp_genesis 1033 }
mp-wp_genesis 1034
mp-wp_genesis 1035 if (empty($this->permalink_structure)) {
mp-wp_genesis 1036 $this->tag_structure = '';
mp-wp_genesis 1037 return false;
mp-wp_genesis 1038 }
mp-wp_genesis 1039
mp-wp_genesis 1040 if (empty($this->tag_base))
mp-wp_genesis 1041 $this->tag_structure = trailingslashit( $this->front . 'tag' );
mp-wp_genesis 1042 else
mp-wp_genesis 1043 $this->tag_structure = trailingslashit( '/' . $this->root . $this->tag_base );
mp-wp_genesis 1044
mp-wp_genesis 1045 $this->tag_structure .= '%tag%';
mp-wp_genesis 1046
mp-wp_genesis 1047 return $this->tag_structure;
mp-wp_genesis 1048 }
mp-wp_genesis 1049
mp-wp_genesis 1050 /**
mp-wp_genesis 1051 * Retrieve extra permalink structure by name.
mp-wp_genesis 1052 *
mp-wp_genesis 1053 * @since unknown
mp-wp_genesis 1054 * @access public
mp-wp_genesis 1055 *
mp-wp_genesis 1056 * @param string $name Permalink structure name.
mp-wp_genesis 1057 * @return string|bool False if not found. Permalink structure string.
mp-wp_genesis 1058 */
mp-wp_genesis 1059 function get_extra_permastruct($name) {
mp-wp_genesis 1060 if ( isset($this->extra_permastructs[$name]) )
mp-wp_genesis 1061 return $this->extra_permastructs[$name];
mp-wp_genesis 1062 return false;
mp-wp_genesis 1063 }
mp-wp_genesis 1064
mp-wp_genesis 1065 /**
mp-wp_genesis 1066 * Retrieve the author permalink structure.
mp-wp_genesis 1067 *
mp-wp_genesis 1068 * The permalink structure is front property, author base, and finally
mp-wp_genesis 1069 * '/%author%'. Will set the author_structure property and then return it
mp-wp_genesis 1070 * without attempting to set the value again.
mp-wp_genesis 1071 *
mp-wp_genesis 1072 * @since 1.5.0
mp-wp_genesis 1073 * @access public
mp-wp_genesis 1074 *
mp-wp_genesis 1075 * @return string|bool False if not found. Permalink structure string.
mp-wp_genesis 1076 */
mp-wp_genesis 1077 function get_author_permastruct() {
mp-wp_genesis 1078 if (isset($this->author_structure)) {
mp-wp_genesis 1079 return $this->author_structure;
mp-wp_genesis 1080 }
mp-wp_genesis 1081
mp-wp_genesis 1082 if (empty($this->permalink_structure)) {
mp-wp_genesis 1083 $this->author_structure = '';
mp-wp_genesis 1084 return false;
mp-wp_genesis 1085 }
mp-wp_genesis 1086
mp-wp_genesis 1087 $this->author_structure = $this->front . $this->author_base . '/%author%';
mp-wp_genesis 1088
mp-wp_genesis 1089 return $this->author_structure;
mp-wp_genesis 1090 }
mp-wp_genesis 1091
mp-wp_genesis 1092 /**
mp-wp_genesis 1093 * Retrieve the search permalink structure.
mp-wp_genesis 1094 *
mp-wp_genesis 1095 * The permalink structure is root property, search base, and finally
mp-wp_genesis 1096 * '/%search%'. Will set the search_structure property and then return it
mp-wp_genesis 1097 * without attempting to set the value again.
mp-wp_genesis 1098 *
mp-wp_genesis 1099 * @since 1.5.0
mp-wp_genesis 1100 * @access public
mp-wp_genesis 1101 *
mp-wp_genesis 1102 * @return string|bool False if not found. Permalink structure string.
mp-wp_genesis 1103 */
mp-wp_genesis 1104 function get_search_permastruct() {
mp-wp_genesis 1105 if (isset($this->search_structure)) {
mp-wp_genesis 1106 return $this->search_structure;
mp-wp_genesis 1107 }
mp-wp_genesis 1108
mp-wp_genesis 1109 if (empty($this->permalink_structure)) {
mp-wp_genesis 1110 $this->search_structure = '';
mp-wp_genesis 1111 return false;
mp-wp_genesis 1112 }
mp-wp_genesis 1113
mp-wp_genesis 1114 $this->search_structure = $this->root . $this->search_base . '/%search%';
mp-wp_genesis 1115
mp-wp_genesis 1116 return $this->search_structure;
mp-wp_genesis 1117 }
mp-wp_genesis 1118
mp-wp_genesis 1119 /**
mp-wp_genesis 1120 * Retrieve the page permalink structure.
mp-wp_genesis 1121 *
mp-wp_genesis 1122 * The permalink structure is root property, and '%pagename%'. Will set the
mp-wp_genesis 1123 * page_structure property and then return it without attempting to set the
mp-wp_genesis 1124 * value again.
mp-wp_genesis 1125 *
mp-wp_genesis 1126 * @since 1.5.0
mp-wp_genesis 1127 * @access public
mp-wp_genesis 1128 *
mp-wp_genesis 1129 * @return string|bool False if not found. Permalink structure string.
mp-wp_genesis 1130 */
mp-wp_genesis 1131 function get_page_permastruct() {
mp-wp_genesis 1132 if (isset($this->page_structure)) {
mp-wp_genesis 1133 return $this->page_structure;
mp-wp_genesis 1134 }
mp-wp_genesis 1135
mp-wp_genesis 1136 if (empty($this->permalink_structure)) {
mp-wp_genesis 1137 $this->page_structure = '';
mp-wp_genesis 1138 return false;
mp-wp_genesis 1139 }
mp-wp_genesis 1140
mp-wp_genesis 1141 $this->page_structure = $this->root . '%pagename%';
mp-wp_genesis 1142
mp-wp_genesis 1143 return $this->page_structure;
mp-wp_genesis 1144 }
mp-wp_genesis 1145
mp-wp_genesis 1146 /**
mp-wp_genesis 1147 * Retrieve the feed permalink structure.
mp-wp_genesis 1148 *
mp-wp_genesis 1149 * The permalink structure is root property, feed base, and finally
mp-wp_genesis 1150 * '/%feed%'. Will set the feed_structure property and then return it
mp-wp_genesis 1151 * without attempting to set the value again.
mp-wp_genesis 1152 *
mp-wp_genesis 1153 * @since 1.5.0
mp-wp_genesis 1154 * @access public
mp-wp_genesis 1155 *
mp-wp_genesis 1156 * @return string|bool False if not found. Permalink structure string.
mp-wp_genesis 1157 */
mp-wp_genesis 1158 function get_feed_permastruct() {
mp-wp_genesis 1159 if (isset($this->feed_structure)) {
mp-wp_genesis 1160 return $this->feed_structure;
mp-wp_genesis 1161 }
mp-wp_genesis 1162
mp-wp_genesis 1163 if (empty($this->permalink_structure)) {
mp-wp_genesis 1164 $this->feed_structure = '';
mp-wp_genesis 1165 return false;
mp-wp_genesis 1166 }
mp-wp_genesis 1167
mp-wp_genesis 1168 $this->feed_structure = $this->root . $this->feed_base . '/%feed%';
mp-wp_genesis 1169
mp-wp_genesis 1170 return $this->feed_structure;
mp-wp_genesis 1171 }
mp-wp_genesis 1172
mp-wp_genesis 1173 /**
mp-wp_genesis 1174 * Retrieve the comment feed permalink structure.
mp-wp_genesis 1175 *
mp-wp_genesis 1176 * The permalink structure is root property, comment base property, feed
mp-wp_genesis 1177 * base and finally '/%feed%'. Will set the comment_feed_structure property
mp-wp_genesis 1178 * and then return it without attempting to set the value again.
mp-wp_genesis 1179 *
mp-wp_genesis 1180 * @since 1.5.0
mp-wp_genesis 1181 * @access public
mp-wp_genesis 1182 *
mp-wp_genesis 1183 * @return string|bool False if not found. Permalink structure string.
mp-wp_genesis 1184 */
mp-wp_genesis 1185 function get_comment_feed_permastruct() {
mp-wp_genesis 1186 if (isset($this->comment_feed_structure)) {
mp-wp_genesis 1187 return $this->comment_feed_structure;
mp-wp_genesis 1188 }
mp-wp_genesis 1189
mp-wp_genesis 1190 if (empty($this->permalink_structure)) {
mp-wp_genesis 1191 $this->comment_feed_structure = '';
mp-wp_genesis 1192 return false;
mp-wp_genesis 1193 }
mp-wp_genesis 1194
mp-wp_genesis 1195 $this->comment_feed_structure = $this->root . $this->comments_base . '/' . $this->feed_base . '/%feed%';
mp-wp_genesis 1196
mp-wp_genesis 1197 return $this->comment_feed_structure;
mp-wp_genesis 1198 }
mp-wp_genesis 1199
mp-wp_genesis 1200 /**
mp-wp_genesis 1201 * Append or update tag, pattern, and query for replacement.
mp-wp_genesis 1202 *
mp-wp_genesis 1203 * If the tag already exists, replace the existing pattern and query for
mp-wp_genesis 1204 * that tag, otherwise add the new tag, pattern, and query to the end of the
mp-wp_genesis 1205 * arrays.
mp-wp_genesis 1206 *
mp-wp_genesis 1207 * @internal What is the purpose of this function again? Need to finish long
mp-wp_genesis 1208 * description.
mp-wp_genesis 1209 *
mp-wp_genesis 1210 * @since 1.5.0
mp-wp_genesis 1211 * @access public
mp-wp_genesis 1212 *
mp-wp_genesis 1213 * @param string $tag Append tag to rewritecode property array.
mp-wp_genesis 1214 * @param string $pattern Append pattern to rewritereplace property array.
mp-wp_genesis 1215 * @param string $query Append query to queryreplace property array.
mp-wp_genesis 1216 */
mp-wp_genesis 1217 function add_rewrite_tag($tag, $pattern, $query) {
mp-wp_genesis 1218 $position = array_search($tag, $this->rewritecode);
mp-wp_genesis 1219 if ( false !== $position && null !== $position ) {
mp-wp_genesis 1220 $this->rewritereplace[$position] = $pattern;
mp-wp_genesis 1221 $this->queryreplace[$position] = $query;
mp-wp_genesis 1222 } else {
mp-wp_genesis 1223 $this->rewritecode[] = $tag;
mp-wp_genesis 1224 $this->rewritereplace[] = $pattern;
mp-wp_genesis 1225 $this->queryreplace[] = $query;
mp-wp_genesis 1226 }
mp-wp_genesis 1227 }
mp-wp_genesis 1228
mp-wp_genesis 1229 /**
mp-wp_genesis 1230 * Generate the rules from permalink structure.
mp-wp_genesis 1231 *
mp-wp_genesis 1232 * The main WP_Rewrite function for building the rewrite rule list. The
mp-wp_genesis 1233 * contents of the function is a mix of black magic and regular expressions,
mp-wp_genesis 1234 * so best just ignore the contents and move to the parameters.
mp-wp_genesis 1235 *
mp-wp_genesis 1236 * @since 1.5.0
mp-wp_genesis 1237 * @access public
mp-wp_genesis 1238 *
mp-wp_genesis 1239 * @param string $permalink_structure The permalink structure.
mp-wp_genesis 1240 * @param int $ep_mask Optional, default is EP_NONE. Endpoint constant, see EP_* constants.
mp-wp_genesis 1241 * @param bool $paged Optional, default is true. Whether permalink request is paged.
mp-wp_genesis 1242 * @param bool $feed Optional, default is true. Whether for feed.
mp-wp_genesis 1243 * @param bool $forcomments Optional, default is false. Whether for comments.
mp-wp_genesis 1244 * @param bool $walk_dirs Optional, default is true. Whether to create list of directories to walk over.
mp-wp_genesis 1245 * @param bool $endpoints Optional, default is true. Whether endpoints are enabled.
mp-wp_genesis 1246 * @return array Rewrite rule list.
mp-wp_genesis 1247 */
mp-wp_genesis 1248 function generate_rewrite_rules($permalink_structure, $ep_mask = EP_NONE, $paged = true, $feed = true, $forcomments = false, $walk_dirs = true, $endpoints = true) {
mp-wp_genesis 1249 //build a regex to match the feed section of URLs, something like (feed|atom|rss|rss2)/?
mp-wp_genesis 1250 $feedregex2 = '';
mp-wp_genesis 1251 foreach ( (array) $this->feeds as $feed_name) {
mp-wp_genesis 1252 $feedregex2 .= $feed_name . '|';
mp-wp_genesis 1253 }
mp-wp_genesis 1254 $feedregex2 = '(' . trim($feedregex2, '|') . ')/?$';
mp-wp_genesis 1255 //$feedregex is identical but with /feed/ added on as well, so URLs like <permalink>/feed/atom
mp-wp_genesis 1256 //and <permalink>/atom are both possible
mp-wp_genesis 1257 $feedregex = $this->feed_base . '/' . $feedregex2;
mp-wp_genesis 1258
mp-wp_genesis 1259 //build a regex to match the trackback and page/xx parts of URLs
mp-wp_genesis 1260 $trackbackregex = 'trackback/?$';
mp-wp_genesis 1261 $pageregex = 'page/?([0-9]{1,})/?$';
mp-wp_genesis 1262 $commentregex = 'comment-page-([0-9]{1,})/?$';
mp-wp_genesis 1263
mp-wp_genesis 1264 //build up an array of endpoint regexes to append => queries to append
mp-wp_genesis 1265 if ($endpoints) {
mp-wp_genesis 1266 $ep_query_append = array ();
mp-wp_genesis 1267 foreach ( (array) $this->endpoints as $endpoint) {
mp-wp_genesis 1268 //match everything after the endpoint name, but allow for nothing to appear there
mp-wp_genesis 1269 $epmatch = $endpoint[1] . '(/(.*))?/?$';
mp-wp_genesis 1270 //this will be appended on to the rest of the query for each dir
mp-wp_genesis 1271 $epquery = '&' . $endpoint[1] . '=';
mp-wp_genesis 1272 $ep_query_append[$epmatch] = array ( $endpoint[0], $epquery );
mp-wp_genesis 1273 }
mp-wp_genesis 1274 }
mp-wp_genesis 1275
mp-wp_genesis 1276 //get everything up to the first rewrite tag
mp-wp_genesis 1277 $front = substr($permalink_structure, 0, strpos($permalink_structure, '%'));
mp-wp_genesis 1278 //build an array of the tags (note that said array ends up being in $tokens[0])
mp-wp_genesis 1279 preg_match_all('/%.+?%/', $permalink_structure, $tokens);
mp-wp_genesis 1280
mp-wp_genesis 1281 $num_tokens = count($tokens[0]);
mp-wp_genesis 1282
mp-wp_genesis 1283 $index = $this->index; //probably 'index.php'
mp-wp_genesis 1284 $feedindex = $index;
mp-wp_genesis 1285 $trackbackindex = $index;
mp-wp_genesis 1286 //build a list from the rewritecode and queryreplace arrays, that will look something like
mp-wp_genesis 1287 //tagname=$matches[i] where i is the current $i
mp-wp_genesis 1288 for ($i = 0; $i < $num_tokens; ++$i) {
mp-wp_genesis 1289 if (0 < $i) {
mp-wp_genesis 1290 $queries[$i] = $queries[$i - 1] . '&';
mp-wp_genesis 1291 } else {
mp-wp_genesis 1292 $queries[$i] = '';
mp-wp_genesis 1293 }
mp-wp_genesis 1294
mp-wp_genesis 1295 $query_token = str_replace($this->rewritecode, $this->queryreplace, $tokens[0][$i]) . $this->preg_index($i+1);
mp-wp_genesis 1296 $queries[$i] .= $query_token;
mp-wp_genesis 1297 }
mp-wp_genesis 1298
mp-wp_genesis 1299 //get the structure, minus any cruft (stuff that isn't tags) at the front
mp-wp_genesis 1300 $structure = $permalink_structure;
mp-wp_genesis 1301 if ($front != '/') {
mp-wp_genesis 1302 $structure = str_replace($front, '', $structure);
mp-wp_genesis 1303 }
mp-wp_genesis 1304 //create a list of dirs to walk over, making rewrite rules for each level
mp-wp_genesis 1305 //so for example, a $structure of /%year%/%month%/%postname% would create
mp-wp_genesis 1306 //rewrite rules for /%year%/, /%year%/%month%/ and /%year%/%month%/%postname%
mp-wp_genesis 1307 $structure = trim($structure, '/');
mp-wp_genesis 1308 if ($walk_dirs) {
mp-wp_genesis 1309 $dirs = explode('/', $structure);
mp-wp_genesis 1310 } else {
mp-wp_genesis 1311 $dirs[] = $structure;
mp-wp_genesis 1312 }
mp-wp_genesis 1313 $num_dirs = count($dirs);
mp-wp_genesis 1314
mp-wp_genesis 1315 //strip slashes from the front of $front
mp-wp_genesis 1316 $front = preg_replace('|^/+|', '', $front);
mp-wp_genesis 1317
mp-wp_genesis 1318 //the main workhorse loop
mp-wp_genesis 1319 $post_rewrite = array();
mp-wp_genesis 1320 $struct = $front;
mp-wp_genesis 1321 for ($j = 0; $j < $num_dirs; ++$j) {
mp-wp_genesis 1322 //get the struct for this dir, and trim slashes off the front
mp-wp_genesis 1323 $struct .= $dirs[$j] . '/'; //accumulate. see comment near explode('/', $structure) above
mp-wp_genesis 1324 $struct = ltrim($struct, '/');
mp-wp_genesis 1325 //replace tags with regexes
mp-wp_genesis 1326 $match = str_replace($this->rewritecode, $this->rewritereplace, $struct);
mp-wp_genesis 1327 //make a list of tags, and store how many there are in $num_toks
mp-wp_genesis 1328 $num_toks = preg_match_all('/%.+?%/', $struct, $toks);
mp-wp_genesis 1329 //get the 'tagname=$matches[i]'
mp-wp_genesis 1330 $query = ( isset($queries) && is_array($queries) ) ? $queries[$num_toks - 1] : '';
mp-wp_genesis 1331
mp-wp_genesis 1332 //set up $ep_mask_specific which is used to match more specific URL types
mp-wp_genesis 1333 switch ($dirs[$j]) {
mp-wp_genesis 1334 case '%year%': $ep_mask_specific = EP_YEAR; break;
mp-wp_genesis 1335 case '%monthnum%': $ep_mask_specific = EP_MONTH; break;
mp-wp_genesis 1336 case '%day%': $ep_mask_specific = EP_DAY; break;
mp-wp_genesis 1337 }
mp-wp_genesis 1338
mp-wp_genesis 1339 //create query for /page/xx
mp-wp_genesis 1340 $pagematch = $match . $pageregex;
mp-wp_genesis 1341 $pagequery = $index . '?' . $query . '&paged=' . $this->preg_index($num_toks + 1);
mp-wp_genesis 1342
mp-wp_genesis 1343 //create query for /comment-page-xx
mp-wp_genesis 1344 $commentmatch = $match . $commentregex;
mp-wp_genesis 1345 $commentquery = $index . '?' . $query . '&cpage=' . $this->preg_index($num_toks + 1);
mp-wp_genesis 1346
mp-wp_genesis 1347 //create query for /feed/(feed|atom|rss|rss2|rdf)
mp-wp_genesis 1348 $feedmatch = $match . $feedregex;
mp-wp_genesis 1349 $feedquery = $feedindex . '?' . $query . '&feed=' . $this->preg_index($num_toks + 1);
mp-wp_genesis 1350
mp-wp_genesis 1351 //create query for /(feed|atom|rss|rss2|rdf) (see comment near creation of $feedregex)
mp-wp_genesis 1352 $feedmatch2 = $match . $feedregex2;
mp-wp_genesis 1353 $feedquery2 = $feedindex . '?' . $query . '&feed=' . $this->preg_index($num_toks + 1);
mp-wp_genesis 1354
mp-wp_genesis 1355 //if asked to, turn the feed queries into comment feed ones
mp-wp_genesis 1356 if ($forcomments) {
mp-wp_genesis 1357 $feedquery .= '&withcomments=1';
mp-wp_genesis 1358 $feedquery2 .= '&withcomments=1';
mp-wp_genesis 1359 }
mp-wp_genesis 1360
mp-wp_genesis 1361 //start creating the array of rewrites for this dir
mp-wp_genesis 1362 $rewrite = array();
mp-wp_genesis 1363 if ($feed) //...adding on /feed/ regexes => queries
mp-wp_genesis 1364 $rewrite = array($feedmatch => $feedquery, $feedmatch2 => $feedquery2);
mp-wp_genesis 1365 if ($paged) //...and /page/xx ones
mp-wp_genesis 1366 $rewrite = array_merge($rewrite, array($pagematch => $pagequery));
mp-wp_genesis 1367
mp-wp_genesis 1368 //only on pages with comments add ../comment-page-xx/
mp-wp_genesis 1369 if ( EP_PAGES & $ep_mask || EP_PERMALINK & $ep_mask || EP_NONE & $ep_mask )
mp-wp_genesis 1370 $rewrite = array_merge($rewrite, array($commentmatch => $commentquery));
mp-wp_genesis 1371
mp-wp_genesis 1372 //do endpoints
mp-wp_genesis 1373 if ($endpoints) {
mp-wp_genesis 1374 foreach ( (array) $ep_query_append as $regex => $ep) {
mp-wp_genesis 1375 //add the endpoints on if the mask fits
mp-wp_genesis 1376 if ($ep[0] & $ep_mask || $ep[0] & $ep_mask_specific) {
mp-wp_genesis 1377 $rewrite[$match . $regex] = $index . '?' . $query . $ep[1] . $this->preg_index($num_toks + 2);
mp-wp_genesis 1378 }
mp-wp_genesis 1379 }
mp-wp_genesis 1380 }
mp-wp_genesis 1381
mp-wp_genesis 1382 //if we've got some tags in this dir
mp-wp_genesis 1383 if ($num_toks) {
mp-wp_genesis 1384 $post = false;
mp-wp_genesis 1385 $page = false;
mp-wp_genesis 1386
mp-wp_genesis 1387 //check to see if this dir is permalink-level: i.e. the structure specifies an
mp-wp_genesis 1388 //individual post. Do this by checking it contains at least one of 1) post name,
mp-wp_genesis 1389 //2) post ID, 3) page name, 4) timestamp (year, month, day, hour, second and
mp-wp_genesis 1390 //minute all present). Set these flags now as we need them for the endpoints.
mp-wp_genesis 1391 if (strpos($struct, '%postname%') !== false || strpos($struct, '%post_id%') !== false
mp-wp_genesis 1392 || strpos($struct, '%pagename%') !== false
mp-wp_genesis 1393 || (strpos($struct, '%year%') !== false && strpos($struct, '%monthnum%') !== false && strpos($struct, '%day%') !== false && strpos($struct, '%hour%') !== false && strpos($struct, '%minute%') !== false && strpos($struct, '%second%') !== false)) {
mp-wp_genesis 1394 $post = true;
mp-wp_genesis 1395 if (strpos($struct, '%pagename%') !== false)
mp-wp_genesis 1396 $page = true;
mp-wp_genesis 1397 }
mp-wp_genesis 1398
mp-wp_genesis 1399 //if we're creating rules for a permalink, do all the endpoints like attachments etc
mp-wp_genesis 1400 if ($post) {
mp-wp_genesis 1401 $post = true;
mp-wp_genesis 1402 //create query and regex for trackback
mp-wp_genesis 1403 $trackbackmatch = $match . $trackbackregex;
mp-wp_genesis 1404 $trackbackquery = $trackbackindex . '?' . $query . '&tb=1';
mp-wp_genesis 1405 //trim slashes from the end of the regex for this dir
mp-wp_genesis 1406 $match = rtrim($match, '/');
mp-wp_genesis 1407 //get rid of brackets
mp-wp_genesis 1408 $submatchbase = str_replace(array('(',')'),'',$match);
mp-wp_genesis 1409
mp-wp_genesis 1410 //add a rule for at attachments, which take the form of <permalink>/some-text
mp-wp_genesis 1411 $sub1 = $submatchbase . '/([^/]+)/';
mp-wp_genesis 1412 $sub1tb = $sub1 . $trackbackregex; //add trackback regex <permalink>/trackback/...
mp-wp_genesis 1413 $sub1feed = $sub1 . $feedregex; //and <permalink>/feed/(atom|...)
mp-wp_genesis 1414 $sub1feed2 = $sub1 . $feedregex2; //and <permalink>/(feed|atom...)
mp-wp_genesis 1415 $sub1comment = $sub1 . $commentregex; //and <permalink>/comment-page-xx
mp-wp_genesis 1416 //add an ? as we don't have to match that last slash, and finally a $ so we
mp-wp_genesis 1417 //match to the end of the URL
mp-wp_genesis 1418
mp-wp_genesis 1419 //add another rule to match attachments in the explicit form:
mp-wp_genesis 1420 //<permalink>/attachment/some-text
mp-wp_genesis 1421 $sub2 = $submatchbase . '/attachment/([^/]+)/';
mp-wp_genesis 1422 $sub2tb = $sub2 . $trackbackregex; //and add trackbacks <permalink>/attachment/trackback
mp-wp_genesis 1423 $sub2feed = $sub2 . $feedregex; //feeds, <permalink>/attachment/feed/(atom|...)
mp-wp_genesis 1424 $sub2feed2 = $sub2 . $feedregex2; //and feeds again on to this <permalink>/attachment/(feed|atom...)
mp-wp_genesis 1425 $sub2comment = $sub2 . $commentregex; //and <permalink>/comment-page-xx
mp-wp_genesis 1426
mp-wp_genesis 1427 //create queries for these extra tag-ons we've just dealt with
mp-wp_genesis 1428 $subquery = $index . '?attachment=' . $this->preg_index(1);
mp-wp_genesis 1429 $subtbquery = $subquery . '&tb=1';
mp-wp_genesis 1430 $subfeedquery = $subquery . '&feed=' . $this->preg_index(2);
mp-wp_genesis 1431 $subcommentquery = $subquery . '&cpage=' . $this->preg_index(2);
mp-wp_genesis 1432
mp-wp_genesis 1433 //do endpoints for attachments
mp-wp_genesis 1434 if ( !empty($endpoint) ) { foreach ( (array) $ep_query_append as $regex => $ep ) {
mp-wp_genesis 1435 if ($ep[0] & EP_ATTACHMENT) {
mp-wp_genesis 1436 $rewrite[$sub1 . $regex] = $subquery . '?' . $ep[1] . $this->preg_index(2);
mp-wp_genesis 1437 $rewrite[$sub2 . $regex] = $subquery . '?' . $ep[1] . $this->preg_index(2);
mp-wp_genesis 1438 }
mp-wp_genesis 1439 } }
mp-wp_genesis 1440
mp-wp_genesis 1441 //now we've finished with endpoints, finish off the $sub1 and $sub2 matches
mp-wp_genesis 1442 $sub1 .= '?$';
mp-wp_genesis 1443 $sub2 .= '?$';
mp-wp_genesis 1444
mp-wp_genesis 1445 //allow URLs like <permalink>/2 for <permalink>/page/2
mp-wp_genesis 1446 $match = $match . '(/[0-9]+)?/?$';
mp-wp_genesis 1447 $query = $index . '?' . $query . '&page=' . $this->preg_index($num_toks + 1);
mp-wp_genesis 1448 } else { //not matching a permalink so this is a lot simpler
mp-wp_genesis 1449 //close the match and finalise the query
mp-wp_genesis 1450 $match .= '?$';
mp-wp_genesis 1451 $query = $index . '?' . $query;
mp-wp_genesis 1452 }
mp-wp_genesis 1453
mp-wp_genesis 1454 //create the final array for this dir by joining the $rewrite array (which currently
mp-wp_genesis 1455 //only contains rules/queries for trackback, pages etc) to the main regex/query for
mp-wp_genesis 1456 //this dir
mp-wp_genesis 1457 $rewrite = array_merge($rewrite, array($match => $query));
mp-wp_genesis 1458
mp-wp_genesis 1459 //if we're matching a permalink, add those extras (attachments etc) on
mp-wp_genesis 1460 if ($post) {
mp-wp_genesis 1461 //add trackback
mp-wp_genesis 1462 $rewrite = array_merge(array($trackbackmatch => $trackbackquery), $rewrite);
mp-wp_genesis 1463
mp-wp_genesis 1464 //add regexes/queries for attachments, attachment trackbacks and so on
mp-wp_genesis 1465 if ( ! $page ) //require <permalink>/attachment/stuff form for pages because of confusion with subpages
mp-wp_genesis 1466 $rewrite = array_merge($rewrite, array($sub1 => $subquery, $sub1tb => $subtbquery, $sub1feed => $subfeedquery, $sub1feed2 => $subfeedquery, $sub1comment => $subcommentquery));
mp-wp_genesis 1467 $rewrite = array_merge(array($sub2 => $subquery, $sub2tb => $subtbquery, $sub2feed => $subfeedquery, $sub2feed2 => $subfeedquery, $sub2comment => $subcommentquery), $rewrite);
mp-wp_genesis 1468 }
mp-wp_genesis 1469 } //if($num_toks)
mp-wp_genesis 1470 //add the rules for this dir to the accumulating $post_rewrite
mp-wp_genesis 1471 $post_rewrite = array_merge($rewrite, $post_rewrite);
mp-wp_genesis 1472 } //foreach ($dir)
mp-wp_genesis 1473 return $post_rewrite; //the finished rules. phew!
mp-wp_genesis 1474 }
mp-wp_genesis 1475
mp-wp_genesis 1476 /**
mp-wp_genesis 1477 * Generate Rewrite rules with permalink structure and walking directory only.
mp-wp_genesis 1478 *
mp-wp_genesis 1479 * Shorten version of {@link WP_Rewrite::generate_rewrite_rules()} that
mp-wp_genesis 1480 * allows for shorter list of parameters. See the method for longer
mp-wp_genesis 1481 * description of what generating rewrite rules does.
mp-wp_genesis 1482 *
mp-wp_genesis 1483 * @uses WP_Rewrite::generate_rewrite_rules() See for long description and rest of parameters.
mp-wp_genesis 1484 * @since 1.5.0
mp-wp_genesis 1485 * @access public
mp-wp_genesis 1486 *
mp-wp_genesis 1487 * @param string $permalink_structure The permalink structure to generate rules.
mp-wp_genesis 1488 * @param bool $walk_dirs Optional, default is false. Whether to create list of directories to walk over.
mp-wp_genesis 1489 * @return array
mp-wp_genesis 1490 */
mp-wp_genesis 1491 function generate_rewrite_rule($permalink_structure, $walk_dirs = false) {
mp-wp_genesis 1492 return $this->generate_rewrite_rules($permalink_structure, EP_NONE, false, false, false, $walk_dirs);
mp-wp_genesis 1493 }
mp-wp_genesis 1494
mp-wp_genesis 1495 /**
mp-wp_genesis 1496 * Construct rewrite matches and queries from permalink structure.
mp-wp_genesis 1497 *
mp-wp_genesis 1498 * Runs the action 'generate_rewrite_rules' with the parameter that is an
mp-wp_genesis 1499 * reference to the current WP_Rewrite instance to further manipulate the
mp-wp_genesis 1500 * permalink structures and rewrite rules. Runs the 'rewrite_rules_array'
mp-wp_genesis 1501 * filter on the full rewrite rule array.
mp-wp_genesis 1502 *
mp-wp_genesis 1503 * There are two ways to manipulate the rewrite rules, one by hooking into
mp-wp_genesis 1504 * the 'generate_rewrite_rules' action and gaining full control of the
mp-wp_genesis 1505 * object or just manipulating the rewrite rule array before it is passed
mp-wp_genesis 1506 * from the function.
mp-wp_genesis 1507 *
mp-wp_genesis 1508 * @since 1.5.0
mp-wp_genesis 1509 * @access public
mp-wp_genesis 1510 *
mp-wp_genesis 1511 * @return array An associate array of matches and queries.
mp-wp_genesis 1512 */
mp-wp_genesis 1513 function rewrite_rules() {
mp-wp_genesis 1514 $rewrite = array();
mp-wp_genesis 1515
mp-wp_genesis 1516 if (empty($this->permalink_structure)) {
mp-wp_genesis 1517 return $rewrite;
mp-wp_genesis 1518 }
mp-wp_genesis 1519
mp-wp_genesis 1520 // robots.txt
mp-wp_genesis 1521 $robots_rewrite = array('robots\.txt$' => $this->index . '?robots=1');
mp-wp_genesis 1522
mp-wp_genesis 1523 //Default Feed rules - These are require to allow for the direct access files to work with permalink structure starting with %category%
mp-wp_genesis 1524 $default_feeds = array( '.*wp-atom.php$' => $this->index .'?feed=atom',
mp-wp_genesis 1525 '.*wp-rdf.php$' => $this->index .'?feed=rdf',
mp-wp_genesis 1526 '.*wp-rss.php$' => $this->index .'?feed=rss',
mp-wp_genesis 1527 '.*wp-rss2.php$' => $this->index .'?feed=rss2',
mp-wp_genesis 1528 '.*wp-feed.php$' => $this->index .'?feed=feed',
mp-wp_genesis 1529 '.*wp-commentsrss2.php$' => $this->index . '?feed=rss2&withcomments=1');
mp-wp_genesis 1530
mp-wp_genesis 1531 // Post
mp-wp_genesis 1532 $post_rewrite = $this->generate_rewrite_rules($this->permalink_structure, EP_PERMALINK);
mp-wp_genesis 1533 $post_rewrite = apply_filters('post_rewrite_rules', $post_rewrite);
mp-wp_genesis 1534
mp-wp_genesis 1535 // Date
mp-wp_genesis 1536 $date_rewrite = $this->generate_rewrite_rules($this->get_date_permastruct(), EP_DATE);
mp-wp_genesis 1537 $date_rewrite = apply_filters('date_rewrite_rules', $date_rewrite);
mp-wp_genesis 1538
mp-wp_genesis 1539 // Root
mp-wp_genesis 1540 $root_rewrite = $this->generate_rewrite_rules($this->root . '/', EP_ROOT);
mp-wp_genesis 1541 $root_rewrite = apply_filters('root_rewrite_rules', $root_rewrite);
mp-wp_genesis 1542
mp-wp_genesis 1543 // Comments
mp-wp_genesis 1544 $comments_rewrite = $this->generate_rewrite_rules($this->root . $this->comments_base, EP_COMMENTS, true, true, true, false);
mp-wp_genesis 1545 $comments_rewrite = apply_filters('comments_rewrite_rules', $comments_rewrite);
mp-wp_genesis 1546
mp-wp_genesis 1547 // Search
mp-wp_genesis 1548 $search_structure = $this->get_search_permastruct();
mp-wp_genesis 1549 $search_rewrite = $this->generate_rewrite_rules($search_structure, EP_SEARCH);
mp-wp_genesis 1550 $search_rewrite = apply_filters('search_rewrite_rules', $search_rewrite);
mp-wp_genesis 1551
mp-wp_genesis 1552 // Categories
mp-wp_genesis 1553 $category_rewrite = $this->generate_rewrite_rules($this->get_category_permastruct(), EP_CATEGORIES);
mp-wp_genesis 1554 $category_rewrite = apply_filters('category_rewrite_rules', $category_rewrite);
mp-wp_genesis 1555
mp-wp_genesis 1556 // Tags
mp-wp_genesis 1557 $tag_rewrite = $this->generate_rewrite_rules($this->get_tag_permastruct(), EP_TAGS);
mp-wp_genesis 1558 $tag_rewrite = apply_filters('tag_rewrite_rules', $tag_rewrite);
mp-wp_genesis 1559
mp-wp_genesis 1560 // Authors
mp-wp_genesis 1561 $author_rewrite = $this->generate_rewrite_rules($this->get_author_permastruct(), EP_AUTHORS);
mp-wp_genesis 1562 $author_rewrite = apply_filters('author_rewrite_rules', $author_rewrite);
mp-wp_genesis 1563
mp-wp_genesis 1564 // Pages
mp-wp_genesis 1565 $page_rewrite = $this->page_rewrite_rules();
mp-wp_genesis 1566 $page_rewrite = apply_filters('page_rewrite_rules', $page_rewrite);
mp-wp_genesis 1567
mp-wp_genesis 1568 // Extra permastructs
mp-wp_genesis 1569 foreach ( $this->extra_permastructs as $permastruct )
mp-wp_genesis 1570 $this->extra_rules_top = array_merge($this->extra_rules_top, $this->generate_rewrite_rules($permastruct, EP_NONE));
mp-wp_genesis 1571
mp-wp_genesis 1572 // Put them together.
mp-wp_genesis 1573 if ( $this->use_verbose_page_rules )
mp-wp_genesis 1574 $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);
mp-wp_genesis 1575 else
mp-wp_genesis 1576 $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);
mp-wp_genesis 1577
mp-wp_genesis 1578 do_action_ref_array('generate_rewrite_rules', array(&$this));
mp-wp_genesis 1579 $this->rules = apply_filters('rewrite_rules_array', $this->rules);
mp-wp_genesis 1580
mp-wp_genesis 1581 return $this->rules;
mp-wp_genesis 1582 }
mp-wp_genesis 1583
mp-wp_genesis 1584 /**
mp-wp_genesis 1585 * Retrieve the rewrite rules.
mp-wp_genesis 1586 *
mp-wp_genesis 1587 * The difference between this method and {@link
mp-wp_genesis 1588 * WP_Rewrite::rewrite_rules()} is that this method stores the rewrite rules
mp-wp_genesis 1589 * in the 'rewrite_rules' option and retrieves it. This prevents having to
mp-wp_genesis 1590 * process all of the permalinks to get the rewrite rules in the form of
mp-wp_genesis 1591 * caching.
mp-wp_genesis 1592 *
mp-wp_genesis 1593 * @since 1.5.0
mp-wp_genesis 1594 * @access public
mp-wp_genesis 1595 *
mp-wp_genesis 1596 * @return array Rewrite rules.
mp-wp_genesis 1597 */
mp-wp_genesis 1598 function wp_rewrite_rules() {
mp-wp_genesis 1599 $this->rules = get_option('rewrite_rules');
mp-wp_genesis 1600 if ( empty($this->rules) ) {
mp-wp_genesis 1601 $this->matches = 'matches';
mp-wp_genesis 1602 $this->rewrite_rules();
mp-wp_genesis 1603 update_option('rewrite_rules', $this->rules);
mp-wp_genesis 1604 }
mp-wp_genesis 1605
mp-wp_genesis 1606 return $this->rules;
mp-wp_genesis 1607 }
mp-wp_genesis 1608
mp-wp_genesis 1609 /**
mp-wp_genesis 1610 * Retrieve mod_rewrite formatted rewrite rules to write to .htaccess.
mp-wp_genesis 1611 *
mp-wp_genesis 1612 * Does not actually write to the .htaccess file, but creates the rules for
mp-wp_genesis 1613 * the process that will.
mp-wp_genesis 1614 *
mp-wp_genesis 1615 * Will add the non_wp_rules property rules to the .htaccess file before
mp-wp_genesis 1616 * the WordPress rewrite rules one.
mp-wp_genesis 1617 *
mp-wp_genesis 1618 * @since 1.5.0
mp-wp_genesis 1619 * @access public
mp-wp_genesis 1620 *
mp-wp_genesis 1621 * @return string
mp-wp_genesis 1622 */
mp-wp_genesis 1623 function mod_rewrite_rules() {
mp-wp_genesis 1624 if ( ! $this->using_permalinks()) {
mp-wp_genesis 1625 return '';
mp-wp_genesis 1626 }
mp-wp_genesis 1627
mp-wp_genesis 1628 $site_root = parse_url(get_option('siteurl'));
mp-wp_genesis 1629 if ( isset( $site_root['path'] ) ) {
mp-wp_genesis 1630 $site_root = trailingslashit($site_root['path']);
mp-wp_genesis 1631 }
mp-wp_genesis 1632
mp-wp_genesis 1633 $home_root = parse_url(get_option('home'));
mp-wp_genesis 1634 if ( isset( $home_root['path'] ) ) {
mp-wp_genesis 1635 $home_root = trailingslashit($home_root['path']);
mp-wp_genesis 1636 } else {
mp-wp_genesis 1637 $home_root = '/';
mp-wp_genesis 1638 }
mp-wp_genesis 1639
mp-wp_genesis 1640 $rules = "<IfModule mod_rewrite.c>\n";
mp-wp_genesis 1641 $rules .= "RewriteEngine On\n";
mp-wp_genesis 1642 $rules .= "RewriteBase $home_root\n";
mp-wp_genesis 1643
mp-wp_genesis 1644 //add in the rules that don't redirect to WP's index.php (and thus shouldn't be handled by WP at all)
mp-wp_genesis 1645 foreach ( (array) $this->non_wp_rules as $match => $query) {
mp-wp_genesis 1646 // Apache 1.3 does not support the reluctant (non-greedy) modifier.
mp-wp_genesis 1647 $match = str_replace('.+?', '.+', $match);
mp-wp_genesis 1648
mp-wp_genesis 1649 // If the match is unanchored and greedy, prepend rewrite conditions
mp-wp_genesis 1650 // to avoid infinite redirects and eclipsing of real files.
mp-wp_genesis 1651 if ($match == '(.+)/?$' || $match == '([^/]+)/?$' ) {
mp-wp_genesis 1652 //nada.
mp-wp_genesis 1653 }
mp-wp_genesis 1654
mp-wp_genesis 1655 $rules .= 'RewriteRule ^' . $match . ' ' . $home_root . $query . " [QSA,L]\n";
mp-wp_genesis 1656 }
mp-wp_genesis 1657
mp-wp_genesis 1658 if ($this->use_verbose_rules) {
mp-wp_genesis 1659 $this->matches = '';
mp-wp_genesis 1660 $rewrite = $this->rewrite_rules();
mp-wp_genesis 1661 $num_rules = count($rewrite);
mp-wp_genesis 1662 $rules .= "RewriteCond %{REQUEST_FILENAME} -f [OR]\n" .
mp-wp_genesis 1663 "RewriteCond %{REQUEST_FILENAME} -d\n" .
mp-wp_genesis 1664 "RewriteRule ^.*$ - [S=$num_rules]\n";
mp-wp_genesis 1665
mp-wp_genesis 1666 foreach ( (array) $rewrite as $match => $query) {
mp-wp_genesis 1667 // Apache 1.3 does not support the reluctant (non-greedy) modifier.
mp-wp_genesis 1668 $match = str_replace('.+?', '.+', $match);
mp-wp_genesis 1669
mp-wp_genesis 1670 // If the match is unanchored and greedy, prepend rewrite conditions
mp-wp_genesis 1671 // to avoid infinite redirects and eclipsing of real files.
mp-wp_genesis 1672 if ($match == '(.+)/?$' || $match == '([^/]+)/?$' ) {
mp-wp_genesis 1673 //nada.
mp-wp_genesis 1674 }
mp-wp_genesis 1675
mp-wp_genesis 1676 if (strpos($query, $this->index) !== false) {
mp-wp_genesis 1677 $rules .= 'RewriteRule ^' . $match . ' ' . $home_root . $query . " [QSA,L]\n";
mp-wp_genesis 1678 } else {
mp-wp_genesis 1679 $rules .= 'RewriteRule ^' . $match . ' ' . $site_root . $query . " [QSA,L]\n";
mp-wp_genesis 1680 }
mp-wp_genesis 1681 }
mp-wp_genesis 1682 } else {
mp-wp_genesis 1683 $rules .= "RewriteCond %{REQUEST_FILENAME} !-f\n" .
mp-wp_genesis 1684 "RewriteCond %{REQUEST_FILENAME} !-d\n" .
mp-wp_genesis 1685 "RewriteRule . {$home_root}{$this->index} [L]\n";
mp-wp_genesis 1686 }
mp-wp_genesis 1687
mp-wp_genesis 1688 $rules .= "</IfModule>\n";
mp-wp_genesis 1689
mp-wp_genesis 1690 $rules = apply_filters('mod_rewrite_rules', $rules);
mp-wp_genesis 1691 $rules = apply_filters('rewrite_rules', $rules); // Deprecated
mp-wp_genesis 1692
mp-wp_genesis 1693 return $rules;
mp-wp_genesis 1694 }
mp-wp_genesis 1695
mp-wp_genesis 1696 /**
mp-wp_genesis 1697 * Add a straight rewrite rule.
mp-wp_genesis 1698 *
mp-wp_genesis 1699 * Any value in the $after parameter that isn't 'bottom' will be placed at
mp-wp_genesis 1700 * the top of the rules.
mp-wp_genesis 1701 *
mp-wp_genesis 1702 * @since 2.1.0
mp-wp_genesis 1703 * @access public
mp-wp_genesis 1704 *
mp-wp_genesis 1705 * @param string $regex Regular expression to match against request.
mp-wp_genesis 1706 * @param string $redirect URL regex redirects to when regex matches request.
mp-wp_genesis 1707 * @param string $after Optional, default is bottom. Location to place rule.
mp-wp_genesis 1708 */
mp-wp_genesis 1709 function add_rule($regex, $redirect, $after = 'bottom') {
mp-wp_genesis 1710 //get everything up to the first ?
mp-wp_genesis 1711 $index = (strpos($redirect, '?') == false ? strlen($redirect) : strpos($redirect, '?'));
mp-wp_genesis 1712 $front = substr($redirect, 0, $index);
mp-wp_genesis 1713 if ($front != $this->index) { //it doesn't redirect to WP's index.php
mp-wp_genesis 1714 $this->add_external_rule($regex, $redirect);
mp-wp_genesis 1715 } else {
mp-wp_genesis 1716 if ( 'bottom' == $after)
mp-wp_genesis 1717 $this->extra_rules = array_merge($this->extra_rules, array($regex => $redirect));
mp-wp_genesis 1718 else
mp-wp_genesis 1719 $this->extra_rules_top = array_merge($this->extra_rules_top, array($regex => $redirect));
mp-wp_genesis 1720 //$this->extra_rules[$regex] = $redirect;
mp-wp_genesis 1721 }
mp-wp_genesis 1722 }
mp-wp_genesis 1723
mp-wp_genesis 1724 /**
mp-wp_genesis 1725 * Add a rule that doesn't redirect to index.php.
mp-wp_genesis 1726 *
mp-wp_genesis 1727 * Can redirect to any place.
mp-wp_genesis 1728 *
mp-wp_genesis 1729 * @since 2.1.0
mp-wp_genesis 1730 * @access public
mp-wp_genesis 1731 *
mp-wp_genesis 1732 * @param string $regex Regular expression to match against request.
mp-wp_genesis 1733 * @param string $redirect URL regex redirects to when regex matches request.
mp-wp_genesis 1734 */
mp-wp_genesis 1735 function add_external_rule($regex, $redirect) {
mp-wp_genesis 1736 $this->non_wp_rules[$regex] = $redirect;
mp-wp_genesis 1737 }
mp-wp_genesis 1738
mp-wp_genesis 1739 /**
mp-wp_genesis 1740 * Add an endpoint, like /trackback/.
mp-wp_genesis 1741 *
mp-wp_genesis 1742 * To be inserted after certain URL types (specified in $places).
mp-wp_genesis 1743 *
mp-wp_genesis 1744 * @since 2.1.0
mp-wp_genesis 1745 * @access public
mp-wp_genesis 1746 *
mp-wp_genesis 1747 * @param string $name Name of endpoint.
mp-wp_genesis 1748 * @param array $places URL types that endpoint can be used.
mp-wp_genesis 1749 */
mp-wp_genesis 1750 function add_endpoint($name, $places) {
mp-wp_genesis 1751 global $wp;
mp-wp_genesis 1752 $this->endpoints[] = array ( $places, $name );
mp-wp_genesis 1753 $wp->add_query_var($name);
mp-wp_genesis 1754 }
mp-wp_genesis 1755
mp-wp_genesis 1756 /**
mp-wp_genesis 1757 * Add permalink structure.
mp-wp_genesis 1758 *
mp-wp_genesis 1759 * These are added along with the extra rewrite rules that are merged to the
mp-wp_genesis 1760 * top.
mp-wp_genesis 1761 *
mp-wp_genesis 1762 * @since unknown
mp-wp_genesis 1763 * @access public
mp-wp_genesis 1764 *
mp-wp_genesis 1765 * @param string $name Name for permalink structure.
mp-wp_genesis 1766 * @param string $struct Permalink structure.
mp-wp_genesis 1767 * @param bool $with_front Prepend front base to permalink structure.
mp-wp_genesis 1768 */
mp-wp_genesis 1769 function add_permastruct($name, $struct, $with_front = true) {
mp-wp_genesis 1770 if ( $with_front )
mp-wp_genesis 1771 $struct = $this->front . $struct;
mp-wp_genesis 1772 $this->extra_permastructs[$name] = $struct;
mp-wp_genesis 1773 }
mp-wp_genesis 1774
mp-wp_genesis 1775 /**
mp-wp_genesis 1776 * Remove rewrite rules and then recreate rewrite rules.
mp-wp_genesis 1777 *
mp-wp_genesis 1778 * Calls {@link WP_Rewrite::wp_rewrite_rules()} after removing the
mp-wp_genesis 1779 * 'rewrite_rules' option. If the function named 'save_mod_rewrite_rules'
mp-wp_genesis 1780 * exists, it will be called.
mp-wp_genesis 1781 *
mp-wp_genesis 1782 * @since 2.0.1
mp-wp_genesis 1783 * @access public
mp-wp_genesis 1784 */
mp-wp_genesis 1785 function flush_rules() {
mp-wp_genesis 1786 delete_option('rewrite_rules');
mp-wp_genesis 1787 $this->wp_rewrite_rules();
mp-wp_genesis 1788 if ( function_exists('save_mod_rewrite_rules') )
mp-wp_genesis 1789 save_mod_rewrite_rules();
mp-wp_genesis 1790 }
mp-wp_genesis 1791
mp-wp_genesis 1792 /**
mp-wp_genesis 1793 * Sets up the object's properties.
mp-wp_genesis 1794 *
mp-wp_genesis 1795 * The 'use_verbose_page_rules' object property will be turned on, if the
mp-wp_genesis 1796 * permalink structure includes the following: '%postname%', '%category%',
mp-wp_genesis 1797 * '%tag%', or '%author%'.
mp-wp_genesis 1798 *
mp-wp_genesis 1799 * @since 1.5.0
mp-wp_genesis 1800 * @access public
mp-wp_genesis 1801 */
mp-wp_genesis 1802 function init() {
mp-wp_genesis 1803 $this->extra_rules = $this->non_wp_rules = $this->endpoints = array();
mp-wp_genesis 1804 $this->permalink_structure = get_option('permalink_structure');
mp-wp_genesis 1805 $this->front = substr($this->permalink_structure, 0, strpos($this->permalink_structure, '%'));
mp-wp_genesis 1806 $this->root = '';
mp-wp_genesis 1807 if ($this->using_index_permalinks()) {
mp-wp_genesis 1808 $this->root = $this->index . '/';
mp-wp_genesis 1809 }
mp-wp_genesis 1810 $this->category_base = get_option( 'category_base' );
mp-wp_genesis 1811 $this->tag_base = get_option( 'tag_base' );
mp-wp_genesis 1812 unset($this->category_structure);
mp-wp_genesis 1813 unset($this->author_structure);
mp-wp_genesis 1814 unset($this->date_structure);
mp-wp_genesis 1815 unset($this->page_structure);
mp-wp_genesis 1816 unset($this->search_structure);
mp-wp_genesis 1817 unset($this->feed_structure);
mp-wp_genesis 1818 unset($this->comment_feed_structure);
mp-wp_genesis 1819 $this->use_trailing_slashes = ( substr($this->permalink_structure, -1, 1) == '/' ) ? true : false;
mp-wp_genesis 1820
mp-wp_genesis 1821 // Enable generic rules for pages if permalink structure doesn't begin with a wildcard.
mp-wp_genesis 1822 $structure = ltrim($this->permalink_structure, '/');
mp-wp_genesis 1823 if ( $this->using_index_permalinks() )
mp-wp_genesis 1824 $structure = ltrim($this->permalink_structure, $this->index . '/');
mp-wp_genesis 1825 if ( 0 === strpos($structure, '%postname%') ||
mp-wp_genesis 1826 0 === strpos($structure, '%category%') ||
mp-wp_genesis 1827 0 === strpos($structure, '%tag%') ||
mp-wp_genesis 1828 0 === strpos($structure, '%author%') )
mp-wp_genesis 1829 $this->use_verbose_page_rules = true;
mp-wp_genesis 1830 else
mp-wp_genesis 1831 $this->use_verbose_page_rules = false;
mp-wp_genesis 1832 }
mp-wp_genesis 1833
mp-wp_genesis 1834 /**
mp-wp_genesis 1835 * Set the main permalink structure for the blog.
mp-wp_genesis 1836 *
mp-wp_genesis 1837 * Will update the 'permalink_structure' option, if there is a difference
mp-wp_genesis 1838 * between the current permalink structure and the parameter value. Calls
mp-wp_genesis 1839 * {@link WP_Rewrite::init()} after the option is updated.
mp-wp_genesis 1840 *
mp-wp_genesis 1841 * @since 1.5.0
mp-wp_genesis 1842 * @access public
mp-wp_genesis 1843 *
mp-wp_genesis 1844 * @param string $permalink_structure Permalink structure.
mp-wp_genesis 1845 */
mp-wp_genesis 1846 function set_permalink_structure($permalink_structure) {
mp-wp_genesis 1847 if ($permalink_structure != $this->permalink_structure) {
mp-wp_genesis 1848 update_option('permalink_structure', $permalink_structure);
mp-wp_genesis 1849 $this->init();
mp-wp_genesis 1850 }
mp-wp_genesis 1851 }
mp-wp_genesis 1852
mp-wp_genesis 1853 /**
mp-wp_genesis 1854 * Set the category base for the category permalink.
mp-wp_genesis 1855 *
mp-wp_genesis 1856 * Will update the 'category_base' option, if there is a difference between
mp-wp_genesis 1857 * the current category base and the parameter value. Calls
mp-wp_genesis 1858 * {@link WP_Rewrite::init()} after the option is updated.
mp-wp_genesis 1859 *
mp-wp_genesis 1860 * @since 1.5.0
mp-wp_genesis 1861 * @access public
mp-wp_genesis 1862 *
mp-wp_genesis 1863 * @param string $category_base Category permalink structure base.
mp-wp_genesis 1864 */
mp-wp_genesis 1865 function set_category_base($category_base) {
mp-wp_genesis 1866 if ($category_base != $this->category_base) {
mp-wp_genesis 1867 update_option('category_base', $category_base);
mp-wp_genesis 1868 $this->init();
mp-wp_genesis 1869 }
mp-wp_genesis 1870 }
mp-wp_genesis 1871
mp-wp_genesis 1872 /**
mp-wp_genesis 1873 * Set the tag base for the tag permalink.
mp-wp_genesis 1874 *
mp-wp_genesis 1875 * Will update the 'tag_base' option, if there is a difference between the
mp-wp_genesis 1876 * current tag base and the parameter value. Calls
mp-wp_genesis 1877 * {@link WP_Rewrite::init()} after the option is updated.
mp-wp_genesis 1878 *
mp-wp_genesis 1879 * @since 2.3.0
mp-wp_genesis 1880 * @access public
mp-wp_genesis 1881 *
mp-wp_genesis 1882 * @param string $tag_base Tag permalink structure base.
mp-wp_genesis 1883 */
mp-wp_genesis 1884 function set_tag_base( $tag_base ) {
mp-wp_genesis 1885 if ( $tag_base != $this->tag_base ) {
mp-wp_genesis 1886 update_option( 'tag_base', $tag_base );
mp-wp_genesis 1887 $this->init();
mp-wp_genesis 1888 }
mp-wp_genesis 1889 }
mp-wp_genesis 1890
mp-wp_genesis 1891 /**
mp-wp_genesis 1892 * PHP4 Constructor - Calls init(), which runs setup.
mp-wp_genesis 1893 *
mp-wp_genesis 1894 * @since 1.5.0
mp-wp_genesis 1895 * @access public
mp-wp_genesis 1896 *
mp-wp_genesis 1897 * @return WP_Rewrite
mp-wp_genesis 1898 */
mp-wp_genesis 1899 function WP_Rewrite() {
mp-wp_genesis 1900 $this->init();
mp-wp_genesis 1901 }
mp-wp_genesis 1902 }
mp-wp_genesis 1903
mp-wp_genesis 1904 ?>