Edit File by line
/home/barbar84/www/wp-inclu...
File: rewrite.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* WordPress Rewrite API
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @subpackage Rewrite
[5] Fix | Delete
*/
[6] Fix | Delete
[7] Fix | Delete
/**
[8] Fix | Delete
* Endpoint mask that matches nothing.
[9] Fix | Delete
*
[10] Fix | Delete
* @since 2.1.0
[11] Fix | Delete
*/
[12] Fix | Delete
define( 'EP_NONE', 0 );
[13] Fix | Delete
[14] Fix | Delete
/**
[15] Fix | Delete
* Endpoint mask that matches post permalinks.
[16] Fix | Delete
*
[17] Fix | Delete
* @since 2.1.0
[18] Fix | Delete
*/
[19] Fix | Delete
define( 'EP_PERMALINK', 1 );
[20] Fix | Delete
[21] Fix | Delete
/**
[22] Fix | Delete
* Endpoint mask that matches attachment permalinks.
[23] Fix | Delete
*
[24] Fix | Delete
* @since 2.1.0
[25] Fix | Delete
*/
[26] Fix | Delete
define( 'EP_ATTACHMENT', 2 );
[27] Fix | Delete
[28] Fix | Delete
/**
[29] Fix | Delete
* Endpoint mask that matches any date archives.
[30] Fix | Delete
*
[31] Fix | Delete
* @since 2.1.0
[32] Fix | Delete
*/
[33] Fix | Delete
define( 'EP_DATE', 4 );
[34] Fix | Delete
[35] Fix | Delete
/**
[36] Fix | Delete
* Endpoint mask that matches yearly archives.
[37] Fix | Delete
*
[38] Fix | Delete
* @since 2.1.0
[39] Fix | Delete
*/
[40] Fix | Delete
define( 'EP_YEAR', 8 );
[41] Fix | Delete
[42] Fix | Delete
/**
[43] Fix | Delete
* Endpoint mask that matches monthly archives.
[44] Fix | Delete
*
[45] Fix | Delete
* @since 2.1.0
[46] Fix | Delete
*/
[47] Fix | Delete
define( 'EP_MONTH', 16 );
[48] Fix | Delete
[49] Fix | Delete
/**
[50] Fix | Delete
* Endpoint mask that matches daily archives.
[51] Fix | Delete
*
[52] Fix | Delete
* @since 2.1.0
[53] Fix | Delete
*/
[54] Fix | Delete
define( 'EP_DAY', 32 );
[55] Fix | Delete
[56] Fix | Delete
/**
[57] Fix | Delete
* Endpoint mask that matches the site root.
[58] Fix | Delete
*
[59] Fix | Delete
* @since 2.1.0
[60] Fix | Delete
*/
[61] Fix | Delete
define( 'EP_ROOT', 64 );
[62] Fix | Delete
[63] Fix | Delete
/**
[64] Fix | Delete
* Endpoint mask that matches comment feeds.
[65] Fix | Delete
*
[66] Fix | Delete
* @since 2.1.0
[67] Fix | Delete
*/
[68] Fix | Delete
define( 'EP_COMMENTS', 128 );
[69] Fix | Delete
[70] Fix | Delete
/**
[71] Fix | Delete
* Endpoint mask that matches searches.
[72] Fix | Delete
*
[73] Fix | Delete
* Note that this only matches a search at a "pretty" URL such as
[74] Fix | Delete
* `/search/my-search-term`, not `?s=my-search-term`.
[75] Fix | Delete
*
[76] Fix | Delete
* @since 2.1.0
[77] Fix | Delete
*/
[78] Fix | Delete
define( 'EP_SEARCH', 256 );
[79] Fix | Delete
[80] Fix | Delete
/**
[81] Fix | Delete
* Endpoint mask that matches category archives.
[82] Fix | Delete
*
[83] Fix | Delete
* @since 2.1.0
[84] Fix | Delete
*/
[85] Fix | Delete
define( 'EP_CATEGORIES', 512 );
[86] Fix | Delete
[87] Fix | Delete
/**
[88] Fix | Delete
* Endpoint mask that matches tag archives.
[89] Fix | Delete
*
[90] Fix | Delete
* @since 2.3.0
[91] Fix | Delete
*/
[92] Fix | Delete
define( 'EP_TAGS', 1024 );
[93] Fix | Delete
[94] Fix | Delete
/**
[95] Fix | Delete
* Endpoint mask that matches author archives.
[96] Fix | Delete
*
[97] Fix | Delete
* @since 2.1.0
[98] Fix | Delete
*/
[99] Fix | Delete
define( 'EP_AUTHORS', 2048 );
[100] Fix | Delete
[101] Fix | Delete
/**
[102] Fix | Delete
* Endpoint mask that matches pages.
[103] Fix | Delete
*
[104] Fix | Delete
* @since 2.1.0
[105] Fix | Delete
*/
[106] Fix | Delete
define( 'EP_PAGES', 4096 );
[107] Fix | Delete
[108] Fix | Delete
/**
[109] Fix | Delete
* Endpoint mask that matches all archive views.
[110] Fix | Delete
*
[111] Fix | Delete
* @since 3.7.0
[112] Fix | Delete
*/
[113] Fix | Delete
define( 'EP_ALL_ARCHIVES', EP_DATE | EP_YEAR | EP_MONTH | EP_DAY | EP_CATEGORIES | EP_TAGS | EP_AUTHORS );
[114] Fix | Delete
[115] Fix | Delete
/**
[116] Fix | Delete
* Endpoint mask that matches everything.
[117] Fix | Delete
*
[118] Fix | Delete
* @since 2.1.0
[119] Fix | Delete
*/
[120] Fix | Delete
define( 'EP_ALL', EP_PERMALINK | EP_ATTACHMENT | EP_ROOT | EP_COMMENTS | EP_SEARCH | EP_PAGES | EP_ALL_ARCHIVES );
[121] Fix | Delete
[122] Fix | Delete
/**
[123] Fix | Delete
* Adds a rewrite rule that transforms a URL structure to a set of query vars.
[124] Fix | Delete
*
[125] Fix | Delete
* Any value in the $after parameter that isn't 'bottom' will result in the rule
[126] Fix | Delete
* being placed at the top of the rewrite rules.
[127] Fix | Delete
*
[128] Fix | Delete
* @since 2.1.0
[129] Fix | Delete
* @since 4.4.0 Array support was added to the `$query` parameter.
[130] Fix | Delete
*
[131] Fix | Delete
* @global WP_Rewrite $wp_rewrite WordPress rewrite component.
[132] Fix | Delete
*
[133] Fix | Delete
* @param string $regex Regular expression to match request against.
[134] Fix | Delete
* @param string|array $query The corresponding query vars for this rewrite rule.
[135] Fix | Delete
* @param string $after Optional. Priority of the new rule. Accepts 'top'
[136] Fix | Delete
* or 'bottom'. Default 'bottom'.
[137] Fix | Delete
*/
[138] Fix | Delete
function add_rewrite_rule( $regex, $query, $after = 'bottom' ) {
[139] Fix | Delete
global $wp_rewrite;
[140] Fix | Delete
[141] Fix | Delete
$wp_rewrite->add_rule( $regex, $query, $after );
[142] Fix | Delete
}
[143] Fix | Delete
[144] Fix | Delete
/**
[145] Fix | Delete
* Add a new rewrite tag (like %postname%).
[146] Fix | Delete
*
[147] Fix | Delete
* The `$query` parameter is optional. If it is omitted you must ensure that you call
[148] Fix | Delete
* this on, or before, the {@see 'init'} hook. This is because `$query` defaults to
[149] Fix | Delete
* `$tag=`, and for this to work a new query var has to be added.
[150] Fix | Delete
*
[151] Fix | Delete
* @since 2.1.0
[152] Fix | Delete
*
[153] Fix | Delete
* @global WP_Rewrite $wp_rewrite WordPress rewrite component.
[154] Fix | Delete
* @global WP $wp Current WordPress environment instance.
[155] Fix | Delete
*
[156] Fix | Delete
* @param string $tag Name of the new rewrite tag.
[157] Fix | Delete
* @param string $regex Regular expression to substitute the tag for in rewrite rules.
[158] Fix | Delete
* @param string $query Optional. String to append to the rewritten query. Must end in '='. Default empty.
[159] Fix | Delete
*/
[160] Fix | Delete
function add_rewrite_tag( $tag, $regex, $query = '' ) {
[161] Fix | Delete
// Validate the tag's name.
[162] Fix | Delete
if ( strlen( $tag ) < 3 || '%' !== $tag[0] || '%' !== $tag[ strlen( $tag ) - 1 ] ) {
[163] Fix | Delete
return;
[164] Fix | Delete
}
[165] Fix | Delete
[166] Fix | Delete
global $wp_rewrite, $wp;
[167] Fix | Delete
[168] Fix | Delete
if ( empty( $query ) ) {
[169] Fix | Delete
$qv = trim( $tag, '%' );
[170] Fix | Delete
$wp->add_query_var( $qv );
[171] Fix | Delete
$query = $qv . '=';
[172] Fix | Delete
}
[173] Fix | Delete
[174] Fix | Delete
$wp_rewrite->add_rewrite_tag( $tag, $regex, $query );
[175] Fix | Delete
}
[176] Fix | Delete
[177] Fix | Delete
/**
[178] Fix | Delete
* Removes an existing rewrite tag (like %postname%).
[179] Fix | Delete
*
[180] Fix | Delete
* @since 4.5.0
[181] Fix | Delete
*
[182] Fix | Delete
* @global WP_Rewrite $wp_rewrite WordPress rewrite component.
[183] Fix | Delete
*
[184] Fix | Delete
* @param string $tag Name of the rewrite tag.
[185] Fix | Delete
*/
[186] Fix | Delete
function remove_rewrite_tag( $tag ) {
[187] Fix | Delete
global $wp_rewrite;
[188] Fix | Delete
$wp_rewrite->remove_rewrite_tag( $tag );
[189] Fix | Delete
}
[190] Fix | Delete
[191] Fix | Delete
/**
[192] Fix | Delete
* Add permalink structure.
[193] Fix | Delete
*
[194] Fix | Delete
* @since 3.0.0
[195] Fix | Delete
*
[196] Fix | Delete
* @see WP_Rewrite::add_permastruct()
[197] Fix | Delete
* @global WP_Rewrite $wp_rewrite WordPress rewrite component.
[198] Fix | Delete
*
[199] Fix | Delete
* @param string $name Name for permalink structure.
[200] Fix | Delete
* @param string $struct Permalink structure.
[201] Fix | Delete
* @param array $args Optional. Arguments for building the rules from the permalink structure,
[202] Fix | Delete
* see WP_Rewrite::add_permastruct() for full details. Default empty array.
[203] Fix | Delete
*/
[204] Fix | Delete
function add_permastruct( $name, $struct, $args = array() ) {
[205] Fix | Delete
global $wp_rewrite;
[206] Fix | Delete
[207] Fix | Delete
// Back-compat for the old parameters: $with_front and $ep_mask.
[208] Fix | Delete
if ( ! is_array( $args ) ) {
[209] Fix | Delete
$args = array( 'with_front' => $args );
[210] Fix | Delete
}
[211] Fix | Delete
if ( func_num_args() == 4 ) {
[212] Fix | Delete
$args['ep_mask'] = func_get_arg( 3 );
[213] Fix | Delete
}
[214] Fix | Delete
[215] Fix | Delete
$wp_rewrite->add_permastruct( $name, $struct, $args );
[216] Fix | Delete
}
[217] Fix | Delete
[218] Fix | Delete
/**
[219] Fix | Delete
* Removes a permalink structure.
[220] Fix | Delete
*
[221] Fix | Delete
* Can only be used to remove permastructs that were added using add_permastruct().
[222] Fix | Delete
* Built-in permastructs cannot be removed.
[223] Fix | Delete
*
[224] Fix | Delete
* @since 4.5.0
[225] Fix | Delete
*
[226] Fix | Delete
* @see WP_Rewrite::remove_permastruct()
[227] Fix | Delete
* @global WP_Rewrite $wp_rewrite WordPress rewrite component.
[228] Fix | Delete
*
[229] Fix | Delete
* @param string $name Name for permalink structure.
[230] Fix | Delete
*/
[231] Fix | Delete
function remove_permastruct( $name ) {
[232] Fix | Delete
global $wp_rewrite;
[233] Fix | Delete
[234] Fix | Delete
$wp_rewrite->remove_permastruct( $name );
[235] Fix | Delete
}
[236] Fix | Delete
[237] Fix | Delete
/**
[238] Fix | Delete
* Add a new feed type like /atom1/.
[239] Fix | Delete
*
[240] Fix | Delete
* @since 2.1.0
[241] Fix | Delete
*
[242] Fix | Delete
* @global WP_Rewrite $wp_rewrite WordPress rewrite component.
[243] Fix | Delete
*
[244] Fix | Delete
* @param string $feedname Feed name.
[245] Fix | Delete
* @param callable $function Callback to run on feed display.
[246] Fix | Delete
* @return string Feed action name.
[247] Fix | Delete
*/
[248] Fix | Delete
function add_feed( $feedname, $function ) {
[249] Fix | Delete
global $wp_rewrite;
[250] Fix | Delete
[251] Fix | Delete
if ( ! in_array( $feedname, $wp_rewrite->feeds, true ) ) {
[252] Fix | Delete
$wp_rewrite->feeds[] = $feedname;
[253] Fix | Delete
}
[254] Fix | Delete
[255] Fix | Delete
$hook = 'do_feed_' . $feedname;
[256] Fix | Delete
[257] Fix | Delete
// Remove default function hook.
[258] Fix | Delete
remove_action( $hook, $hook );
[259] Fix | Delete
[260] Fix | Delete
add_action( $hook, $function, 10, 2 );
[261] Fix | Delete
[262] Fix | Delete
return $hook;
[263] Fix | Delete
}
[264] Fix | Delete
[265] Fix | Delete
/**
[266] Fix | Delete
* Remove rewrite rules and then recreate rewrite rules.
[267] Fix | Delete
*
[268] Fix | Delete
* @since 3.0.0
[269] Fix | Delete
*
[270] Fix | Delete
* @global WP_Rewrite $wp_rewrite WordPress rewrite component.
[271] Fix | Delete
*
[272] Fix | Delete
* @param bool $hard Whether to update .htaccess (hard flush) or just update
[273] Fix | Delete
* rewrite_rules option (soft flush). Default is true (hard).
[274] Fix | Delete
*/
[275] Fix | Delete
function flush_rewrite_rules( $hard = true ) {
[276] Fix | Delete
global $wp_rewrite;
[277] Fix | Delete
[278] Fix | Delete
if ( is_callable( array( $wp_rewrite, 'flush_rules' ) ) ) {
[279] Fix | Delete
$wp_rewrite->flush_rules( $hard );
[280] Fix | Delete
}
[281] Fix | Delete
}
[282] Fix | Delete
[283] Fix | Delete
/**
[284] Fix | Delete
* Add an endpoint, like /trackback/.
[285] Fix | Delete
*
[286] Fix | Delete
* Adding an endpoint creates extra rewrite rules for each of the matching
[287] Fix | Delete
* places specified by the provided bitmask. For example:
[288] Fix | Delete
*
[289] Fix | Delete
* add_rewrite_endpoint( 'json', EP_PERMALINK | EP_PAGES );
[290] Fix | Delete
*
[291] Fix | Delete
* will add a new rewrite rule ending with "json(/(.*))?/?$" for every permastruct
[292] Fix | Delete
* that describes a permalink (post) or page. This is rewritten to "json=$match"
[293] Fix | Delete
* where $match is the part of the URL matched by the endpoint regex (e.g. "foo" in
[294] Fix | Delete
* "[permalink]/json/foo/").
[295] Fix | Delete
*
[296] Fix | Delete
* A new query var with the same name as the endpoint will also be created.
[297] Fix | Delete
*
[298] Fix | Delete
* When specifying $places ensure that you are using the EP_* constants (or a
[299] Fix | Delete
* combination of them using the bitwise OR operator) as their values are not
[300] Fix | Delete
* guaranteed to remain static (especially `EP_ALL`).
[301] Fix | Delete
*
[302] Fix | Delete
* Be sure to flush the rewrite rules - see flush_rewrite_rules() - when your plugin gets
[303] Fix | Delete
* activated and deactivated.
[304] Fix | Delete
*
[305] Fix | Delete
* @since 2.1.0
[306] Fix | Delete
* @since 4.3.0 Added support for skipping query var registration by passing `false` to `$query_var`.
[307] Fix | Delete
*
[308] Fix | Delete
* @global WP_Rewrite $wp_rewrite WordPress rewrite component.
[309] Fix | Delete
*
[310] Fix | Delete
* @param string $name Name of the endpoint.
[311] Fix | Delete
* @param int $places Endpoint mask describing the places the endpoint should be added.
[312] Fix | Delete
* Accepts a mask of:
[313] Fix | Delete
* - `EP_ALL`
[314] Fix | Delete
* - `EP_NONE`
[315] Fix | Delete
* - `EP_ALL_ARCHIVES`
[316] Fix | Delete
* - `EP_ATTACHMENT`
[317] Fix | Delete
* - `EP_AUTHORS`
[318] Fix | Delete
* - `EP_CATEGORIES`
[319] Fix | Delete
* - `EP_COMMENTS`
[320] Fix | Delete
* - `EP_DATE`
[321] Fix | Delete
* - `EP_DAY`
[322] Fix | Delete
* - `EP_MONTH`
[323] Fix | Delete
* - `EP_PAGES`
[324] Fix | Delete
* - `EP_PERMALINK`
[325] Fix | Delete
* - `EP_ROOT`
[326] Fix | Delete
* - `EP_SEARCH`
[327] Fix | Delete
* - `EP_TAGS`
[328] Fix | Delete
* - `EP_YEAR`
[329] Fix | Delete
* @param string|bool $query_var Name of the corresponding query variable. Pass `false` to skip registering a query_var
[330] Fix | Delete
* for this endpoint. Defaults to the value of `$name`.
[331] Fix | Delete
*/
[332] Fix | Delete
function add_rewrite_endpoint( $name, $places, $query_var = true ) {
[333] Fix | Delete
global $wp_rewrite;
[334] Fix | Delete
$wp_rewrite->add_endpoint( $name, $places, $query_var );
[335] Fix | Delete
}
[336] Fix | Delete
[337] Fix | Delete
/**
[338] Fix | Delete
* Filters the URL base for taxonomies.
[339] Fix | Delete
*
[340] Fix | Delete
* To remove any manually prepended /index.php/.
[341] Fix | Delete
*
[342] Fix | Delete
* @access private
[343] Fix | Delete
* @since 2.6.0
[344] Fix | Delete
*
[345] Fix | Delete
* @param string $base The taxonomy base that we're going to filter
[346] Fix | Delete
* @return string
[347] Fix | Delete
*/
[348] Fix | Delete
function _wp_filter_taxonomy_base( $base ) {
[349] Fix | Delete
if ( ! empty( $base ) ) {
[350] Fix | Delete
$base = preg_replace( '|^/index\.php/|', '', $base );
[351] Fix | Delete
$base = trim( $base, '/' );
[352] Fix | Delete
}
[353] Fix | Delete
return $base;
[354] Fix | Delete
}
[355] Fix | Delete
[356] Fix | Delete
[357] Fix | Delete
/**
[358] Fix | Delete
* Resolve numeric slugs that collide with date permalinks.
[359] Fix | Delete
*
[360] Fix | Delete
* Permalinks of posts with numeric slugs can sometimes look to WP_Query::parse_query()
[361] Fix | Delete
* like a date archive, as when your permalink structure is `/%year%/%postname%/` and
[362] Fix | Delete
* a post with post_name '05' has the URL `/2015/05/`.
[363] Fix | Delete
*
[364] Fix | Delete
* This function detects conflicts of this type and resolves them in favor of the
[365] Fix | Delete
* post permalink.
[366] Fix | Delete
*
[367] Fix | Delete
* Note that, since 4.3.0, wp_unique_post_slug() prevents the creation of post slugs
[368] Fix | Delete
* that would result in a date archive conflict. The resolution performed in this
[369] Fix | Delete
* function is primarily for legacy content, as well as cases when the admin has changed
[370] Fix | Delete
* the site's permalink structure in a way that introduces URL conflicts.
[371] Fix | Delete
*
[372] Fix | Delete
* @since 4.3.0
[373] Fix | Delete
*
[374] Fix | Delete
* @param array $query_vars Optional. Query variables for setting up the loop, as determined in
[375] Fix | Delete
* WP::parse_request(). Default empty array.
[376] Fix | Delete
* @return array Returns the original array of query vars, with date/post conflicts resolved.
[377] Fix | Delete
*/
[378] Fix | Delete
function wp_resolve_numeric_slug_conflicts( $query_vars = array() ) {
[379] Fix | Delete
if ( ! isset( $query_vars['year'] ) && ! isset( $query_vars['monthnum'] ) && ! isset( $query_vars['day'] ) ) {
[380] Fix | Delete
return $query_vars;
[381] Fix | Delete
}
[382] Fix | Delete
[383] Fix | Delete
// Identify the 'postname' position in the permastruct array.
[384] Fix | Delete
$permastructs = array_values( array_filter( explode( '/', get_option( 'permalink_structure' ) ) ) );
[385] Fix | Delete
$postname_index = array_search( '%postname%', $permastructs, true );
[386] Fix | Delete
[387] Fix | Delete
if ( false === $postname_index ) {
[388] Fix | Delete
return $query_vars;
[389] Fix | Delete
}
[390] Fix | Delete
[391] Fix | Delete
/*
[392] Fix | Delete
* A numeric slug could be confused with a year, month, or day, depending on position. To account for
[393] Fix | Delete
* the possibility of post pagination (eg 2015/2 for the second page of a post called '2015'), our
[394] Fix | Delete
* `is_*` checks are generous: check for year-slug clashes when `is_year` *or* `is_month`, and check
[395] Fix | Delete
* for month-slug clashes when `is_month` *or* `is_day`.
[396] Fix | Delete
*/
[397] Fix | Delete
$compare = '';
[398] Fix | Delete
if ( 0 === $postname_index && ( isset( $query_vars['year'] ) || isset( $query_vars['monthnum'] ) ) ) {
[399] Fix | Delete
$compare = 'year';
[400] Fix | Delete
} elseif ( $postname_index && '%year%' === $permastructs[ $postname_index - 1 ] && ( isset( $query_vars['monthnum'] ) || isset( $query_vars['day'] ) ) ) {
[401] Fix | Delete
$compare = 'monthnum';
[402] Fix | Delete
} elseif ( $postname_index && '%monthnum%' === $permastructs[ $postname_index - 1 ] && isset( $query_vars['day'] ) ) {
[403] Fix | Delete
$compare = 'day';
[404] Fix | Delete
}
[405] Fix | Delete
[406] Fix | Delete
if ( ! $compare ) {
[407] Fix | Delete
return $query_vars;
[408] Fix | Delete
}
[409] Fix | Delete
[410] Fix | Delete
// This is the potentially clashing slug.
[411] Fix | Delete
$value = $query_vars[ $compare ];
[412] Fix | Delete
[413] Fix | Delete
$post = get_page_by_path( $value, OBJECT, 'post' );
[414] Fix | Delete
if ( ! ( $post instanceof WP_Post ) ) {
[415] Fix | Delete
return $query_vars;
[416] Fix | Delete
}
[417] Fix | Delete
[418] Fix | Delete
// If the date of the post doesn't match the date specified in the URL, resolve to the date archive.
[419] Fix | Delete
if ( preg_match( '/^([0-9]{4})\-([0-9]{2})/', $post->post_date, $matches ) && isset( $query_vars['year'] ) && ( 'monthnum' === $compare || 'day' === $compare ) ) {
[420] Fix | Delete
// $matches[1] is the year the post was published.
[421] Fix | Delete
if ( (int) $query_vars['year'] !== (int) $matches[1] ) {
[422] Fix | Delete
return $query_vars;
[423] Fix | Delete
}
[424] Fix | Delete
[425] Fix | Delete
// $matches[2] is the month the post was published.
[426] Fix | Delete
if ( 'day' === $compare && isset( $query_vars['monthnum'] ) && (int) $query_vars['monthnum'] !== (int) $matches[2] ) {
[427] Fix | Delete
return $query_vars;
[428] Fix | Delete
}
[429] Fix | Delete
}
[430] Fix | Delete
[431] Fix | Delete
/*
[432] Fix | Delete
* If the located post contains nextpage pagination, then the URL chunk following postname may be
[433] Fix | Delete
* intended as the page number. Verify that it's a valid page before resolving to it.
[434] Fix | Delete
*/
[435] Fix | Delete
$maybe_page = '';
[436] Fix | Delete
if ( 'year' === $compare && isset( $query_vars['monthnum'] ) ) {
[437] Fix | Delete
$maybe_page = $query_vars['monthnum'];
[438] Fix | Delete
} elseif ( 'monthnum' === $compare && isset( $query_vars['day'] ) ) {
[439] Fix | Delete
$maybe_page = $query_vars['day'];
[440] Fix | Delete
}
[441] Fix | Delete
// Bug found in #11694 - 'page' was returning '/4'.
[442] Fix | Delete
$maybe_page = (int) trim( $maybe_page, '/' );
[443] Fix | Delete
[444] Fix | Delete
$post_page_count = substr_count( $post->post_content, '<!--nextpage-->' ) + 1;
[445] Fix | Delete
[446] Fix | Delete
// If the post doesn't have multiple pages, but a 'page' candidate is found, resolve to the date archive.
[447] Fix | Delete
if ( 1 === $post_page_count && $maybe_page ) {
[448] Fix | Delete
return $query_vars;
[449] Fix | Delete
}
[450] Fix | Delete
[451] Fix | Delete
// If the post has multiple pages and the 'page' number isn't valid, resolve to the date archive.
[452] Fix | Delete
if ( $post_page_count > 1 && $maybe_page > $post_page_count ) {
[453] Fix | Delete
return $query_vars;
[454] Fix | Delete
}
[455] Fix | Delete
[456] Fix | Delete
// If we've gotten to this point, we have a slug/date clash. First, adjust for nextpage.
[457] Fix | Delete
if ( '' !== $maybe_page ) {
[458] Fix | Delete
$query_vars['page'] = (int) $maybe_page;
[459] Fix | Delete
}
[460] Fix | Delete
[461] Fix | Delete
// Next, unset autodetected date-related query vars.
[462] Fix | Delete
unset( $query_vars['year'] );
[463] Fix | Delete
unset( $query_vars['monthnum'] );
[464] Fix | Delete
unset( $query_vars['day'] );
[465] Fix | Delete
[466] Fix | Delete
// Then, set the identified post.
[467] Fix | Delete
$query_vars['name'] = $post->post_name;
[468] Fix | Delete
[469] Fix | Delete
// Finally, return the modified query vars.
[470] Fix | Delete
return $query_vars;
[471] Fix | Delete
}
[472] Fix | Delete
[473] Fix | Delete
/**
[474] Fix | Delete
* Examine a URL and try to determine the post ID it represents.
[475] Fix | Delete
*
[476] Fix | Delete
* Checks are supposedly from the hosted site blog.
[477] Fix | Delete
*
[478] Fix | Delete
* @since 1.0.0
[479] Fix | Delete
*
[480] Fix | Delete
* @global WP_Rewrite $wp_rewrite WordPress rewrite component.
[481] Fix | Delete
* @global WP $wp Current WordPress environment instance.
[482] Fix | Delete
*
[483] Fix | Delete
* @param string $url Permalink to check.
[484] Fix | Delete
* @return int Post ID, or 0 on failure.
[485] Fix | Delete
*/
[486] Fix | Delete
function url_to_postid( $url ) {
[487] Fix | Delete
global $wp_rewrite;
[488] Fix | Delete
[489] Fix | Delete
/**
[490] Fix | Delete
* Filters the URL to derive the post ID from.
[491] Fix | Delete
*
[492] Fix | Delete
* @since 2.2.0
[493] Fix | Delete
*
[494] Fix | Delete
* @param string $url The URL to derive the post ID from.
[495] Fix | Delete
*/
[496] Fix | Delete
$url = apply_filters( 'url_to_postid', $url );
[497] Fix | Delete
[498] Fix | Delete
$url_host = str_replace( 'www.', '', parse_url( $url, PHP_URL_HOST ) );
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function