Edit File by line
/home/barbar84/www/wp-inclu...
File: canonical.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Canonical API to handle WordPress Redirecting
[2] Fix | Delete
*
[3] Fix | Delete
* Based on "Permalink Redirect" from Scott Yang and "Enforce www. Preference"
[4] Fix | Delete
* by Mark Jaquith
[5] Fix | Delete
*
[6] Fix | Delete
* @package WordPress
[7] Fix | Delete
* @since 2.3.0
[8] Fix | Delete
*/
[9] Fix | Delete
[10] Fix | Delete
/**
[11] Fix | Delete
* Redirects incoming links to the proper URL based on the site url.
[12] Fix | Delete
*
[13] Fix | Delete
* Search engines consider www.somedomain.com and somedomain.com to be two
[14] Fix | Delete
* different URLs when they both go to the same location. This SEO enhancement
[15] Fix | Delete
* prevents penalty for duplicate content by redirecting all incoming links to
[16] Fix | Delete
* one or the other.
[17] Fix | Delete
*
[18] Fix | Delete
* Prevents redirection for feeds, trackbacks, searches, and
[19] Fix | Delete
* admin URLs. Does not redirect on non-pretty-permalink-supporting IIS 7+,
[20] Fix | Delete
* page/post previews, WP admin, Trackbacks, robots.txt, favicon.ico, searches,
[21] Fix | Delete
* or on POST requests.
[22] Fix | Delete
*
[23] Fix | Delete
* Will also attempt to find the correct link when a user enters a URL that does
[24] Fix | Delete
* not exist based on exact WordPress query. Will instead try to parse the URL
[25] Fix | Delete
* or query in an attempt to figure the correct page to go to.
[26] Fix | Delete
*
[27] Fix | Delete
* @since 2.3.0
[28] Fix | Delete
*
[29] Fix | Delete
* @global WP_Rewrite $wp_rewrite WordPress rewrite component.
[30] Fix | Delete
* @global bool $is_IIS
[31] Fix | Delete
* @global WP_Query $wp_query WordPress Query object.
[32] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[33] Fix | Delete
* @global WP $wp Current WordPress environment instance.
[34] Fix | Delete
*
[35] Fix | Delete
* @param string $requested_url Optional. The URL that was requested, used to
[36] Fix | Delete
* figure if redirect is needed.
[37] Fix | Delete
* @param bool $do_redirect Optional. Redirect to the new URL.
[38] Fix | Delete
* @return string|void The string of the URL, if redirect needed.
[39] Fix | Delete
*/
[40] Fix | Delete
function redirect_canonical( $requested_url = null, $do_redirect = true ) {
[41] Fix | Delete
global $wp_rewrite, $is_IIS, $wp_query, $wpdb, $wp;
[42] Fix | Delete
[43] Fix | Delete
if ( isset( $_SERVER['REQUEST_METHOD'] ) && ! in_array( strtoupper( $_SERVER['REQUEST_METHOD'] ), array( 'GET', 'HEAD' ), true ) ) {
[44] Fix | Delete
return;
[45] Fix | Delete
}
[46] Fix | Delete
[47] Fix | Delete
// If we're not in wp-admin and the post has been published and preview nonce
[48] Fix | Delete
// is non-existent or invalid then no need for preview in query.
[49] Fix | Delete
if ( is_preview() && get_query_var( 'p' ) && 'publish' === get_post_status( get_query_var( 'p' ) ) ) {
[50] Fix | Delete
if ( ! isset( $_GET['preview_id'] )
[51] Fix | Delete
|| ! isset( $_GET['preview_nonce'] )
[52] Fix | Delete
|| ! wp_verify_nonce( $_GET['preview_nonce'], 'post_preview_' . (int) $_GET['preview_id'] )
[53] Fix | Delete
) {
[54] Fix | Delete
$wp_query->is_preview = false;
[55] Fix | Delete
}
[56] Fix | Delete
}
[57] Fix | Delete
[58] Fix | Delete
if ( is_admin() || is_search() || is_preview() || is_trackback() || is_favicon()
[59] Fix | Delete
|| ( $is_IIS && ! iis7_supports_permalinks() )
[60] Fix | Delete
) {
[61] Fix | Delete
return;
[62] Fix | Delete
}
[63] Fix | Delete
[64] Fix | Delete
if ( ! $requested_url && isset( $_SERVER['HTTP_HOST'] ) ) {
[65] Fix | Delete
// Build the URL in the address bar.
[66] Fix | Delete
$requested_url = is_ssl() ? 'https://' : 'http://';
[67] Fix | Delete
$requested_url .= $_SERVER['HTTP_HOST'];
[68] Fix | Delete
$requested_url .= $_SERVER['REQUEST_URI'];
[69] Fix | Delete
}
[70] Fix | Delete
[71] Fix | Delete
$original = parse_url( $requested_url );
[72] Fix | Delete
if ( false === $original ) {
[73] Fix | Delete
return;
[74] Fix | Delete
}
[75] Fix | Delete
[76] Fix | Delete
$redirect = $original;
[77] Fix | Delete
$redirect_url = false;
[78] Fix | Delete
$redirect_obj = false;
[79] Fix | Delete
[80] Fix | Delete
// Notice fixing.
[81] Fix | Delete
if ( ! isset( $redirect['path'] ) ) {
[82] Fix | Delete
$redirect['path'] = '';
[83] Fix | Delete
}
[84] Fix | Delete
if ( ! isset( $redirect['query'] ) ) {
[85] Fix | Delete
$redirect['query'] = '';
[86] Fix | Delete
}
[87] Fix | Delete
[88] Fix | Delete
/*
[89] Fix | Delete
* If the original URL ended with non-breaking spaces, they were almost
[90] Fix | Delete
* certainly inserted by accident. Let's remove them, so the reader doesn't
[91] Fix | Delete
* see a 404 error with no obvious cause.
[92] Fix | Delete
*/
[93] Fix | Delete
$redirect['path'] = preg_replace( '|(%C2%A0)+$|i', '', $redirect['path'] );
[94] Fix | Delete
[95] Fix | Delete
// It's not a preview, so remove it from URL.
[96] Fix | Delete
if ( get_query_var( 'preview' ) ) {
[97] Fix | Delete
$redirect['query'] = remove_query_arg( 'preview', $redirect['query'] );
[98] Fix | Delete
}
[99] Fix | Delete
[100] Fix | Delete
$post_id = get_query_var( 'p' );
[101] Fix | Delete
[102] Fix | Delete
if ( is_feed() && $post_id ) {
[103] Fix | Delete
$redirect_url = get_post_comments_feed_link( $post_id, get_query_var( 'feed' ) );
[104] Fix | Delete
$redirect_obj = get_post( $post_id );
[105] Fix | Delete
[106] Fix | Delete
if ( $redirect_url ) {
[107] Fix | Delete
$redirect['query'] = _remove_qs_args_if_not_in_url(
[108] Fix | Delete
$redirect['query'],
[109] Fix | Delete
array( 'p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type', 'feed' ),
[110] Fix | Delete
$redirect_url
[111] Fix | Delete
);
[112] Fix | Delete
[113] Fix | Delete
$redirect['path'] = parse_url( $redirect_url, PHP_URL_PATH );
[114] Fix | Delete
}
[115] Fix | Delete
}
[116] Fix | Delete
[117] Fix | Delete
if ( is_singular() && $wp_query->post_count < 1 && $post_id ) {
[118] Fix | Delete
[119] Fix | Delete
$vars = $wpdb->get_results( $wpdb->prepare( "SELECT post_type, post_parent FROM $wpdb->posts WHERE ID = %d", $post_id ) );
[120] Fix | Delete
[121] Fix | Delete
if ( ! empty( $vars[0] ) ) {
[122] Fix | Delete
$vars = $vars[0];
[123] Fix | Delete
[124] Fix | Delete
if ( 'revision' === $vars->post_type && $vars->post_parent > 0 ) {
[125] Fix | Delete
$post_id = $vars->post_parent;
[126] Fix | Delete
}
[127] Fix | Delete
[128] Fix | Delete
$redirect_url = get_permalink( $post_id );
[129] Fix | Delete
$redirect_obj = get_post( $post_id );
[130] Fix | Delete
[131] Fix | Delete
if ( $redirect_url ) {
[132] Fix | Delete
$redirect['query'] = _remove_qs_args_if_not_in_url(
[133] Fix | Delete
$redirect['query'],
[134] Fix | Delete
array( 'p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type' ),
[135] Fix | Delete
$redirect_url
[136] Fix | Delete
);
[137] Fix | Delete
}
[138] Fix | Delete
}
[139] Fix | Delete
}
[140] Fix | Delete
[141] Fix | Delete
// These tests give us a WP-generated permalink.
[142] Fix | Delete
if ( is_404() ) {
[143] Fix | Delete
[144] Fix | Delete
// Redirect ?page_id, ?p=, ?attachment_id= to their respective URLs.
[145] Fix | Delete
$post_id = max( get_query_var( 'p' ), get_query_var( 'page_id' ), get_query_var( 'attachment_id' ) );
[146] Fix | Delete
[147] Fix | Delete
$redirect_post = $post_id ? get_post( $post_id ) : false;
[148] Fix | Delete
[149] Fix | Delete
if ( $redirect_post ) {
[150] Fix | Delete
$post_type_obj = get_post_type_object( $redirect_post->post_type );
[151] Fix | Delete
[152] Fix | Delete
if ( $post_type_obj && $post_type_obj->public && 'auto-draft' !== $redirect_post->post_status ) {
[153] Fix | Delete
$redirect_url = get_permalink( $redirect_post );
[154] Fix | Delete
$redirect_obj = get_post( $redirect_post );
[155] Fix | Delete
[156] Fix | Delete
$redirect['query'] = _remove_qs_args_if_not_in_url(
[157] Fix | Delete
$redirect['query'],
[158] Fix | Delete
array( 'p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type' ),
[159] Fix | Delete
$redirect_url
[160] Fix | Delete
);
[161] Fix | Delete
}
[162] Fix | Delete
}
[163] Fix | Delete
[164] Fix | Delete
$year = get_query_var( 'year' );
[165] Fix | Delete
$month = get_query_var( 'monthnum' );
[166] Fix | Delete
$day = get_query_var( 'day' );
[167] Fix | Delete
[168] Fix | Delete
if ( $year && $month && $day ) {
[169] Fix | Delete
$date = sprintf( '%04d-%02d-%02d', $year, $month, $day );
[170] Fix | Delete
[171] Fix | Delete
if ( ! wp_checkdate( $month, $day, $year, $date ) ) {
[172] Fix | Delete
$redirect_url = get_month_link( $year, $month );
[173] Fix | Delete
[174] Fix | Delete
$redirect['query'] = _remove_qs_args_if_not_in_url(
[175] Fix | Delete
$redirect['query'],
[176] Fix | Delete
array( 'year', 'monthnum', 'day' ),
[177] Fix | Delete
$redirect_url
[178] Fix | Delete
);
[179] Fix | Delete
}
[180] Fix | Delete
} elseif ( $year && $month && $month > 12 ) {
[181] Fix | Delete
$redirect_url = get_year_link( $year );
[182] Fix | Delete
[183] Fix | Delete
$redirect['query'] = _remove_qs_args_if_not_in_url(
[184] Fix | Delete
$redirect['query'],
[185] Fix | Delete
array( 'year', 'monthnum' ),
[186] Fix | Delete
$redirect_url
[187] Fix | Delete
);
[188] Fix | Delete
}
[189] Fix | Delete
[190] Fix | Delete
// Strip off non-existing <!--nextpage--> links from single posts or pages.
[191] Fix | Delete
if ( get_query_var( 'page' ) ) {
[192] Fix | Delete
$post_id = 0;
[193] Fix | Delete
[194] Fix | Delete
if ( $wp_query->queried_object instanceof WP_Post ) {
[195] Fix | Delete
$post_id = $wp_query->queried_object->ID;
[196] Fix | Delete
} elseif ( $wp_query->post ) {
[197] Fix | Delete
$post_id = $wp_query->post->ID;
[198] Fix | Delete
}
[199] Fix | Delete
[200] Fix | Delete
if ( $post_id ) {
[201] Fix | Delete
$redirect_url = get_permalink( $post_id );
[202] Fix | Delete
$redirect_obj = get_post( $post_id );
[203] Fix | Delete
[204] Fix | Delete
$redirect['path'] = rtrim( $redirect['path'], (int) get_query_var( 'page' ) . '/' );
[205] Fix | Delete
$redirect['query'] = remove_query_arg( 'page', $redirect['query'] );
[206] Fix | Delete
}
[207] Fix | Delete
}
[208] Fix | Delete
[209] Fix | Delete
if ( ! $redirect_url ) {
[210] Fix | Delete
$redirect_url = redirect_guess_404_permalink();
[211] Fix | Delete
[212] Fix | Delete
if ( $redirect_url ) {
[213] Fix | Delete
$redirect['query'] = _remove_qs_args_if_not_in_url(
[214] Fix | Delete
$redirect['query'],
[215] Fix | Delete
array( 'page', 'feed', 'p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type' ),
[216] Fix | Delete
$redirect_url
[217] Fix | Delete
);
[218] Fix | Delete
}
[219] Fix | Delete
}
[220] Fix | Delete
} elseif ( is_object( $wp_rewrite ) && $wp_rewrite->using_permalinks() ) {
[221] Fix | Delete
[222] Fix | Delete
// Rewriting of old ?p=X, ?m=2004, ?m=200401, ?m=20040101.
[223] Fix | Delete
if ( is_attachment()
[224] Fix | Delete
&& ! array_diff( array_keys( $wp->query_vars ), array( 'attachment', 'attachment_id' ) )
[225] Fix | Delete
&& ! $redirect_url
[226] Fix | Delete
) {
[227] Fix | Delete
if ( ! empty( $_GET['attachment_id'] ) ) {
[228] Fix | Delete
$redirect_url = get_attachment_link( get_query_var( 'attachment_id' ) );
[229] Fix | Delete
$redirect_obj = get_post( get_query_var( 'attachment_id' ) );
[230] Fix | Delete
[231] Fix | Delete
if ( $redirect_url ) {
[232] Fix | Delete
$redirect['query'] = remove_query_arg( 'attachment_id', $redirect['query'] );
[233] Fix | Delete
}
[234] Fix | Delete
} else {
[235] Fix | Delete
$redirect_url = get_attachment_link();
[236] Fix | Delete
$redirect_obj = get_post();
[237] Fix | Delete
}
[238] Fix | Delete
} elseif ( is_single() && ! empty( $_GET['p'] ) && ! $redirect_url ) {
[239] Fix | Delete
$redirect_url = get_permalink( get_query_var( 'p' ) );
[240] Fix | Delete
$redirect_obj = get_post( get_query_var( 'p' ) );
[241] Fix | Delete
[242] Fix | Delete
if ( $redirect_url ) {
[243] Fix | Delete
$redirect['query'] = remove_query_arg( array( 'p', 'post_type' ), $redirect['query'] );
[244] Fix | Delete
}
[245] Fix | Delete
} elseif ( is_single() && ! empty( $_GET['name'] ) && ! $redirect_url ) {
[246] Fix | Delete
$redirect_url = get_permalink( $wp_query->get_queried_object_id() );
[247] Fix | Delete
$redirect_obj = get_post( $wp_query->get_queried_object_id() );
[248] Fix | Delete
[249] Fix | Delete
if ( $redirect_url ) {
[250] Fix | Delete
$redirect['query'] = remove_query_arg( 'name', $redirect['query'] );
[251] Fix | Delete
}
[252] Fix | Delete
} elseif ( is_page() && ! empty( $_GET['page_id'] ) && ! $redirect_url ) {
[253] Fix | Delete
$redirect_url = get_permalink( get_query_var( 'page_id' ) );
[254] Fix | Delete
$redirect_obj = get_post( get_query_var( 'page_id' ) );
[255] Fix | Delete
[256] Fix | Delete
if ( $redirect_url ) {
[257] Fix | Delete
$redirect['query'] = remove_query_arg( 'page_id', $redirect['query'] );
[258] Fix | Delete
}
[259] Fix | Delete
} elseif ( is_page() && ! is_feed() && ! $redirect_url
[260] Fix | Delete
&& 'page' === get_option( 'show_on_front' ) && get_queried_object_id() === (int) get_option( 'page_on_front' )
[261] Fix | Delete
) {
[262] Fix | Delete
$redirect_url = home_url( '/' );
[263] Fix | Delete
} elseif ( is_home() && ! empty( $_GET['page_id'] ) && ! $redirect_url
[264] Fix | Delete
&& 'page' === get_option( 'show_on_front' ) && get_query_var( 'page_id' ) === (int) get_option( 'page_for_posts' )
[265] Fix | Delete
) {
[266] Fix | Delete
$redirect_url = get_permalink( get_option( 'page_for_posts' ) );
[267] Fix | Delete
$redirect_obj = get_post( get_option( 'page_for_posts' ) );
[268] Fix | Delete
[269] Fix | Delete
if ( $redirect_url ) {
[270] Fix | Delete
$redirect['query'] = remove_query_arg( 'page_id', $redirect['query'] );
[271] Fix | Delete
}
[272] Fix | Delete
} elseif ( ! empty( $_GET['m'] ) && ( is_year() || is_month() || is_day() ) ) {
[273] Fix | Delete
$m = get_query_var( 'm' );
[274] Fix | Delete
[275] Fix | Delete
switch ( strlen( $m ) ) {
[276] Fix | Delete
case 4: // Yearly.
[277] Fix | Delete
$redirect_url = get_year_link( $m );
[278] Fix | Delete
break;
[279] Fix | Delete
case 6: // Monthly.
[280] Fix | Delete
$redirect_url = get_month_link( substr( $m, 0, 4 ), substr( $m, 4, 2 ) );
[281] Fix | Delete
break;
[282] Fix | Delete
case 8: // Daily.
[283] Fix | Delete
$redirect_url = get_day_link( substr( $m, 0, 4 ), substr( $m, 4, 2 ), substr( $m, 6, 2 ) );
[284] Fix | Delete
break;
[285] Fix | Delete
}
[286] Fix | Delete
[287] Fix | Delete
if ( $redirect_url ) {
[288] Fix | Delete
$redirect['query'] = remove_query_arg( 'm', $redirect['query'] );
[289] Fix | Delete
}
[290] Fix | Delete
// Now moving on to non ?m=X year/month/day links.
[291] Fix | Delete
} elseif ( is_date() ) {
[292] Fix | Delete
$year = get_query_var( 'year' );
[293] Fix | Delete
$month = get_query_var( 'monthnum' );
[294] Fix | Delete
$day = get_query_var( 'day' );
[295] Fix | Delete
[296] Fix | Delete
if ( is_day() && $year && $month && ! empty( $_GET['day'] ) ) {
[297] Fix | Delete
$redirect_url = get_day_link( $year, $month, $day );
[298] Fix | Delete
[299] Fix | Delete
if ( $redirect_url ) {
[300] Fix | Delete
$redirect['query'] = remove_query_arg( array( 'year', 'monthnum', 'day' ), $redirect['query'] );
[301] Fix | Delete
}
[302] Fix | Delete
} elseif ( is_month() && $year && ! empty( $_GET['monthnum'] ) ) {
[303] Fix | Delete
$redirect_url = get_month_link( $year, $month );
[304] Fix | Delete
[305] Fix | Delete
if ( $redirect_url ) {
[306] Fix | Delete
$redirect['query'] = remove_query_arg( array( 'year', 'monthnum' ), $redirect['query'] );
[307] Fix | Delete
}
[308] Fix | Delete
} elseif ( is_year() && ! empty( $_GET['year'] ) ) {
[309] Fix | Delete
$redirect_url = get_year_link( $year );
[310] Fix | Delete
[311] Fix | Delete
if ( $redirect_url ) {
[312] Fix | Delete
$redirect['query'] = remove_query_arg( 'year', $redirect['query'] );
[313] Fix | Delete
}
[314] Fix | Delete
}
[315] Fix | Delete
} elseif ( is_author() && ! empty( $_GET['author'] ) && preg_match( '|^[0-9]+$|', $_GET['author'] ) ) {
[316] Fix | Delete
$author = get_userdata( get_query_var( 'author' ) );
[317] Fix | Delete
[318] Fix | Delete
if ( false !== $author
[319] Fix | Delete
&& $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE $wpdb->posts.post_author = %d AND $wpdb->posts.post_status = 'publish' LIMIT 1", $author->ID ) )
[320] Fix | Delete
) {
[321] Fix | Delete
$redirect_url = get_author_posts_url( $author->ID, $author->user_nicename );
[322] Fix | Delete
$redirect_obj = $author;
[323] Fix | Delete
[324] Fix | Delete
if ( $redirect_url ) {
[325] Fix | Delete
$redirect['query'] = remove_query_arg( 'author', $redirect['query'] );
[326] Fix | Delete
}
[327] Fix | Delete
}
[328] Fix | Delete
} elseif ( is_category() || is_tag() || is_tax() ) { // Terms (tags/categories).
[329] Fix | Delete
$term_count = 0;
[330] Fix | Delete
[331] Fix | Delete
foreach ( $wp_query->tax_query->queried_terms as $tax_query ) {
[332] Fix | Delete
$term_count += count( $tax_query['terms'] );
[333] Fix | Delete
}
[334] Fix | Delete
[335] Fix | Delete
$obj = $wp_query->get_queried_object();
[336] Fix | Delete
[337] Fix | Delete
if ( $term_count <= 1 && ! empty( $obj->term_id ) ) {
[338] Fix | Delete
$tax_url = get_term_link( (int) $obj->term_id, $obj->taxonomy );
[339] Fix | Delete
[340] Fix | Delete
if ( $tax_url && ! is_wp_error( $tax_url ) ) {
[341] Fix | Delete
if ( ! empty( $redirect['query'] ) ) {
[342] Fix | Delete
// Strip taxonomy query vars off the URL.
[343] Fix | Delete
$qv_remove = array( 'term', 'taxonomy' );
[344] Fix | Delete
[345] Fix | Delete
if ( is_category() ) {
[346] Fix | Delete
$qv_remove[] = 'category_name';
[347] Fix | Delete
$qv_remove[] = 'cat';
[348] Fix | Delete
} elseif ( is_tag() ) {
[349] Fix | Delete
$qv_remove[] = 'tag';
[350] Fix | Delete
$qv_remove[] = 'tag_id';
[351] Fix | Delete
} else {
[352] Fix | Delete
// Custom taxonomies will have a custom query var, remove those too.
[353] Fix | Delete
$tax_obj = get_taxonomy( $obj->taxonomy );
[354] Fix | Delete
if ( false !== $tax_obj->query_var ) {
[355] Fix | Delete
$qv_remove[] = $tax_obj->query_var;
[356] Fix | Delete
}
[357] Fix | Delete
}
[358] Fix | Delete
[359] Fix | Delete
$rewrite_vars = array_diff( array_keys( $wp_query->query ), array_keys( $_GET ) );
[360] Fix | Delete
[361] Fix | Delete
// Check to see if all the query vars are coming from the rewrite, none are set via $_GET.
[362] Fix | Delete
if ( ! array_diff( $rewrite_vars, array_keys( $_GET ) ) ) {
[363] Fix | Delete
// Remove all of the per-tax query vars.
[364] Fix | Delete
$redirect['query'] = remove_query_arg( $qv_remove, $redirect['query'] );
[365] Fix | Delete
[366] Fix | Delete
// Create the destination URL for this taxonomy.
[367] Fix | Delete
$tax_url = parse_url( $tax_url );
[368] Fix | Delete
[369] Fix | Delete
if ( ! empty( $tax_url['query'] ) ) {
[370] Fix | Delete
// Taxonomy accessible via ?taxonomy=...&term=... or any custom query var.
[371] Fix | Delete
parse_str( $tax_url['query'], $query_vars );
[372] Fix | Delete
$redirect['query'] = add_query_arg( $query_vars, $redirect['query'] );
[373] Fix | Delete
} else {
[374] Fix | Delete
// Taxonomy is accessible via a "pretty URL".
[375] Fix | Delete
$redirect['path'] = $tax_url['path'];
[376] Fix | Delete
}
[377] Fix | Delete
} else {
[378] Fix | Delete
// Some query vars are set via $_GET. Unset those from $_GET that exist via the rewrite.
[379] Fix | Delete
foreach ( $qv_remove as $_qv ) {
[380] Fix | Delete
if ( isset( $rewrite_vars[ $_qv ] ) ) {
[381] Fix | Delete
$redirect['query'] = remove_query_arg( $_qv, $redirect['query'] );
[382] Fix | Delete
}
[383] Fix | Delete
}
[384] Fix | Delete
}
[385] Fix | Delete
}
[386] Fix | Delete
}
[387] Fix | Delete
}
[388] Fix | Delete
} elseif ( is_single() && strpos( $wp_rewrite->permalink_structure, '%category%' ) !== false ) {
[389] Fix | Delete
$category_name = get_query_var( 'category_name' );
[390] Fix | Delete
[391] Fix | Delete
if ( $category_name ) {
[392] Fix | Delete
$category = get_category_by_path( $category_name );
[393] Fix | Delete
[394] Fix | Delete
if ( ! $category || is_wp_error( $category )
[395] Fix | Delete
|| ! has_term( $category->term_id, 'category', $wp_query->get_queried_object_id() )
[396] Fix | Delete
) {
[397] Fix | Delete
$redirect_url = get_permalink( $wp_query->get_queried_object_id() );
[398] Fix | Delete
$redirect_obj = get_post( $wp_query->get_queried_object_id() );
[399] Fix | Delete
}
[400] Fix | Delete
}
[401] Fix | Delete
}
[402] Fix | Delete
[403] Fix | Delete
// Post paging.
[404] Fix | Delete
if ( is_singular() && get_query_var( 'page' ) ) {
[405] Fix | Delete
$page = get_query_var( 'page' );
[406] Fix | Delete
[407] Fix | Delete
if ( ! $redirect_url ) {
[408] Fix | Delete
$redirect_url = get_permalink( get_queried_object_id() );
[409] Fix | Delete
$redirect_obj = get_post( get_queried_object_id() );
[410] Fix | Delete
}
[411] Fix | Delete
[412] Fix | Delete
if ( $page > 1 ) {
[413] Fix | Delete
$redirect_url = trailingslashit( $redirect_url );
[414] Fix | Delete
[415] Fix | Delete
if ( is_front_page() ) {
[416] Fix | Delete
$redirect_url .= user_trailingslashit( "$wp_rewrite->pagination_base/$page", 'paged' );
[417] Fix | Delete
} else {
[418] Fix | Delete
$redirect_url .= user_trailingslashit( $page, 'single_paged' );
[419] Fix | Delete
}
[420] Fix | Delete
}
[421] Fix | Delete
[422] Fix | Delete
$redirect['query'] = remove_query_arg( 'page', $redirect['query'] );
[423] Fix | Delete
}
[424] Fix | Delete
[425] Fix | Delete
if ( get_query_var( 'sitemap' ) ) {
[426] Fix | Delete
$redirect_url = get_sitemap_url( get_query_var( 'sitemap' ), get_query_var( 'sitemap-subtype' ), get_query_var( 'paged' ) );
[427] Fix | Delete
$redirect['query'] = remove_query_arg( array( 'sitemap', 'sitemap-subtype', 'paged' ), $redirect['query'] );
[428] Fix | Delete
} elseif ( get_query_var( 'paged' ) || is_feed() || get_query_var( 'cpage' ) ) {
[429] Fix | Delete
// Paging and feeds.
[430] Fix | Delete
$paged = get_query_var( 'paged' );
[431] Fix | Delete
$feed = get_query_var( 'feed' );
[432] Fix | Delete
$cpage = get_query_var( 'cpage' );
[433] Fix | Delete
[434] Fix | Delete
while ( preg_match( "#/$wp_rewrite->pagination_base/?[0-9]+?(/+)?$#", $redirect['path'] )
[435] Fix | Delete
|| preg_match( '#/(comments/?)?(feed|rss2?|rdf|atom)(/+)?$#', $redirect['path'] )
[436] Fix | Delete
|| preg_match( "#/{$wp_rewrite->comments_pagination_base}-[0-9]+(/+)?$#", $redirect['path'] )
[437] Fix | Delete
) {
[438] Fix | Delete
// Strip off any existing paging.
[439] Fix | Delete
$redirect['path'] = preg_replace( "#/$wp_rewrite->pagination_base/?[0-9]+?(/+)?$#", '/', $redirect['path'] );
[440] Fix | Delete
// Strip off feed endings.
[441] Fix | Delete
$redirect['path'] = preg_replace( '#/(comments/?)?(feed|rss2?|rdf|atom)(/+|$)#', '/', $redirect['path'] );
[442] Fix | Delete
// Strip off any existing comment paging.
[443] Fix | Delete
$redirect['path'] = preg_replace( "#/{$wp_rewrite->comments_pagination_base}-[0-9]+?(/+)?$#", '/', $redirect['path'] );
[444] Fix | Delete
}
[445] Fix | Delete
[446] Fix | Delete
$addl_path = '';
[447] Fix | Delete
$default_feed = get_default_feed();
[448] Fix | Delete
[449] Fix | Delete
if ( is_feed() && in_array( $feed, $wp_rewrite->feeds, true ) ) {
[450] Fix | Delete
$addl_path = ! empty( $addl_path ) ? trailingslashit( $addl_path ) : '';
[451] Fix | Delete
[452] Fix | Delete
if ( ! is_singular() && get_query_var( 'withcomments' ) ) {
[453] Fix | Delete
$addl_path .= 'comments/';
[454] Fix | Delete
}
[455] Fix | Delete
[456] Fix | Delete
if ( ( 'rss' === $default_feed && 'feed' === $feed ) || 'rss' === $feed ) {
[457] Fix | Delete
$format = ( 'rss2' === $default_feed ) ? '' : 'rss2';
[458] Fix | Delete
} else {
[459] Fix | Delete
$format = ( $default_feed === $feed || 'feed' === $feed ) ? '' : $feed;
[460] Fix | Delete
}
[461] Fix | Delete
[462] Fix | Delete
$addl_path .= user_trailingslashit( 'feed/' . $format, 'feed' );
[463] Fix | Delete
[464] Fix | Delete
$redirect['query'] = remove_query_arg( 'feed', $redirect['query'] );
[465] Fix | Delete
} elseif ( is_feed() && 'old' === $feed ) {
[466] Fix | Delete
$old_feed_files = array(
[467] Fix | Delete
'wp-atom.php' => 'atom',
[468] Fix | Delete
'wp-commentsrss2.php' => 'comments_rss2',
[469] Fix | Delete
'wp-feed.php' => $default_feed,
[470] Fix | Delete
'wp-rdf.php' => 'rdf',
[471] Fix | Delete
'wp-rss.php' => 'rss2',
[472] Fix | Delete
'wp-rss2.php' => 'rss2',
[473] Fix | Delete
);
[474] Fix | Delete
[475] Fix | Delete
if ( isset( $old_feed_files[ basename( $redirect['path'] ) ] ) ) {
[476] Fix | Delete
$redirect_url = get_feed_link( $old_feed_files[ basename( $redirect['path'] ) ] );
[477] Fix | Delete
[478] Fix | Delete
wp_redirect( $redirect_url, 301 );
[479] Fix | Delete
die();
[480] Fix | Delete
}
[481] Fix | Delete
}
[482] Fix | Delete
[483] Fix | Delete
if ( $paged > 0 ) {
[484] Fix | Delete
$redirect['query'] = remove_query_arg( 'paged', $redirect['query'] );
[485] Fix | Delete
[486] Fix | Delete
if ( ! is_feed() ) {
[487] Fix | Delete
if ( ! is_single() ) {
[488] Fix | Delete
$addl_path = ! empty( $addl_path ) ? trailingslashit( $addl_path ) : '';
[489] Fix | Delete
[490] Fix | Delete
if ( $paged > 1 ) {
[491] Fix | Delete
$addl_path .= user_trailingslashit( "$wp_rewrite->pagination_base/$paged", 'paged' );
[492] Fix | Delete
}
[493] Fix | Delete
}
[494] Fix | Delete
} elseif ( $paged > 1 ) {
[495] Fix | Delete
$redirect['query'] = add_query_arg( 'paged', $paged, $redirect['query'] );
[496] Fix | Delete
}
[497] Fix | Delete
}
[498] Fix | Delete
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function