<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[47759] trunk/src/wp-includes/canonical.php: Coding Standards: Fix WPCS issues in `wp-includes/canonical.php`.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/47759">47759</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/47759","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>SergeyBiryukov</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2020-05-04 09:03:11 +0000 (Mon, 04 May 2020)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Coding Standards: Fix WPCS issues in `wp-includes/canonical.php`.
Reformat long conditions and dense code blocks for better readability.
See <a href="https://core.trac.wordpress.org/ticket/49542">#49542</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludescanonicalphp">trunk/src/wp-includes/canonical.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludescanonicalphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/canonical.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/canonical.php 2020-05-04 02:44:44 UTC (rev 47758)
+++ trunk/src/wp-includes/canonical.php 2020-05-04 09:03:11 UTC (rev 47759)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -48,15 +48,19 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // If we're not in wp-admin and the post has been published and preview nonce
</span><span class="cx" style="display: block; padding: 0 10px"> // is non-existent or invalid then no need for preview in query.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( is_preview() && get_query_var( 'p' ) && 'publish' == get_post_status( get_query_var( 'p' ) ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( is_preview() && get_query_var( 'p' ) && 'publish' === get_post_status( get_query_var( 'p' ) ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! isset( $_GET['preview_id'] )
</span><span class="cx" style="display: block; padding: 0 10px"> || ! isset( $_GET['preview_nonce'] )
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- || ! wp_verify_nonce( $_GET['preview_nonce'], 'post_preview_' . (int) $_GET['preview_id'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ || ! wp_verify_nonce( $_GET['preview_nonce'], 'post_preview_' . (int) $_GET['preview_id'] )
+ ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $wp_query->is_preview = false;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( is_trackback() || is_search() || is_admin() || is_preview() || is_robots() || is_favicon() || ( $is_IIS && ! iis7_supports_permalinks() ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( is_admin() || is_search() || is_preview() || is_trackback()
+ || is_robots() || is_favicon()
+ || ( $is_IIS && ! iis7_supports_permalinks() )
+ ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -95,29 +99,41 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $redirect['query'] = remove_query_arg( 'preview', $redirect['query'] );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $id = get_query_var( 'p' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $post_id = get_query_var( 'p' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( is_feed() && $id ) {
- $redirect_url = get_post_comments_feed_link( $id, get_query_var( 'feed' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( is_feed() && $post_id ) {
+ $redirect_url = get_post_comments_feed_link( $post_id, get_query_var( 'feed' ) );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( $redirect_url ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $redirect['query'] = _remove_qs_args_if_not_in_url( $redirect['query'], array( 'p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type', 'feed' ), $redirect_url );
- $redirect['path'] = parse_url( $redirect_url, PHP_URL_PATH );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $redirect['query'] = _remove_qs_args_if_not_in_url(
+ $redirect['query'],
+ array( 'p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type', 'feed' ),
+ $redirect_url
+ );
+
+ $redirect['path'] = parse_url( $redirect_url, PHP_URL_PATH );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( is_singular() && 1 > $wp_query->post_count && $id ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( is_singular() && $wp_query->post_count < 1 && $post_id ) {
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $vars = $wpdb->get_results( $wpdb->prepare( "SELECT post_type, post_parent FROM $wpdb->posts WHERE ID = %d", $id ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $vars = $wpdb->get_results( $wpdb->prepare( "SELECT post_type, post_parent FROM $wpdb->posts WHERE ID = %d", $post_id ) );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! empty( $vars[0] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $vars = $vars[0];
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( 'revision' == $vars->post_type && $vars->post_parent > 0 ) {
- $id = $vars->post_parent;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ if ( 'revision' === $vars->post_type && $vars->post_parent > 0 ) {
+ $post_id = $vars->post_parent;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $redirect_url = get_permalink( $id );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $redirect_url = get_permalink( $post_id );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( $redirect_url ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $redirect['query'] = _remove_qs_args_if_not_in_url( $redirect['query'], array( 'p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type' ), $redirect_url );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $redirect['query'] = _remove_qs_args_if_not_in_url(
+ $redirect['query'],
+ array( 'p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type' ),
+ $redirect_url
+ );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -126,49 +142,79 @@
</span><span class="cx" style="display: block; padding: 0 10px"> if ( is_404() ) {
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Redirect ?page_id, ?p=, ?attachment_id= to their respective URLs.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $id = max( get_query_var( 'p' ), get_query_var( 'page_id' ), get_query_var( 'attachment_id' ) );
- $redirect_post = $id ? get_post( $id ) : false;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $post_id = max( get_query_var( 'p' ), get_query_var( 'page_id' ), get_query_var( 'attachment_id' ) );
+
+ $redirect_post = $post_id ? get_post( $post_id ) : false;
+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( $redirect_post ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $post_type_obj = get_post_type_object( $redirect_post->post_type );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( $post_type_obj->public && 'auto-draft' != $redirect_post->post_status ) {
- $redirect_url = get_permalink( $redirect_post );
- $redirect['query'] = _remove_qs_args_if_not_in_url( $redirect['query'], array( 'p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type' ), $redirect_url );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ if ( $post_type_obj->public && 'auto-draft' !== $redirect_post->post_status ) {
+ $redirect_url = get_permalink( $redirect_post );
+
+ $redirect['query'] = _remove_qs_args_if_not_in_url(
+ $redirect['query'],
+ array( 'p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type' ),
+ $redirect_url
+ );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( get_query_var( 'day' ) && get_query_var( 'monthnum' ) && get_query_var( 'year' ) ) {
- $year = get_query_var( 'year' );
- $month = get_query_var( 'monthnum' );
- $day = get_query_var( 'day' );
- $date = sprintf( '%04d-%02d-%02d', $year, $month, $day );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $year = get_query_var( 'year' );
+ $month = get_query_var( 'monthnum' );
+ $day = get_query_var( 'day' );
+
+ if ( $year && $month && $day ) {
+ $date = sprintf( '%04d-%02d-%02d', $year, $month, $day );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! wp_checkdate( $month, $day, $year, $date ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $redirect_url = get_month_link( $year, $month );
- $redirect['query'] = _remove_qs_args_if_not_in_url( $redirect['query'], array( 'year', 'monthnum', 'day' ), $redirect_url );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $redirect_url = get_month_link( $year, $month );
+
+ $redirect['query'] = _remove_qs_args_if_not_in_url(
+ $redirect['query'],
+ array( 'year', 'monthnum', 'day' ),
+ $redirect_url
+ );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- } elseif ( get_query_var( 'monthnum' ) && get_query_var( 'year' ) && 12 < get_query_var( 'monthnum' ) ) {
- $redirect_url = get_year_link( get_query_var( 'year' ) );
- $redirect['query'] = _remove_qs_args_if_not_in_url( $redirect['query'], array( 'year', 'monthnum' ), $redirect_url );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ } elseif ( $year && $month && $month > 12 ) {
+ $redirect_url = get_year_link( $year );
+
+ $redirect['query'] = _remove_qs_args_if_not_in_url(
+ $redirect['query'],
+ array( 'year', 'monthnum' ),
+ $redirect_url
+ );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! $redirect_url ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $redirect_url = redirect_guess_404_permalink();
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( $redirect_url ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $redirect['query'] = _remove_qs_args_if_not_in_url( $redirect['query'], array( 'page', 'feed', 'p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type' ), $redirect_url );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $redirect['query'] = _remove_qs_args_if_not_in_url(
+ $redirect['query'],
+ array( 'page', 'feed', 'p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type' ),
+ $redirect_url
+ );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Strip off non-existing page links from single posts or pages.
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( get_query_var( 'page' ) && $wp_query->post ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $redirect['path'] = rtrim( $redirect['path'], (int) get_query_var( 'page' ) . '/' );
</span><span class="cx" style="display: block; padding: 0 10px"> $redirect['query'] = remove_query_arg( 'page', $redirect['query'] );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $redirect_url = get_permalink( $wp_query->post->ID );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ $redirect_url = get_permalink( $wp_query->post->ID );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> } elseif ( is_object( $wp_rewrite ) && $wp_rewrite->using_permalinks() ) {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> // Rewriting of old ?p=X, ?m=2004, ?m=200401, ?m=20040101.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( is_attachment() &&
- ! array_diff( array_keys( $wp->query_vars ), array( 'attachment', 'attachment_id' ) ) &&
- ! $redirect_url ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( is_attachment()
+ && ! array_diff( array_keys( $wp->query_vars ), array( 'attachment', 'attachment_id' ) )
+ && ! $redirect_url
+ ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! empty( $_GET['attachment_id'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $redirect_url = get_attachment_link( get_query_var( 'attachment_id' ) );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( $redirect_url ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $redirect['query'] = remove_query_arg( 'attachment_id', $redirect['query'] );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -177,28 +223,37 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> } elseif ( is_single() && ! empty( $_GET['p'] ) && ! $redirect_url ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $redirect_url = get_permalink( get_query_var( 'p' ) );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( $redirect_url ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $redirect['query'] = remove_query_arg( array( 'p', 'post_type' ), $redirect['query'] );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> } elseif ( is_single() && ! empty( $_GET['name'] ) && ! $redirect_url ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $redirect_url = get_permalink( $wp_query->get_queried_object_id() );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( $redirect_url ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $redirect['query'] = remove_query_arg( 'name', $redirect['query'] );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> } elseif ( is_page() && ! empty( $_GET['page_id'] ) && ! $redirect_url ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $redirect_url = get_permalink( get_query_var( 'page_id' ) );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( $redirect_url ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $redirect['query'] = remove_query_arg( 'page_id', $redirect['query'] );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- } elseif ( is_page() && ! is_feed() && 'page' == get_option( 'show_on_front' ) && get_queried_object_id() == get_option( 'page_on_front' ) && ! $redirect_url ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ } elseif ( is_page() && ! is_feed() && ! $redirect_url
+ && 'page' === get_option( 'show_on_front' ) && get_queried_object_id() === (int) get_option( 'page_on_front' )
+ ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $redirect_url = home_url( '/' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- } elseif ( is_home() && ! empty( $_GET['page_id'] ) && 'page' == get_option( 'show_on_front' ) && get_query_var( 'page_id' ) == get_option( 'page_for_posts' ) && ! $redirect_url ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ } elseif ( is_home() && ! empty( $_GET['page_id'] ) && ! $redirect_url
+ && 'page' === get_option( 'show_on_front' ) && get_query_var( 'page_id' ) === (int) get_option( 'page_for_posts' )
+ ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $redirect_url = get_permalink( get_option( 'page_for_posts' ) );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( $redirect_url ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $redirect['query'] = remove_query_arg( 'page_id', $redirect['query'] );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> } elseif ( ! empty( $_GET['m'] ) && ( is_year() || is_month() || is_day() ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $m = get_query_var( 'm' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> switch ( strlen( $m ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> case 4: // Yearly.
</span><span class="cx" style="display: block; padding: 0 10px"> $redirect_url = get_year_link( $m );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -210,47 +265,64 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $redirect_url = get_day_link( substr( $m, 0, 4 ), substr( $m, 4, 2 ), substr( $m, 6, 2 ) );
</span><span class="cx" style="display: block; padding: 0 10px"> break;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( $redirect_url ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $redirect['query'] = remove_query_arg( 'm', $redirect['query'] );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> // Now moving on to non ?m=X year/month/day links.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- } elseif ( is_day() && get_query_var( 'year' ) && get_query_var( 'monthnum' ) && ! empty( $_GET['day'] ) ) {
- $redirect_url = get_day_link( get_query_var( 'year' ), get_query_var( 'monthnum' ), get_query_var( 'day' ) );
- if ( $redirect_url ) {
- $redirect['query'] = remove_query_arg( array( 'year', 'monthnum', 'day' ), $redirect['query'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ } elseif ( is_date() ) {
+ $year = get_query_var( 'year' );
+ $month = get_query_var( 'monthnum' );
+ $day = get_query_var( 'day' );
+
+ if ( is_day() && $year && $month && ! empty( $_GET['day'] ) ) {
+ $redirect_url = get_day_link( $year, $month, $day );
+
+ if ( $redirect_url ) {
+ $redirect['query'] = remove_query_arg( array( 'year', 'monthnum', 'day' ), $redirect['query'] );
+ }
+ } elseif ( is_month() && $year && ! empty( $_GET['monthnum'] ) ) {
+ $redirect_url = get_month_link( $year, $month );
+
+ if ( $redirect_url ) {
+ $redirect['query'] = remove_query_arg( array( 'year', 'monthnum' ), $redirect['query'] );
+ }
+ } elseif ( is_year() && ! empty( $_GET['year'] ) ) {
+ $redirect_url = get_year_link( $year );
+
+ if ( $redirect_url ) {
+ $redirect['query'] = remove_query_arg( 'year', $redirect['query'] );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- } elseif ( is_month() && get_query_var( 'year' ) && ! empty( $_GET['monthnum'] ) ) {
- $redirect_url = get_month_link( get_query_var( 'year' ), get_query_var( 'monthnum' ) );
- if ( $redirect_url ) {
- $redirect['query'] = remove_query_arg( array( 'year', 'monthnum' ), $redirect['query'] );
- }
- } elseif ( is_year() && ! empty( $_GET['year'] ) ) {
- $redirect_url = get_year_link( get_query_var( 'year' ) );
- if ( $redirect_url ) {
- $redirect['query'] = remove_query_arg( 'year', $redirect['query'] );
- }
</del><span class="cx" style="display: block; padding: 0 10px"> } elseif ( is_author() && ! empty( $_GET['author'] ) && preg_match( '|^[0-9]+$|', $_GET['author'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $author = get_userdata( get_query_var( 'author' ) );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ( false !== $author ) && $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 ) ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ if ( false !== $author
+ && $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 ) )
+ ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $redirect_url = get_author_posts_url( $author->ID, $author->user_nicename );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( $redirect_url ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $redirect['query'] = remove_query_arg( 'author', $redirect['query'] );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> } elseif ( is_category() || is_tag() || is_tax() ) { // Terms (tags/categories).
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $term_count = 0;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $term_count = 0;
</del><span class="cx" style="display: block; padding: 0 10px"> foreach ( $wp_query->tax_query->queried_terms as $tax_query ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $term_count += count( $tax_query['terms'] );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $obj = $wp_query->get_queried_object();
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( $term_count <= 1 && ! empty( $obj->term_id ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $tax_url = get_term_link( (int) $obj->term_id, $obj->taxonomy );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( $tax_url && ! is_wp_error( $tax_url ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! empty( $redirect['query'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> // Strip taxonomy query vars off the URL.
</span><span class="cx" style="display: block; padding: 0 10px"> $qv_remove = array( 'term', 'taxonomy' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( is_category() ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $qv_remove[] = 'category_name';
</span><span class="cx" style="display: block; padding: 0 10px"> $qv_remove[] = 'cat';
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -274,6 +346,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Create the destination URL for this taxonomy.
</span><span class="cx" style="display: block; padding: 0 10px"> $tax_url = parse_url( $tax_url );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! empty( $tax_url['query'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> // Taxonomy accessible via ?taxonomy=...&term=... or any custom query var.
</span><span class="cx" style="display: block; padding: 0 10px"> parse_str( $tax_url['query'], $query_vars );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -294,77 +367,105 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> } elseif ( is_single() && strpos( $wp_rewrite->permalink_structure, '%category%' ) !== false ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $cat = get_query_var( 'category_name' );
- if ( $cat ) {
- $category = get_category_by_path( $cat );
- if ( ( ! $category || is_wp_error( $category ) ) || ! has_term( $category->term_id, 'category', $wp_query->get_queried_object_id() ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $category_name = get_query_var( 'category_name' );
+
+ if ( $category_name ) {
+ $category = get_category_by_path( $category_name );
+
+ if ( ! $category || is_wp_error( $category )
+ || ! has_term( $category->term_id, 'category', $wp_query->get_queried_object_id() )
+ ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $redirect_url = get_permalink( $wp_query->get_queried_object_id() );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Post paging.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Post paging.
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( is_singular() && get_query_var( 'page' ) ) {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $page = get_query_var( 'page' );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! $redirect_url ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $redirect_url = get_permalink( get_queried_object_id() );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $page = get_query_var( 'page' );
</del><span class="cx" style="display: block; padding: 0 10px"> if ( $page > 1 ) {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $redirect_url = trailingslashit( $redirect_url );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( is_front_page() ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $redirect_url = trailingslashit( $redirect_url ) . user_trailingslashit( "$wp_rewrite->pagination_base/$page", 'paged' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $redirect_url .= user_trailingslashit( "$wp_rewrite->pagination_base/$page", 'paged' );
</ins><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $redirect_url = trailingslashit( $redirect_url ) . user_trailingslashit( $page, 'single_paged' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $redirect_url .= user_trailingslashit( $page, 'single_paged' );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $redirect['query'] = remove_query_arg( 'page', $redirect['query'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ $redirect['query'] = remove_query_arg( 'page', $redirect['query'] );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Paging and feeds.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Paging and feeds.
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( get_query_var( 'paged' ) || is_feed() || get_query_var( 'cpage' ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- while ( preg_match( "#/$wp_rewrite->pagination_base/?[0-9]+?(/+)?$#", $redirect['path'] ) || preg_match( '#/(comments/?)?(feed|rss|rdf|atom|rss2)(/+)?$#', $redirect['path'] ) || preg_match( "#/{$wp_rewrite->comments_pagination_base}-[0-9]+(/+)?$#", $redirect['path'] ) ) {
- // Strip off paging and feed.
- $redirect['path'] = preg_replace( "#/$wp_rewrite->pagination_base/?[0-9]+?(/+)?$#", '/', $redirect['path'] ); // Strip off any existing paging.
- $redirect['path'] = preg_replace( '#/(comments/?)?(feed|rss2?|rdf|atom)(/+|$)#', '/', $redirect['path'] ); // Strip off feed endings.
- $redirect['path'] = preg_replace( "#/{$wp_rewrite->comments_pagination_base}-[0-9]+?(/+)?$#", '/', $redirect['path'] ); // Strip off any existing comment paging.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $paged = get_query_var( 'paged' );
+ $feed = get_query_var( 'feed' );
+ $cpage = get_query_var( 'cpage' );
+
+ while ( preg_match( "#/$wp_rewrite->pagination_base/?[0-9]+?(/+)?$#", $redirect['path'] )
+ || preg_match( '#/(comments/?)?(feed|rss2?|rdf|atom)(/+)?$#', $redirect['path'] )
+ || preg_match( "#/{$wp_rewrite->comments_pagination_base}-[0-9]+(/+)?$#", $redirect['path'] )
+ ) {
+ // Strip off any existing paging.
+ $redirect['path'] = preg_replace( "#/$wp_rewrite->pagination_base/?[0-9]+?(/+)?$#", '/', $redirect['path'] );
+ // Strip off feed endings.
+ $redirect['path'] = preg_replace( '#/(comments/?)?(feed|rss2?|rdf|atom)(/+|$)#', '/', $redirect['path'] );
+ // Strip off any existing comment paging.
+ $redirect['path'] = preg_replace( "#/{$wp_rewrite->comments_pagination_base}-[0-9]+?(/+)?$#", '/', $redirect['path'] );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $addl_path = '';
- if ( is_feed() && in_array( get_query_var( 'feed' ), $wp_rewrite->feeds, true ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $addl_path = '';
+ $default_feed = get_default_feed();
+
+ if ( is_feed() && in_array( $feed, $wp_rewrite->feeds, true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $addl_path = ! empty( $addl_path ) ? trailingslashit( $addl_path ) : '';
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! is_singular() && get_query_var( 'withcomments' ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $addl_path .= 'comments/';
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ( 'rss' == get_default_feed() && 'feed' == get_query_var( 'feed' ) ) || 'rss' == get_query_var( 'feed' ) ) {
- $addl_path .= user_trailingslashit( 'feed/' . ( ( get_default_feed() == 'rss2' ) ? '' : 'rss2' ), 'feed' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ if ( ( 'rss' === $default_feed && 'feed' === $feed ) || 'rss' === $feed ) {
+ $format = ( 'rss2' === $default_feed ) ? '' : 'rss2';
</ins><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $addl_path .= user_trailingslashit( 'feed/' . ( ( get_default_feed() == get_query_var( 'feed' ) || 'feed' == get_query_var( 'feed' ) ) ? '' : get_query_var( 'feed' ) ), 'feed' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $format = ( $default_feed === $feed || 'feed' === $feed ) ? '' : $feed;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ $addl_path .= user_trailingslashit( 'feed/' . $format, 'feed' );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> $redirect['query'] = remove_query_arg( 'feed', $redirect['query'] );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- } elseif ( is_feed() && 'old' == get_query_var( 'feed' ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ } elseif ( is_feed() && 'old' === $feed ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $old_feed_files = array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'wp-atom.php' => 'atom',
</span><span class="cx" style="display: block; padding: 0 10px"> 'wp-commentsrss2.php' => 'comments_rss2',
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'wp-feed.php' => get_default_feed(),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'wp-feed.php' => $default_feed,
</ins><span class="cx" style="display: block; padding: 0 10px"> 'wp-rdf.php' => 'rdf',
</span><span class="cx" style="display: block; padding: 0 10px"> 'wp-rss.php' => 'rss2',
</span><span class="cx" style="display: block; padding: 0 10px"> 'wp-rss2.php' => 'rss2',
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( isset( $old_feed_files[ basename( $redirect['path'] ) ] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $redirect_url = get_feed_link( $old_feed_files[ basename( $redirect['path'] ) ] );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> wp_redirect( $redirect_url, 301 );
</span><span class="cx" style="display: block; padding: 0 10px"> die();
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( get_query_var( 'paged' ) > 0 ) {
- $paged = get_query_var( 'paged' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( $paged > 0 ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $redirect['query'] = remove_query_arg( 'paged', $redirect['query'] );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! is_feed() ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( $paged > 1 && ! is_single() ) {
- $addl_path = ( ! empty( $addl_path ) ? trailingslashit( $addl_path ) : '' ) . user_trailingslashit( "$wp_rewrite->pagination_base/$paged", 'paged' );
- } elseif ( ! is_single() ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! is_single() ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $addl_path = ! empty( $addl_path ) ? trailingslashit( $addl_path ) : '';
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ if ( $paged > 1 ) {
+ $addl_path .= user_trailingslashit( "$wp_rewrite->pagination_base/$paged", 'paged' );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> } elseif ( $paged > 1 ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $redirect['query'] = add_query_arg( 'paged', $paged, $redirect['query'] );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -371,25 +472,37 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( get_option( 'page_comments' ) && (
- ( 'newest' == get_option( 'default_comments_page' ) && get_query_var( 'cpage' ) > 0 ) ||
- ( 'newest' != get_option( 'default_comments_page' ) && get_query_var( 'cpage' ) > 1 )
- ) ) {
- $addl_path = ( ! empty( $addl_path ) ? trailingslashit( $addl_path ) : '' ) . user_trailingslashit( $wp_rewrite->comments_pagination_base . '-' . get_query_var( 'cpage' ), 'commentpaged' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $default_comments_page = get_option( 'default_comments_page' );
+
+ if ( get_option( 'page_comments' )
+ && ( 'newest' === $default_comments_page && $cpage > 0
+ || 'newest' !== $default_comments_page && $cpage > 1 )
+ ) {
+ $addl_path = ( ! empty( $addl_path ) ? trailingslashit( $addl_path ) : '' );
+ $addl_path .= user_trailingslashit( $wp_rewrite->comments_pagination_base . '-' . $cpage, 'commentpaged' );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> $redirect['query'] = remove_query_arg( 'cpage', $redirect['query'] );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $redirect['path'] = user_trailingslashit( preg_replace( '|/' . preg_quote( $wp_rewrite->index, '|' ) . '/?$|', '/', $redirect['path'] ) ); // Strip off trailing /index.php/.
- if ( ! empty( $addl_path ) && $wp_rewrite->using_index_permalinks() && strpos( $redirect['path'], '/' . $wp_rewrite->index . '/' ) === false ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Strip off trailing /index.php/.
+ $redirect['path'] = preg_replace( '|/' . preg_quote( $wp_rewrite->index, '|' ) . '/?$|', '/', $redirect['path'] );
+ $redirect['path'] = user_trailingslashit( $redirect['path'] );
+
+ if ( ! empty( $addl_path )
+ && $wp_rewrite->using_index_permalinks()
+ && strpos( $redirect['path'], '/' . $wp_rewrite->index . '/' ) === false
+ ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $redirect['path'] = trailingslashit( $redirect['path'] ) . $wp_rewrite->index . '/';
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! empty( $addl_path ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $redirect['path'] = trailingslashit( $redirect['path'] ) . $addl_path;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> $redirect_url = $redirect['scheme'] . '://' . $redirect['host'] . $redirect['path'];
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( 'wp-register.php' == basename( $redirect['path'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( 'wp-register.php' === basename( $redirect['path'] ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( is_multisite() ) {
</span><span class="cx" style="display: block; padding: 0 10px"> /** This filter is documented in wp-login.php */
</span><span class="cx" style="display: block; padding: 0 10px"> $redirect_url = apply_filters( 'wp_signup_location', network_site_url( 'wp-signup.php' ) );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -402,8 +515,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $redirect['query'] = preg_replace( '#^\??&*?#', '', $redirect['query'] );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> // Tack on any additional query vars.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $redirect['query'] = preg_replace( '#^\??&*?#', '', $redirect['query'] );
</del><span class="cx" style="display: block; padding: 0 10px"> if ( $redirect_url && ! empty( $redirect['query'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> parse_str( $redirect['query'], $_parsed_query );
</span><span class="cx" style="display: block; padding: 0 10px"> $redirect = parse_url( $redirect_url );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -420,7 +534,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> rawurlencode_deep( array_keys( $_parsed_query ) ),
</span><span class="cx" style="display: block; padding: 0 10px"> rawurlencode_deep( array_values( $_parsed_query ) )
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $redirect_url = add_query_arg( $_parsed_query, $redirect_url );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ $redirect_url = add_query_arg( $_parsed_query, $redirect_url );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $redirect_url ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -429,9 +544,11 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // www.example.com vs. example.com
</span><span class="cx" style="display: block; padding: 0 10px"> $user_home = parse_url( home_url() );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! empty( $user_home['host'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $redirect['host'] = $user_home['host'];
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( empty( $user_home['path'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $user_home['path'] = '/';
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -502,8 +619,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Trailing slashes.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( is_object( $wp_rewrite ) && $wp_rewrite->using_permalinks() && ! is_404() && ( ! is_front_page() || ( is_front_page() && ( get_query_var( 'paged' ) > 1 ) ) ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( is_object( $wp_rewrite ) && $wp_rewrite->using_permalinks()
+ && ! is_404() && ( ! is_front_page() || is_front_page() && get_query_var( 'paged' ) > 1 )
+ ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $user_ts_type = '';
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( get_query_var( 'paged' ) > 0 ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $user_ts_type = 'paged';
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -515,6 +635,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> $redirect['path'] = user_trailingslashit( $redirect['path'], $user_ts_type );
</span><span class="cx" style="display: block; padding: 0 10px"> } elseif ( is_front_page() ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $redirect['path'] = trailingslashit( $redirect['path'] );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -526,14 +647,19 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Always trailing slash the Front Page URL.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( trailingslashit( $redirect['path'] ) == trailingslashit( $user_home['path'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( trailingslashit( $redirect['path'] ) === trailingslashit( $user_home['path'] ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $redirect['path'] = trailingslashit( $redirect['path'] );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $original_host_low = strtolower( $original['host'] );
+ $redirect_host_low = strtolower( $redirect['host'] );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> // Ignore differences in host capitalization, as this can lead to infinite redirects.
</span><span class="cx" style="display: block; padding: 0 10px"> // Only redirect no-www <=> yes-www.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( strtolower( $original['host'] ) == strtolower( $redirect['host'] ) ||
- ( strtolower( $original['host'] ) != 'www.' . strtolower( $redirect['host'] ) && 'www.' . strtolower( $original['host'] ) != strtolower( $redirect['host'] ) ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( $original_host_low === $redirect_host_low
+ || ( 'www.' . $original_host_low !== $redirect_host_low
+ && 'www.' . $redirect_host_low !== $original_host_low )
+ ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $redirect['host'] = $original['host'];
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -559,16 +685,19 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $compare_original !== $compare_redirect ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $redirect_url = $redirect['scheme'] . '://' . $redirect['host'];
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! empty( $redirect['port'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $redirect_url .= ':' . $redirect['port'];
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> $redirect_url .= $redirect['path'];
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! empty( $redirect['query'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $redirect_url .= '?' . $redirect['query'];
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! $redirect_url || $redirect_url == $requested_url ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! $redirect_url || $redirect_url === $requested_url ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -588,6 +717,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return strtolower( $matches[0] );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> $requested_url = preg_replace_callback( '|%[a-fA-F0-9][a-fA-F0-9]|', 'lowercase_octets', $requested_url );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -604,7 +734,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $redirect_url = apply_filters( 'redirect_canonical', $redirect_url, $requested_url );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Yes, again -- in case the filter aborted the request.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! $redirect_url || strip_fragment_from_url( $redirect_url ) == strip_fragment_from_url( $requested_url ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! $redirect_url || strip_fragment_from_url( $redirect_url ) === strip_fragment_from_url( $requested_url ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -637,8 +767,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function _remove_qs_args_if_not_in_url( $query_string, array $args_to_check, $url ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $parsed_url = parse_url( $url );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! empty( $parsed_url['query'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> parse_str( $parsed_url['query'], $parsed_query );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> foreach ( $args_to_check as $qv ) {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! isset( $parsed_query[ $qv ] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $query_string = remove_query_arg( $qv, $query_string );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -647,6 +779,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="cx" style="display: block; padding: 0 10px"> $query_string = remove_query_arg( $args_to_check, $query_string );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> return $query_string;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -660,6 +793,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function strip_fragment_from_url( $url ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $parsed_url = parse_url( $url );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! empty( $parsed_url['host'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> // This mirrors code in redirect_canonical(). It does not handle every case.
</span><span class="cx" style="display: block; padding: 0 10px"> $url = $parsed_url['scheme'] . '://' . $parsed_url['host'];
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -711,13 +845,16 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $where .= $wpdb->prepare( ' AND DAYOFMONTH(post_date) = %d', get_query_var( 'day' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
</ins><span class="cx" style="display: block; padding: 0 10px"> $post_id = $wpdb->get_var( "SELECT ID FROM $wpdb->posts WHERE $where AND post_status = 'publish'" );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! $post_id ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return false;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( get_query_var( 'feed' ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return get_post_comments_feed_link( $post_id, get_query_var( 'feed' ) );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- } elseif ( get_query_var( 'page' ) && 1 < get_query_var( 'page' ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ } elseif ( get_query_var( 'page' ) > 1 ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return trailingslashit( get_permalink( $post_id ) ) . user_trailingslashit( get_query_var( 'page' ), 'single_paged' );
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="cx" style="display: block; padding: 0 10px"> return get_permalink( $post_id );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -739,6 +876,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function wp_redirect_admin_locations() {
</span><span class="cx" style="display: block; padding: 0 10px"> global $wp_rewrite;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! ( is_404() && $wp_rewrite->using_permalinks() ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -750,6 +888,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> site_url( 'dashboard', 'relative' ),
</span><span class="cx" style="display: block; padding: 0 10px"> site_url( 'admin', 'relative' ),
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( in_array( untrailingslashit( $_SERVER['REQUEST_URI'] ), $admins, true ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> wp_redirect( admin_url() );
</span><span class="cx" style="display: block; padding: 0 10px"> exit;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -760,6 +899,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> home_url( 'login', 'relative' ),
</span><span class="cx" style="display: block; padding: 0 10px"> site_url( 'login', 'relative' ),
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( in_array( untrailingslashit( $_SERVER['REQUEST_URI'] ), $logins, true ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> wp_redirect( wp_login_url() );
</span><span class="cx" style="display: block; padding: 0 10px"> exit;
</span></span></pre>
</div>
</div>
</body>
</html>