Edit File by line
/home/barbar84/www/wp-inclu...
File: class-wp-rewrite.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Rewrite API: WP_Rewrite class
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @subpackage Rewrite
[5] Fix | Delete
* @since 1.5.0
[6] Fix | Delete
*/
[7] Fix | Delete
[8] Fix | Delete
/**
[9] Fix | Delete
* Core class used to implement a rewrite component API.
[10] Fix | Delete
*
[11] Fix | Delete
* The WordPress Rewrite class writes the rewrite module rules to the .htaccess
[12] Fix | Delete
* file. It also handles parsing the request to get the correct setup for the
[13] Fix | Delete
* WordPress Query class.
[14] Fix | Delete
*
[15] Fix | Delete
* The Rewrite along with WP class function as a front controller for WordPress.
[16] Fix | Delete
* You can add rules to trigger your page view and processing using this
[17] Fix | Delete
* component. The full functionality of a front controller does not exist,
[18] Fix | Delete
* meaning you can't define how the template files load based on the rewrite
[19] Fix | Delete
* rules.
[20] Fix | Delete
*
[21] Fix | Delete
* @since 1.5.0
[22] Fix | Delete
*/
[23] Fix | Delete
class WP_Rewrite {
[24] Fix | Delete
/**
[25] Fix | Delete
* Permalink structure for posts.
[26] Fix | Delete
*
[27] Fix | Delete
* @since 1.5.0
[28] Fix | Delete
* @var string
[29] Fix | Delete
*/
[30] Fix | Delete
public $permalink_structure;
[31] Fix | Delete
[32] Fix | Delete
/**
[33] Fix | Delete
* Whether to add trailing slashes.
[34] Fix | Delete
*
[35] Fix | Delete
* @since 2.2.0
[36] Fix | Delete
* @var bool
[37] Fix | Delete
*/
[38] Fix | Delete
public $use_trailing_slashes;
[39] Fix | Delete
[40] Fix | Delete
/**
[41] Fix | Delete
* Base for the author permalink structure (example.com/$author_base/authorname).
[42] Fix | Delete
*
[43] Fix | Delete
* @since 1.5.0
[44] Fix | Delete
* @var string
[45] Fix | Delete
*/
[46] Fix | Delete
public $author_base = 'author';
[47] Fix | Delete
[48] Fix | Delete
/**
[49] Fix | Delete
* Permalink structure for author archives.
[50] Fix | Delete
*
[51] Fix | Delete
* @since 1.5.0
[52] Fix | Delete
* @var string
[53] Fix | Delete
*/
[54] Fix | Delete
public $author_structure;
[55] Fix | Delete
[56] Fix | Delete
/**
[57] Fix | Delete
* Permalink structure for date archives.
[58] Fix | Delete
*
[59] Fix | Delete
* @since 1.5.0
[60] Fix | Delete
* @var string
[61] Fix | Delete
*/
[62] Fix | Delete
public $date_structure;
[63] Fix | Delete
[64] Fix | Delete
/**
[65] Fix | Delete
* Permalink structure for pages.
[66] Fix | Delete
*
[67] Fix | Delete
* @since 1.5.0
[68] Fix | Delete
* @var string
[69] Fix | Delete
*/
[70] Fix | Delete
public $page_structure;
[71] Fix | Delete
[72] Fix | Delete
/**
[73] Fix | Delete
* Base of the search permalink structure (example.com/$search_base/query).
[74] Fix | Delete
*
[75] Fix | Delete
* @since 1.5.0
[76] Fix | Delete
* @var string
[77] Fix | Delete
*/
[78] Fix | Delete
public $search_base = 'search';
[79] Fix | Delete
[80] Fix | Delete
/**
[81] Fix | Delete
* Permalink structure for searches.
[82] Fix | Delete
*
[83] Fix | Delete
* @since 1.5.0
[84] Fix | Delete
* @var string
[85] Fix | Delete
*/
[86] Fix | Delete
public $search_structure;
[87] Fix | Delete
[88] Fix | Delete
/**
[89] Fix | Delete
* Comments permalink base.
[90] Fix | Delete
*
[91] Fix | Delete
* @since 1.5.0
[92] Fix | Delete
* @var string
[93] Fix | Delete
*/
[94] Fix | Delete
public $comments_base = 'comments';
[95] Fix | Delete
[96] Fix | Delete
/**
[97] Fix | Delete
* Pagination permalink base.
[98] Fix | Delete
*
[99] Fix | Delete
* @since 3.1.0
[100] Fix | Delete
* @var string
[101] Fix | Delete
*/
[102] Fix | Delete
public $pagination_base = 'page';
[103] Fix | Delete
[104] Fix | Delete
/**
[105] Fix | Delete
* Comments pagination permalink base.
[106] Fix | Delete
*
[107] Fix | Delete
* @since 4.2.0
[108] Fix | Delete
* @var string
[109] Fix | Delete
*/
[110] Fix | Delete
public $comments_pagination_base = 'comment-page';
[111] Fix | Delete
[112] Fix | Delete
/**
[113] Fix | Delete
* Feed permalink base.
[114] Fix | Delete
*
[115] Fix | Delete
* @since 1.5.0
[116] Fix | Delete
* @var string
[117] Fix | Delete
*/
[118] Fix | Delete
public $feed_base = 'feed';
[119] Fix | Delete
[120] Fix | Delete
/**
[121] Fix | Delete
* Comments feed permalink structure.
[122] Fix | Delete
*
[123] Fix | Delete
* @since 1.5.0
[124] Fix | Delete
* @var string
[125] Fix | Delete
*/
[126] Fix | Delete
public $comment_feed_structure;
[127] Fix | Delete
[128] Fix | Delete
/**
[129] Fix | Delete
* Feed request permalink structure.
[130] Fix | Delete
*
[131] Fix | Delete
* @since 1.5.0
[132] Fix | Delete
* @var string
[133] Fix | Delete
*/
[134] Fix | Delete
public $feed_structure;
[135] Fix | Delete
[136] Fix | Delete
/**
[137] Fix | Delete
* The static portion of the post permalink structure.
[138] Fix | Delete
*
[139] Fix | Delete
* If the permalink structure is "/archive/%post_id%" then the front
[140] Fix | Delete
* is "/archive/". If the permalink structure is "/%year%/%postname%/"
[141] Fix | Delete
* then the front is "/".
[142] Fix | Delete
*
[143] Fix | Delete
* @since 1.5.0
[144] Fix | Delete
* @var string
[145] Fix | Delete
*
[146] Fix | Delete
* @see WP_Rewrite::init()
[147] Fix | Delete
*/
[148] Fix | Delete
public $front;
[149] Fix | Delete
[150] Fix | Delete
/**
[151] Fix | Delete
* The prefix for all permalink structures.
[152] Fix | Delete
*
[153] Fix | Delete
* If PATHINFO/index permalinks are in use then the root is the value of
[154] Fix | Delete
* `WP_Rewrite::$index` with a trailing slash appended. Otherwise the root
[155] Fix | Delete
* will be empty.
[156] Fix | Delete
*
[157] Fix | Delete
* @since 1.5.0
[158] Fix | Delete
* @var string
[159] Fix | Delete
*
[160] Fix | Delete
* @see WP_Rewrite::init()
[161] Fix | Delete
* @see WP_Rewrite::using_index_permalinks()
[162] Fix | Delete
*/
[163] Fix | Delete
public $root = '';
[164] Fix | Delete
[165] Fix | Delete
/**
[166] Fix | Delete
* The name of the index file which is the entry point to all requests.
[167] Fix | Delete
*
[168] Fix | Delete
* @since 1.5.0
[169] Fix | Delete
* @var string
[170] Fix | Delete
*/
[171] Fix | Delete
public $index = 'index.php';
[172] Fix | Delete
[173] Fix | Delete
/**
[174] Fix | Delete
* Variable name to use for regex matches in the rewritten query.
[175] Fix | Delete
*
[176] Fix | Delete
* @since 1.5.0
[177] Fix | Delete
* @var string
[178] Fix | Delete
*/
[179] Fix | Delete
public $matches = '';
[180] Fix | Delete
[181] Fix | Delete
/**
[182] Fix | Delete
* Rewrite rules to match against the request to find the redirect or query.
[183] Fix | Delete
*
[184] Fix | Delete
* @since 1.5.0
[185] Fix | Delete
* @var array
[186] Fix | Delete
*/
[187] Fix | Delete
public $rules;
[188] Fix | Delete
[189] Fix | Delete
/**
[190] Fix | Delete
* Additional rules added external to the rewrite class.
[191] Fix | Delete
*
[192] Fix | Delete
* Those not generated by the class, see add_rewrite_rule().
[193] Fix | Delete
*
[194] Fix | Delete
* @since 2.1.0
[195] Fix | Delete
* @var array
[196] Fix | Delete
*/
[197] Fix | Delete
public $extra_rules = array();
[198] Fix | Delete
[199] Fix | Delete
/**
[200] Fix | Delete
* Additional rules that belong at the beginning to match first.
[201] Fix | Delete
*
[202] Fix | Delete
* Those not generated by the class, see add_rewrite_rule().
[203] Fix | Delete
*
[204] Fix | Delete
* @since 2.3.0
[205] Fix | Delete
* @var array
[206] Fix | Delete
*/
[207] Fix | Delete
public $extra_rules_top = array();
[208] Fix | Delete
[209] Fix | Delete
/**
[210] Fix | Delete
* Rules that don't redirect to WordPress' index.php.
[211] Fix | Delete
*
[212] Fix | Delete
* These rules are written to the mod_rewrite portion of the .htaccess,
[213] Fix | Delete
* and are added by add_external_rule().
[214] Fix | Delete
*
[215] Fix | Delete
* @since 2.1.0
[216] Fix | Delete
* @var array
[217] Fix | Delete
*/
[218] Fix | Delete
public $non_wp_rules = array();
[219] Fix | Delete
[220] Fix | Delete
/**
[221] Fix | Delete
* Extra permalink structures, e.g. categories, added by add_permastruct().
[222] Fix | Delete
*
[223] Fix | Delete
* @since 2.1.0
[224] Fix | Delete
* @var array
[225] Fix | Delete
*/
[226] Fix | Delete
public $extra_permastructs = array();
[227] Fix | Delete
[228] Fix | Delete
/**
[229] Fix | Delete
* Endpoints (like /trackback/) added by add_rewrite_endpoint().
[230] Fix | Delete
*
[231] Fix | Delete
* @since 2.1.0
[232] Fix | Delete
* @var array
[233] Fix | Delete
*/
[234] Fix | Delete
public $endpoints;
[235] Fix | Delete
[236] Fix | Delete
/**
[237] Fix | Delete
* Whether to write every mod_rewrite rule for WordPress into the .htaccess file.
[238] Fix | Delete
*
[239] Fix | Delete
* This is off by default, turning it on might print a lot of rewrite rules
[240] Fix | Delete
* to the .htaccess file.
[241] Fix | Delete
*
[242] Fix | Delete
* @since 2.0.0
[243] Fix | Delete
* @var bool
[244] Fix | Delete
*
[245] Fix | Delete
* @see WP_Rewrite::mod_rewrite_rules()
[246] Fix | Delete
*/
[247] Fix | Delete
public $use_verbose_rules = false;
[248] Fix | Delete
[249] Fix | Delete
/**
[250] Fix | Delete
* Could post permalinks be confused with those of pages?
[251] Fix | Delete
*
[252] Fix | Delete
* If the first rewrite tag in the post permalink structure is one that could
[253] Fix | Delete
* also match a page name (e.g. %postname% or %author%) then this flag is
[254] Fix | Delete
* set to true. Prior to WordPress 3.3 this flag indicated that every page
[255] Fix | Delete
* would have a set of rules added to the top of the rewrite rules array.
[256] Fix | Delete
* Now it tells WP::parse_request() to check if a URL matching the page
[257] Fix | Delete
* permastruct is actually a page before accepting it.
[258] Fix | Delete
*
[259] Fix | Delete
* @since 2.5.0
[260] Fix | Delete
* @var bool
[261] Fix | Delete
*
[262] Fix | Delete
* @see WP_Rewrite::init()
[263] Fix | Delete
*/
[264] Fix | Delete
public $use_verbose_page_rules = true;
[265] Fix | Delete
[266] Fix | Delete
/**
[267] Fix | Delete
* Rewrite tags that can be used in permalink structures.
[268] Fix | Delete
*
[269] Fix | Delete
* These are translated into the regular expressions stored in
[270] Fix | Delete
* `WP_Rewrite::$rewritereplace` and are rewritten to the query
[271] Fix | Delete
* variables listed in WP_Rewrite::$queryreplace.
[272] Fix | Delete
*
[273] Fix | Delete
* Additional tags can be added with add_rewrite_tag().
[274] Fix | Delete
*
[275] Fix | Delete
* @since 1.5.0
[276] Fix | Delete
* @var array
[277] Fix | Delete
*/
[278] Fix | Delete
public $rewritecode = array(
[279] Fix | Delete
'%year%',
[280] Fix | Delete
'%monthnum%',
[281] Fix | Delete
'%day%',
[282] Fix | Delete
'%hour%',
[283] Fix | Delete
'%minute%',
[284] Fix | Delete
'%second%',
[285] Fix | Delete
'%postname%',
[286] Fix | Delete
'%post_id%',
[287] Fix | Delete
'%author%',
[288] Fix | Delete
'%pagename%',
[289] Fix | Delete
'%search%',
[290] Fix | Delete
);
[291] Fix | Delete
[292] Fix | Delete
/**
[293] Fix | Delete
* Regular expressions to be substituted into rewrite rules in place
[294] Fix | Delete
* of rewrite tags, see WP_Rewrite::$rewritecode.
[295] Fix | Delete
*
[296] Fix | Delete
* @since 1.5.0
[297] Fix | Delete
* @var array
[298] Fix | Delete
*/
[299] Fix | Delete
public $rewritereplace = array(
[300] Fix | Delete
'([0-9]{4})',
[301] Fix | Delete
'([0-9]{1,2})',
[302] Fix | Delete
'([0-9]{1,2})',
[303] Fix | Delete
'([0-9]{1,2})',
[304] Fix | Delete
'([0-9]{1,2})',
[305] Fix | Delete
'([0-9]{1,2})',
[306] Fix | Delete
'([^/]+)',
[307] Fix | Delete
'([0-9]+)',
[308] Fix | Delete
'([^/]+)',
[309] Fix | Delete
'([^/]+?)',
[310] Fix | Delete
'(.+)',
[311] Fix | Delete
);
[312] Fix | Delete
[313] Fix | Delete
/**
[314] Fix | Delete
* Query variables that rewrite tags map to, see WP_Rewrite::$rewritecode.
[315] Fix | Delete
*
[316] Fix | Delete
* @since 1.5.0
[317] Fix | Delete
* @var array
[318] Fix | Delete
*/
[319] Fix | Delete
public $queryreplace = array(
[320] Fix | Delete
'year=',
[321] Fix | Delete
'monthnum=',
[322] Fix | Delete
'day=',
[323] Fix | Delete
'hour=',
[324] Fix | Delete
'minute=',
[325] Fix | Delete
'second=',
[326] Fix | Delete
'name=',
[327] Fix | Delete
'p=',
[328] Fix | Delete
'author_name=',
[329] Fix | Delete
'pagename=',
[330] Fix | Delete
's=',
[331] Fix | Delete
);
[332] Fix | Delete
[333] Fix | Delete
/**
[334] Fix | Delete
* Supported default feeds.
[335] Fix | Delete
*
[336] Fix | Delete
* @since 1.5.0
[337] Fix | Delete
* @var array
[338] Fix | Delete
*/
[339] Fix | Delete
public $feeds = array( 'feed', 'rdf', 'rss', 'rss2', 'atom' );
[340] Fix | Delete
[341] Fix | Delete
/**
[342] Fix | Delete
* Determines whether permalinks are being used.
[343] Fix | Delete
*
[344] Fix | Delete
* This can be either rewrite module or permalink in the HTTP query string.
[345] Fix | Delete
*
[346] Fix | Delete
* @since 1.5.0
[347] Fix | Delete
*
[348] Fix | Delete
* @return bool True, if permalinks are enabled.
[349] Fix | Delete
*/
[350] Fix | Delete
public function using_permalinks() {
[351] Fix | Delete
return ! empty( $this->permalink_structure );
[352] Fix | Delete
}
[353] Fix | Delete
[354] Fix | Delete
/**
[355] Fix | Delete
* Determines whether permalinks are being used and rewrite module is not enabled.
[356] Fix | Delete
*
[357] Fix | Delete
* Means that permalink links are enabled and index.php is in the URL.
[358] Fix | Delete
*
[359] Fix | Delete
* @since 1.5.0
[360] Fix | Delete
*
[361] Fix | Delete
* @return bool Whether permalink links are enabled and index.php is in the URL.
[362] Fix | Delete
*/
[363] Fix | Delete
public function using_index_permalinks() {
[364] Fix | Delete
if ( empty( $this->permalink_structure ) ) {
[365] Fix | Delete
return false;
[366] Fix | Delete
}
[367] Fix | Delete
[368] Fix | Delete
// If the index is not in the permalink, we're using mod_rewrite.
[369] Fix | Delete
return preg_match( '#^/*' . $this->index . '#', $this->permalink_structure );
[370] Fix | Delete
}
[371] Fix | Delete
[372] Fix | Delete
/**
[373] Fix | Delete
* Determines whether permalinks are being used and rewrite module is enabled.
[374] Fix | Delete
*
[375] Fix | Delete
* Using permalinks and index.php is not in the URL.
[376] Fix | Delete
*
[377] Fix | Delete
* @since 1.5.0
[378] Fix | Delete
*
[379] Fix | Delete
* @return bool Whether permalink links are enabled and index.php is NOT in the URL.
[380] Fix | Delete
*/
[381] Fix | Delete
public function using_mod_rewrite_permalinks() {
[382] Fix | Delete
return $this->using_permalinks() && ! $this->using_index_permalinks();
[383] Fix | Delete
}
[384] Fix | Delete
[385] Fix | Delete
/**
[386] Fix | Delete
* Indexes for matches for usage in preg_*() functions.
[387] Fix | Delete
*
[388] Fix | Delete
* The format of the string is, with empty matches property value, '$NUM'.
[389] Fix | Delete
* The 'NUM' will be replaced with the value in the $number parameter. With
[390] Fix | Delete
* the matches property not empty, the value of the returned string will
[391] Fix | Delete
* contain that value of the matches property. The format then will be
[392] Fix | Delete
* '$MATCHES[NUM]', with MATCHES as the value in the property and NUM the
[393] Fix | Delete
* value of the $number parameter.
[394] Fix | Delete
*
[395] Fix | Delete
* @since 1.5.0
[396] Fix | Delete
*
[397] Fix | Delete
* @param int $number Index number.
[398] Fix | Delete
* @return string
[399] Fix | Delete
*/
[400] Fix | Delete
public function preg_index( $number ) {
[401] Fix | Delete
$match_prefix = '$';
[402] Fix | Delete
$match_suffix = '';
[403] Fix | Delete
[404] Fix | Delete
if ( ! empty( $this->matches ) ) {
[405] Fix | Delete
$match_prefix = '$' . $this->matches . '[';
[406] Fix | Delete
$match_suffix = ']';
[407] Fix | Delete
}
[408] Fix | Delete
[409] Fix | Delete
return "$match_prefix$number$match_suffix";
[410] Fix | Delete
}
[411] Fix | Delete
[412] Fix | Delete
/**
[413] Fix | Delete
* Retrieves all page and attachments for pages URIs.
[414] Fix | Delete
*
[415] Fix | Delete
* The attachments are for those that have pages as parents and will be
[416] Fix | Delete
* retrieved.
[417] Fix | Delete
*
[418] Fix | Delete
* @since 2.5.0
[419] Fix | Delete
*
[420] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[421] Fix | Delete
*
[422] Fix | Delete
* @return array Array of page URIs as first element and attachment URIs as second element.
[423] Fix | Delete
*/
[424] Fix | Delete
public function page_uri_index() {
[425] Fix | Delete
global $wpdb;
[426] Fix | Delete
[427] Fix | Delete
// Get pages in order of hierarchy, i.e. children after parents.
[428] Fix | Delete
$pages = $wpdb->get_results( "SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_type = 'page' AND post_status != 'auto-draft'" );
[429] Fix | Delete
$posts = get_page_hierarchy( $pages );
[430] Fix | Delete
[431] Fix | Delete
// If we have no pages get out quick.
[432] Fix | Delete
if ( ! $posts ) {
[433] Fix | Delete
return array( array(), array() );
[434] Fix | Delete
}
[435] Fix | Delete
[436] Fix | Delete
// Now reverse it, because we need parents after children for rewrite rules to work properly.
[437] Fix | Delete
$posts = array_reverse( $posts, true );
[438] Fix | Delete
[439] Fix | Delete
$page_uris = array();
[440] Fix | Delete
$page_attachment_uris = array();
[441] Fix | Delete
[442] Fix | Delete
foreach ( $posts as $id => $post ) {
[443] Fix | Delete
// URL => page name.
[444] Fix | Delete
$uri = get_page_uri( $id );
[445] Fix | Delete
$attachments = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_type = 'attachment' AND post_parent = %d", $id ) );
[446] Fix | Delete
if ( ! empty( $attachments ) ) {
[447] Fix | Delete
foreach ( $attachments as $attachment ) {
[448] Fix | Delete
$attach_uri = get_page_uri( $attachment->ID );
[449] Fix | Delete
$page_attachment_uris[ $attach_uri ] = $attachment->ID;
[450] Fix | Delete
}
[451] Fix | Delete
}
[452] Fix | Delete
[453] Fix | Delete
$page_uris[ $uri ] = $id;
[454] Fix | Delete
}
[455] Fix | Delete
[456] Fix | Delete
return array( $page_uris, $page_attachment_uris );
[457] Fix | Delete
}
[458] Fix | Delete
[459] Fix | Delete
/**
[460] Fix | Delete
* Retrieves all of the rewrite rules for pages.
[461] Fix | Delete
*
[462] Fix | Delete
* @since 1.5.0
[463] Fix | Delete
*
[464] Fix | Delete
* @return string[] Page rewrite rules.
[465] Fix | Delete
*/
[466] Fix | Delete
public function page_rewrite_rules() {
[467] Fix | Delete
// The extra .? at the beginning prevents clashes with other regular expressions in the rules array.
[468] Fix | Delete
$this->add_rewrite_tag( '%pagename%', '(.?.+?)', 'pagename=' );
[469] Fix | Delete
[470] Fix | Delete
return $this->generate_rewrite_rules( $this->get_page_permastruct(), EP_PAGES, true, true, false, false );
[471] Fix | Delete
}
[472] Fix | Delete
[473] Fix | Delete
/**
[474] Fix | Delete
* Retrieves date permalink structure, with year, month, and day.
[475] Fix | Delete
*
[476] Fix | Delete
* The permalink structure for the date, if not set already depends on the
[477] Fix | Delete
* permalink structure. It can be one of three formats. The first is year,
[478] Fix | Delete
* month, day; the second is day, month, year; and the last format is month,
[479] Fix | Delete
* day, year. These are matched against the permalink structure for which
[480] Fix | Delete
* one is used. If none matches, then the default will be used, which is
[481] Fix | Delete
* year, month, day.
[482] Fix | Delete
*
[483] Fix | Delete
* Prevents post ID and date permalinks from overlapping. In the case of
[484] Fix | Delete
* post_id, the date permalink will be prepended with front permalink with
[485] Fix | Delete
* 'date/' before the actual permalink to form the complete date permalink
[486] Fix | Delete
* structure.
[487] Fix | Delete
*
[488] Fix | Delete
* @since 1.5.0
[489] Fix | Delete
*
[490] Fix | Delete
* @return string|false Date permalink structure on success, false on failure.
[491] Fix | Delete
*/
[492] Fix | Delete
public function get_date_permastruct() {
[493] Fix | Delete
if ( isset( $this->date_structure ) ) {
[494] Fix | Delete
return $this->date_structure;
[495] Fix | Delete
}
[496] Fix | Delete
[497] Fix | Delete
if ( empty( $this->permalink_structure ) ) {
[498] Fix | Delete
$this->date_structure = '';
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function