Edit File by line
/home/barbar84/www/wp-inclu...
File: canonical.php
$default_comments_page = get_option( 'default_comments_page' );
[500] Fix | Delete
[501] Fix | Delete
if ( get_option( 'page_comments' )
[502] Fix | Delete
&& ( 'newest' === $default_comments_page && $cpage > 0
[503] Fix | Delete
|| 'newest' !== $default_comments_page && $cpage > 1 )
[504] Fix | Delete
) {
[505] Fix | Delete
$addl_path = ( ! empty( $addl_path ) ? trailingslashit( $addl_path ) : '' );
[506] Fix | Delete
$addl_path .= user_trailingslashit( $wp_rewrite->comments_pagination_base . '-' . $cpage, 'commentpaged' );
[507] Fix | Delete
[508] Fix | Delete
$redirect['query'] = remove_query_arg( 'cpage', $redirect['query'] );
[509] Fix | Delete
}
[510] Fix | Delete
[511] Fix | Delete
// Strip off trailing /index.php/.
[512] Fix | Delete
$redirect['path'] = preg_replace( '|/' . preg_quote( $wp_rewrite->index, '|' ) . '/?$|', '/', $redirect['path'] );
[513] Fix | Delete
$redirect['path'] = user_trailingslashit( $redirect['path'] );
[514] Fix | Delete
[515] Fix | Delete
if ( ! empty( $addl_path )
[516] Fix | Delete
&& $wp_rewrite->using_index_permalinks()
[517] Fix | Delete
&& strpos( $redirect['path'], '/' . $wp_rewrite->index . '/' ) === false
[518] Fix | Delete
) {
[519] Fix | Delete
$redirect['path'] = trailingslashit( $redirect['path'] ) . $wp_rewrite->index . '/';
[520] Fix | Delete
}
[521] Fix | Delete
[522] Fix | Delete
if ( ! empty( $addl_path ) ) {
[523] Fix | Delete
$redirect['path'] = trailingslashit( $redirect['path'] ) . $addl_path;
[524] Fix | Delete
}
[525] Fix | Delete
[526] Fix | Delete
$redirect_url = $redirect['scheme'] . '://' . $redirect['host'] . $redirect['path'];
[527] Fix | Delete
}
[528] Fix | Delete
[529] Fix | Delete
if ( 'wp-register.php' === basename( $redirect['path'] ) ) {
[530] Fix | Delete
if ( is_multisite() ) {
[531] Fix | Delete
/** This filter is documented in wp-login.php */
[532] Fix | Delete
$redirect_url = apply_filters( 'wp_signup_location', network_site_url( 'wp-signup.php' ) );
[533] Fix | Delete
} else {
[534] Fix | Delete
$redirect_url = wp_registration_url();
[535] Fix | Delete
}
[536] Fix | Delete
[537] Fix | Delete
wp_redirect( $redirect_url, 301 );
[538] Fix | Delete
die();
[539] Fix | Delete
}
[540] Fix | Delete
}
[541] Fix | Delete
[542] Fix | Delete
$redirect['query'] = preg_replace( '#^\??&*?#', '', $redirect['query'] );
[543] Fix | Delete
[544] Fix | Delete
// Tack on any additional query vars.
[545] Fix | Delete
if ( $redirect_url && ! empty( $redirect['query'] ) ) {
[546] Fix | Delete
parse_str( $redirect['query'], $_parsed_query );
[547] Fix | Delete
$redirect = parse_url( $redirect_url );
[548] Fix | Delete
[549] Fix | Delete
if ( ! empty( $_parsed_query['name'] ) && ! empty( $redirect['query'] ) ) {
[550] Fix | Delete
parse_str( $redirect['query'], $_parsed_redirect_query );
[551] Fix | Delete
[552] Fix | Delete
if ( empty( $_parsed_redirect_query['name'] ) ) {
[553] Fix | Delete
unset( $_parsed_query['name'] );
[554] Fix | Delete
}
[555] Fix | Delete
}
[556] Fix | Delete
[557] Fix | Delete
$_parsed_query = array_combine(
[558] Fix | Delete
rawurlencode_deep( array_keys( $_parsed_query ) ),
[559] Fix | Delete
rawurlencode_deep( array_values( $_parsed_query ) )
[560] Fix | Delete
);
[561] Fix | Delete
[562] Fix | Delete
$redirect_url = add_query_arg( $_parsed_query, $redirect_url );
[563] Fix | Delete
}
[564] Fix | Delete
[565] Fix | Delete
if ( $redirect_url ) {
[566] Fix | Delete
$redirect = parse_url( $redirect_url );
[567] Fix | Delete
}
[568] Fix | Delete
[569] Fix | Delete
// www.example.com vs. example.com
[570] Fix | Delete
$user_home = parse_url( home_url() );
[571] Fix | Delete
[572] Fix | Delete
if ( ! empty( $user_home['host'] ) ) {
[573] Fix | Delete
$redirect['host'] = $user_home['host'];
[574] Fix | Delete
}
[575] Fix | Delete
[576] Fix | Delete
if ( empty( $user_home['path'] ) ) {
[577] Fix | Delete
$user_home['path'] = '/';
[578] Fix | Delete
}
[579] Fix | Delete
[580] Fix | Delete
// Handle ports.
[581] Fix | Delete
if ( ! empty( $user_home['port'] ) ) {
[582] Fix | Delete
$redirect['port'] = $user_home['port'];
[583] Fix | Delete
} else {
[584] Fix | Delete
unset( $redirect['port'] );
[585] Fix | Delete
}
[586] Fix | Delete
[587] Fix | Delete
// Trailing /index.php.
[588] Fix | Delete
$redirect['path'] = preg_replace( '|/' . preg_quote( $wp_rewrite->index, '|' ) . '/*?$|', '/', $redirect['path'] );
[589] Fix | Delete
[590] Fix | Delete
$punctuation_pattern = implode(
[591] Fix | Delete
'|',
[592] Fix | Delete
array_map(
[593] Fix | Delete
'preg_quote',
[594] Fix | Delete
array(
[595] Fix | Delete
' ',
[596] Fix | Delete
'%20', // Space.
[597] Fix | Delete
'!',
[598] Fix | Delete
'%21', // Exclamation mark.
[599] Fix | Delete
'"',
[600] Fix | Delete
'%22', // Double quote.
[601] Fix | Delete
"'",
[602] Fix | Delete
'%27', // Single quote.
[603] Fix | Delete
'(',
[604] Fix | Delete
'%28', // Opening bracket.
[605] Fix | Delete
')',
[606] Fix | Delete
'%29', // Closing bracket.
[607] Fix | Delete
',',
[608] Fix | Delete
'%2C', // Comma.
[609] Fix | Delete
'.',
[610] Fix | Delete
'%2E', // Period.
[611] Fix | Delete
';',
[612] Fix | Delete
'%3B', // Semicolon.
[613] Fix | Delete
'{',
[614] Fix | Delete
'%7B', // Opening curly bracket.
[615] Fix | Delete
'}',
[616] Fix | Delete
'%7D', // Closing curly bracket.
[617] Fix | Delete
'%E2%80%9C', // Opening curly quote.
[618] Fix | Delete
'%E2%80%9D', // Closing curly quote.
[619] Fix | Delete
)
[620] Fix | Delete
)
[621] Fix | Delete
);
[622] Fix | Delete
[623] Fix | Delete
// Remove trailing spaces and end punctuation from the path.
[624] Fix | Delete
$redirect['path'] = preg_replace( "#($punctuation_pattern)+$#", '', $redirect['path'] );
[625] Fix | Delete
[626] Fix | Delete
if ( ! empty( $redirect['query'] ) ) {
[627] Fix | Delete
// Remove trailing spaces and end punctuation from certain terminating query string args.
[628] Fix | Delete
$redirect['query'] = preg_replace( "#((^|&)(p|page_id|cat|tag)=[^&]*?)($punctuation_pattern)+$#", '$1', $redirect['query'] );
[629] Fix | Delete
[630] Fix | Delete
// Clean up empty query strings.
[631] Fix | Delete
$redirect['query'] = trim( preg_replace( '#(^|&)(p|page_id|cat|tag)=?(&|$)#', '&', $redirect['query'] ), '&' );
[632] Fix | Delete
[633] Fix | Delete
// Redirect obsolete feeds.
[634] Fix | Delete
$redirect['query'] = preg_replace( '#(^|&)feed=rss(&|$)#', '$1feed=rss2$2', $redirect['query'] );
[635] Fix | Delete
[636] Fix | Delete
// Remove redundant leading ampersands.
[637] Fix | Delete
$redirect['query'] = preg_replace( '#^\??&*?#', '', $redirect['query'] );
[638] Fix | Delete
}
[639] Fix | Delete
[640] Fix | Delete
// Strip /index.php/ when we're not using PATHINFO permalinks.
[641] Fix | Delete
if ( ! $wp_rewrite->using_index_permalinks() ) {
[642] Fix | Delete
$redirect['path'] = str_replace( '/' . $wp_rewrite->index . '/', '/', $redirect['path'] );
[643] Fix | Delete
}
[644] Fix | Delete
[645] Fix | Delete
// Trailing slashes.
[646] Fix | Delete
if ( is_object( $wp_rewrite ) && $wp_rewrite->using_permalinks()
[647] Fix | Delete
&& ! is_404() && ( ! is_front_page() || is_front_page() && get_query_var( 'paged' ) > 1 )
[648] Fix | Delete
) {
[649] Fix | Delete
$user_ts_type = '';
[650] Fix | Delete
[651] Fix | Delete
if ( get_query_var( 'paged' ) > 0 ) {
[652] Fix | Delete
$user_ts_type = 'paged';
[653] Fix | Delete
} else {
[654] Fix | Delete
foreach ( array( 'single', 'category', 'page', 'day', 'month', 'year', 'home' ) as $type ) {
[655] Fix | Delete
$func = 'is_' . $type;
[656] Fix | Delete
if ( call_user_func( $func ) ) {
[657] Fix | Delete
$user_ts_type = $type;
[658] Fix | Delete
break;
[659] Fix | Delete
}
[660] Fix | Delete
}
[661] Fix | Delete
}
[662] Fix | Delete
[663] Fix | Delete
$redirect['path'] = user_trailingslashit( $redirect['path'], $user_ts_type );
[664] Fix | Delete
} elseif ( is_front_page() ) {
[665] Fix | Delete
$redirect['path'] = trailingslashit( $redirect['path'] );
[666] Fix | Delete
}
[667] Fix | Delete
[668] Fix | Delete
// Remove trailing slash for robots.txt or sitemap requests.
[669] Fix | Delete
if ( is_robots()
[670] Fix | Delete
|| ! empty( get_query_var( 'sitemap' ) ) || ! empty( get_query_var( 'sitemap-stylesheet' ) )
[671] Fix | Delete
) {
[672] Fix | Delete
$redirect['path'] = untrailingslashit( $redirect['path'] );
[673] Fix | Delete
}
[674] Fix | Delete
[675] Fix | Delete
// Strip multiple slashes out of the URL.
[676] Fix | Delete
if ( strpos( $redirect['path'], '//' ) > -1 ) {
[677] Fix | Delete
$redirect['path'] = preg_replace( '|/+|', '/', $redirect['path'] );
[678] Fix | Delete
}
[679] Fix | Delete
[680] Fix | Delete
// Always trailing slash the Front Page URL.
[681] Fix | Delete
if ( trailingslashit( $redirect['path'] ) === trailingslashit( $user_home['path'] ) ) {
[682] Fix | Delete
$redirect['path'] = trailingslashit( $redirect['path'] );
[683] Fix | Delete
}
[684] Fix | Delete
[685] Fix | Delete
$original_host_low = strtolower( $original['host'] );
[686] Fix | Delete
$redirect_host_low = strtolower( $redirect['host'] );
[687] Fix | Delete
[688] Fix | Delete
// Ignore differences in host capitalization, as this can lead to infinite redirects.
[689] Fix | Delete
// Only redirect no-www <=> yes-www.
[690] Fix | Delete
if ( $original_host_low === $redirect_host_low
[691] Fix | Delete
|| ( 'www.' . $original_host_low !== $redirect_host_low
[692] Fix | Delete
&& 'www.' . $redirect_host_low !== $original_host_low )
[693] Fix | Delete
) {
[694] Fix | Delete
$redirect['host'] = $original['host'];
[695] Fix | Delete
}
[696] Fix | Delete
[697] Fix | Delete
$compare_original = array( $original['host'], $original['path'] );
[698] Fix | Delete
[699] Fix | Delete
if ( ! empty( $original['port'] ) ) {
[700] Fix | Delete
$compare_original[] = $original['port'];
[701] Fix | Delete
}
[702] Fix | Delete
[703] Fix | Delete
if ( ! empty( $original['query'] ) ) {
[704] Fix | Delete
$compare_original[] = $original['query'];
[705] Fix | Delete
}
[706] Fix | Delete
[707] Fix | Delete
$compare_redirect = array( $redirect['host'], $redirect['path'] );
[708] Fix | Delete
[709] Fix | Delete
if ( ! empty( $redirect['port'] ) ) {
[710] Fix | Delete
$compare_redirect[] = $redirect['port'];
[711] Fix | Delete
}
[712] Fix | Delete
[713] Fix | Delete
if ( ! empty( $redirect['query'] ) ) {
[714] Fix | Delete
$compare_redirect[] = $redirect['query'];
[715] Fix | Delete
}
[716] Fix | Delete
[717] Fix | Delete
if ( $compare_original !== $compare_redirect ) {
[718] Fix | Delete
$redirect_url = $redirect['scheme'] . '://' . $redirect['host'];
[719] Fix | Delete
[720] Fix | Delete
if ( ! empty( $redirect['port'] ) ) {
[721] Fix | Delete
$redirect_url .= ':' . $redirect['port'];
[722] Fix | Delete
}
[723] Fix | Delete
[724] Fix | Delete
$redirect_url .= $redirect['path'];
[725] Fix | Delete
[726] Fix | Delete
if ( ! empty( $redirect['query'] ) ) {
[727] Fix | Delete
$redirect_url .= '?' . $redirect['query'];
[728] Fix | Delete
}
[729] Fix | Delete
}
[730] Fix | Delete
[731] Fix | Delete
if ( ! $redirect_url || $redirect_url === $requested_url ) {
[732] Fix | Delete
return;
[733] Fix | Delete
}
[734] Fix | Delete
[735] Fix | Delete
// Hex encoded octets are case-insensitive.
[736] Fix | Delete
if ( false !== strpos( $requested_url, '%' ) ) {
[737] Fix | Delete
if ( ! function_exists( 'lowercase_octets' ) ) {
[738] Fix | Delete
/**
[739] Fix | Delete
* Converts the first hex-encoded octet match to lowercase.
[740] Fix | Delete
*
[741] Fix | Delete
* @since 3.1.0
[742] Fix | Delete
* @ignore
[743] Fix | Delete
*
[744] Fix | Delete
* @param array $matches Hex-encoded octet matches for the requested URL.
[745] Fix | Delete
* @return string Lowercased version of the first match.
[746] Fix | Delete
*/
[747] Fix | Delete
function lowercase_octets( $matches ) {
[748] Fix | Delete
return strtolower( $matches[0] );
[749] Fix | Delete
}
[750] Fix | Delete
}
[751] Fix | Delete
[752] Fix | Delete
$requested_url = preg_replace_callback( '|%[a-fA-F0-9][a-fA-F0-9]|', 'lowercase_octets', $requested_url );
[753] Fix | Delete
}
[754] Fix | Delete
[755] Fix | Delete
if ( $redirect_obj instanceof WP_Post ) {
[756] Fix | Delete
$post_status_obj = get_post_status_object( get_post_status( $redirect_obj ) );
[757] Fix | Delete
/*
[758] Fix | Delete
* Unset the redirect object and URL if they are not readable by the user.
[759] Fix | Delete
* This condition is a little confusing as the condition needs to pass if
[760] Fix | Delete
* the post is not readable by the user. That's why there are ! (not) conditions
[761] Fix | Delete
* throughout.
[762] Fix | Delete
*/
[763] Fix | Delete
if (
[764] Fix | Delete
// Private post statuses only redirect if the user can read them.
[765] Fix | Delete
! (
[766] Fix | Delete
$post_status_obj->private &&
[767] Fix | Delete
current_user_can( 'read_post', $redirect_obj->ID )
[768] Fix | Delete
) &&
[769] Fix | Delete
// For other posts, only redirect if publicly viewable.
[770] Fix | Delete
! is_post_publicly_viewable( $redirect_obj )
[771] Fix | Delete
) {
[772] Fix | Delete
$redirect_obj = false;
[773] Fix | Delete
$redirect_url = false;
[774] Fix | Delete
}
[775] Fix | Delete
}
[776] Fix | Delete
[777] Fix | Delete
/**
[778] Fix | Delete
* Filters the canonical redirect URL.
[779] Fix | Delete
*
[780] Fix | Delete
* Returning false to this filter will cancel the redirect.
[781] Fix | Delete
*
[782] Fix | Delete
* @since 2.3.0
[783] Fix | Delete
*
[784] Fix | Delete
* @param string $redirect_url The redirect URL.
[785] Fix | Delete
* @param string $requested_url The requested URL.
[786] Fix | Delete
*/
[787] Fix | Delete
$redirect_url = apply_filters( 'redirect_canonical', $redirect_url, $requested_url );
[788] Fix | Delete
[789] Fix | Delete
// Yes, again -- in case the filter aborted the request.
[790] Fix | Delete
if ( ! $redirect_url || strip_fragment_from_url( $redirect_url ) === strip_fragment_from_url( $requested_url ) ) {
[791] Fix | Delete
return;
[792] Fix | Delete
}
[793] Fix | Delete
[794] Fix | Delete
if ( $do_redirect ) {
[795] Fix | Delete
// Protect against chained redirects.
[796] Fix | Delete
if ( ! redirect_canonical( $redirect_url, false ) ) {
[797] Fix | Delete
wp_redirect( $redirect_url, 301 );
[798] Fix | Delete
exit;
[799] Fix | Delete
} else {
[800] Fix | Delete
// Debug.
[801] Fix | Delete
// die("1: $redirect_url<br />2: " . redirect_canonical( $redirect_url, false ) );
[802] Fix | Delete
return;
[803] Fix | Delete
}
[804] Fix | Delete
} else {
[805] Fix | Delete
return $redirect_url;
[806] Fix | Delete
}
[807] Fix | Delete
}
[808] Fix | Delete
[809] Fix | Delete
/**
[810] Fix | Delete
* Removes arguments from a query string if they are not present in a URL
[811] Fix | Delete
* DO NOT use this in plugin code.
[812] Fix | Delete
*
[813] Fix | Delete
* @since 3.4.0
[814] Fix | Delete
* @access private
[815] Fix | Delete
*
[816] Fix | Delete
* @param string $query_string
[817] Fix | Delete
* @param array $args_to_check
[818] Fix | Delete
* @param string $url
[819] Fix | Delete
* @return string The altered query string
[820] Fix | Delete
*/
[821] Fix | Delete
function _remove_qs_args_if_not_in_url( $query_string, array $args_to_check, $url ) {
[822] Fix | Delete
$parsed_url = parse_url( $url );
[823] Fix | Delete
[824] Fix | Delete
if ( ! empty( $parsed_url['query'] ) ) {
[825] Fix | Delete
parse_str( $parsed_url['query'], $parsed_query );
[826] Fix | Delete
[827] Fix | Delete
foreach ( $args_to_check as $qv ) {
[828] Fix | Delete
if ( ! isset( $parsed_query[ $qv ] ) ) {
[829] Fix | Delete
$query_string = remove_query_arg( $qv, $query_string );
[830] Fix | Delete
}
[831] Fix | Delete
}
[832] Fix | Delete
} else {
[833] Fix | Delete
$query_string = remove_query_arg( $args_to_check, $query_string );
[834] Fix | Delete
}
[835] Fix | Delete
[836] Fix | Delete
return $query_string;
[837] Fix | Delete
}
[838] Fix | Delete
[839] Fix | Delete
/**
[840] Fix | Delete
* Strips the #fragment from a URL, if one is present.
[841] Fix | Delete
*
[842] Fix | Delete
* @since 4.4.0
[843] Fix | Delete
*
[844] Fix | Delete
* @param string $url The URL to strip.
[845] Fix | Delete
* @return string The altered URL.
[846] Fix | Delete
*/
[847] Fix | Delete
function strip_fragment_from_url( $url ) {
[848] Fix | Delete
$parsed_url = parse_url( $url );
[849] Fix | Delete
[850] Fix | Delete
if ( ! empty( $parsed_url['host'] ) ) {
[851] Fix | Delete
// This mirrors code in redirect_canonical(). It does not handle every case.
[852] Fix | Delete
$url = $parsed_url['scheme'] . '://' . $parsed_url['host'];
[853] Fix | Delete
if ( ! empty( $parsed_url['port'] ) ) {
[854] Fix | Delete
$url .= ':' . $parsed_url['port'];
[855] Fix | Delete
}
[856] Fix | Delete
[857] Fix | Delete
if ( ! empty( $parsed_url['path'] ) ) {
[858] Fix | Delete
$url .= $parsed_url['path'];
[859] Fix | Delete
}
[860] Fix | Delete
[861] Fix | Delete
if ( ! empty( $parsed_url['query'] ) ) {
[862] Fix | Delete
$url .= '?' . $parsed_url['query'];
[863] Fix | Delete
}
[864] Fix | Delete
}
[865] Fix | Delete
[866] Fix | Delete
return $url;
[867] Fix | Delete
}
[868] Fix | Delete
[869] Fix | Delete
/**
[870] Fix | Delete
* Attempts to guess the correct URL for a 404 request based on query vars.
[871] Fix | Delete
*
[872] Fix | Delete
* @since 2.3.0
[873] Fix | Delete
*
[874] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[875] Fix | Delete
*
[876] Fix | Delete
* @return string|false The correct URL if one is found. False on failure.
[877] Fix | Delete
*/
[878] Fix | Delete
function redirect_guess_404_permalink() {
[879] Fix | Delete
global $wpdb;
[880] Fix | Delete
[881] Fix | Delete
/**
[882] Fix | Delete
* Filters whether to attempt to guess a redirect URL for a 404 request.
[883] Fix | Delete
*
[884] Fix | Delete
* Returning a false value from the filter will disable the URL guessing
[885] Fix | Delete
* and return early without performing a redirect.
[886] Fix | Delete
*
[887] Fix | Delete
* @since 5.5.0
[888] Fix | Delete
*
[889] Fix | Delete
* @param bool $do_redirect_guess Whether to attempt to guess a redirect URL
[890] Fix | Delete
* for a 404 request. Default true.
[891] Fix | Delete
*/
[892] Fix | Delete
if ( false === apply_filters( 'do_redirect_guess_404_permalink', true ) ) {
[893] Fix | Delete
return false;
[894] Fix | Delete
}
[895] Fix | Delete
[896] Fix | Delete
/**
[897] Fix | Delete
* Short-circuits the redirect URL guessing for 404 requests.
[898] Fix | Delete
*
[899] Fix | Delete
* Returning a non-null value from the filter will effectively short-circuit
[900] Fix | Delete
* the URL guessing, returning the passed value instead.
[901] Fix | Delete
*
[902] Fix | Delete
* @since 5.5.0
[903] Fix | Delete
*
[904] Fix | Delete
* @param null|string|false $pre Whether to short-circuit guessing the redirect for a 404.
[905] Fix | Delete
* Default null to continue with the URL guessing.
[906] Fix | Delete
*/
[907] Fix | Delete
$pre = apply_filters( 'pre_redirect_guess_404_permalink', null );
[908] Fix | Delete
if ( null !== $pre ) {
[909] Fix | Delete
return $pre;
[910] Fix | Delete
}
[911] Fix | Delete
[912] Fix | Delete
if ( get_query_var( 'name' ) ) {
[913] Fix | Delete
/**
[914] Fix | Delete
* Filters whether to perform a strict guess for a 404 redirect.
[915] Fix | Delete
*
[916] Fix | Delete
* Returning a truthy value from the filter will redirect only exact post_name matches.
[917] Fix | Delete
*
[918] Fix | Delete
* @since 5.5.0
[919] Fix | Delete
*
[920] Fix | Delete
* @param bool $strict_guess Whether to perform a strict guess. Default false (loose guess).
[921] Fix | Delete
*/
[922] Fix | Delete
$strict_guess = apply_filters( 'strict_redirect_guess_404_permalink', false );
[923] Fix | Delete
[924] Fix | Delete
if ( $strict_guess ) {
[925] Fix | Delete
$where = $wpdb->prepare( 'post_name = %s', get_query_var( 'name' ) );
[926] Fix | Delete
} else {
[927] Fix | Delete
$where = $wpdb->prepare( 'post_name LIKE %s', $wpdb->esc_like( get_query_var( 'name' ) ) . '%' );
[928] Fix | Delete
}
[929] Fix | Delete
[930] Fix | Delete
// If any of post_type, year, monthnum, or day are set, use them to refine the query.
[931] Fix | Delete
if ( get_query_var( 'post_type' ) ) {
[932] Fix | Delete
if ( is_array( get_query_var( 'post_type' ) ) ) {
[933] Fix | Delete
// phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
[934] Fix | Delete
$where .= " AND post_type IN ('" . join( "', '", esc_sql( get_query_var( 'post_type' ) ) ) . "')";
[935] Fix | Delete
} else {
[936] Fix | Delete
$where .= $wpdb->prepare( ' AND post_type = %s', get_query_var( 'post_type' ) );
[937] Fix | Delete
}
[938] Fix | Delete
} else {
[939] Fix | Delete
$where .= " AND post_type IN ('" . implode( "', '", get_post_types( array( 'public' => true ) ) ) . "')";
[940] Fix | Delete
}
[941] Fix | Delete
[942] Fix | Delete
if ( get_query_var( 'year' ) ) {
[943] Fix | Delete
$where .= $wpdb->prepare( ' AND YEAR(post_date) = %d', get_query_var( 'year' ) );
[944] Fix | Delete
}
[945] Fix | Delete
if ( get_query_var( 'monthnum' ) ) {
[946] Fix | Delete
$where .= $wpdb->prepare( ' AND MONTH(post_date) = %d', get_query_var( 'monthnum' ) );
[947] Fix | Delete
}
[948] Fix | Delete
if ( get_query_var( 'day' ) ) {
[949] Fix | Delete
$where .= $wpdb->prepare( ' AND DAYOFMONTH(post_date) = %d', get_query_var( 'day' ) );
[950] Fix | Delete
}
[951] Fix | Delete
[952] Fix | Delete
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
[953] Fix | Delete
$post_id = $wpdb->get_var( "SELECT ID FROM $wpdb->posts WHERE $where AND post_status = 'publish'" );
[954] Fix | Delete
[955] Fix | Delete
if ( ! $post_id ) {
[956] Fix | Delete
return false;
[957] Fix | Delete
}
[958] Fix | Delete
[959] Fix | Delete
if ( get_query_var( 'feed' ) ) {
[960] Fix | Delete
return get_post_comments_feed_link( $post_id, get_query_var( 'feed' ) );
[961] Fix | Delete
} elseif ( get_query_var( 'page' ) > 1 ) {
[962] Fix | Delete
return trailingslashit( get_permalink( $post_id ) ) . user_trailingslashit( get_query_var( 'page' ), 'single_paged' );
[963] Fix | Delete
} else {
[964] Fix | Delete
return get_permalink( $post_id );
[965] Fix | Delete
}
[966] Fix | Delete
}
[967] Fix | Delete
[968] Fix | Delete
return false;
[969] Fix | Delete
}
[970] Fix | Delete
[971] Fix | Delete
/**
[972] Fix | Delete
* Redirects a variety of shorthand URLs to the admin.
[973] Fix | Delete
*
[974] Fix | Delete
* If a user visits example.com/admin, they'll be redirected to /wp-admin.
[975] Fix | Delete
* Visiting /login redirects to /wp-login.php, and so on.
[976] Fix | Delete
*
[977] Fix | Delete
* @since 3.4.0
[978] Fix | Delete
*
[979] Fix | Delete
* @global WP_Rewrite $wp_rewrite WordPress rewrite component.
[980] Fix | Delete
*/
[981] Fix | Delete
function wp_redirect_admin_locations() {
[982] Fix | Delete
global $wp_rewrite;
[983] Fix | Delete
[984] Fix | Delete
if ( ! ( is_404() && $wp_rewrite->using_permalinks() ) ) {
[985] Fix | Delete
return;
[986] Fix | Delete
}
[987] Fix | Delete
[988] Fix | Delete
$admins = array(
[989] Fix | Delete
home_url( 'wp-admin', 'relative' ),
[990] Fix | Delete
home_url( 'dashboard', 'relative' ),
[991] Fix | Delete
home_url( 'admin', 'relative' ),
[992] Fix | Delete
site_url( 'dashboard', 'relative' ),
[993] Fix | Delete
site_url( 'admin', 'relative' ),
[994] Fix | Delete
);
[995] Fix | Delete
[996] Fix | Delete
if ( in_array( untrailingslashit( $_SERVER['REQUEST_URI'] ), $admins, true ) ) {
[997] Fix | Delete
wp_redirect( admin_url() );
[998] Fix | Delete
exit;
[999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function