IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
|
|
|
67 | 67 | $requested_url .= $_SERVER['REQUEST_URI']; |
68 | 68 | } |
69 | 69 | |
70 | | $original = @parse_url( $requested_url ); |
| 70 | $original = wp_parse_url( $requested_url ); |
71 | 71 | if ( false === $original ) { |
72 | 72 | return; |
73 | 73 | } |
… |
… |
|
93 | 93 | $redirect['query'] = remove_query_arg( 'preview', $redirect['query'] ); |
94 | 94 | } |
95 | 95 | |
96 | | if ( is_feed() && ( $id = get_query_var( 'p' ) ) ) { |
97 | | if ( $redirect_url = get_post_comments_feed_link( $id, get_query_var( 'feed' ) ) ) { |
98 | | $redirect['query'] = _remove_qs_args_if_not_in_url( $redirect['query'], array( 'p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type', 'feed' ), $redirect_url ); |
99 | | $redirect['path'] = parse_url( $redirect_url, PHP_URL_PATH ); |
| 96 | if ( is_feed() ) { |
| 97 | $id = get_query_var( 'p' ); |
| 98 | if ( ! empty( $id ) ) { |
| 99 | $redirect_url = get_post_comments_feed_link( $id, get_query_var( 'feed' ) ); |
| 100 | if ( ! empty( $redirect_url ) && is_string( $redirect_url ) ) { |
| 101 | $redirect['query'] = _remove_qs_args_if_not_in_url( |
| 102 | $redirect['query'], |
| 103 | array( 'p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type', 'feed' ), |
| 104 | $redirect_url |
| 105 | ); |
| 106 | $redirect['path'] = wp_parse_url( $redirect_url, PHP_URL_PATH ); |
| 107 | } |
100 | 108 | } |
101 | 109 | } |
102 | 110 | |
103 | | if ( is_singular() && 1 > $wp_query->post_count && ( $id = get_query_var( 'p' ) ) ) { |
| 111 | if ( is_singular() && 1 > $wp_query->post_count ) { |
| 112 | $id = get_query_var( 'p' ); |
| 113 | if ( ! empty( $id ) ) { |
104 | 114 | |
105 | | $vars = $wpdb->get_results( $wpdb->prepare( "SELECT post_type, post_parent FROM $wpdb->posts WHERE ID = %d", $id ) ); |
| 115 | $vars = $wpdb->get_results( |
| 116 | $wpdb->prepare( "SELECT post_type, post_parent FROM $wpdb->posts WHERE ID = %d", $id ) |
| 117 | ); |
106 | 118 | |
107 | | if ( isset( $vars[0] ) && $vars = $vars[0] ) { |
108 | | if ( 'revision' == $vars->post_type && $vars->post_parent > 0 ) { |
109 | | $id = $vars->post_parent; |
110 | | } |
| 119 | if ( ! empty( $vars[0] ) ) { |
| 120 | $vars = $vars[0]; |
| 121 | if ( 'revision' === $vars->post_type && $vars->post_parent > 0 ) { |
| 122 | $id = $vars->post_parent; |
| 123 | } |
111 | 124 | |
112 | | if ( $redirect_url = get_permalink( $id ) ) { |
113 | | $redirect['query'] = _remove_qs_args_if_not_in_url( $redirect['query'], array( 'p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type' ), $redirect_url ); |
| 125 | $redirect_url = get_permalink( $id ); |
| 126 | if ( ! empty( $redirect_url ) && is_string( $redirect_url ) ) { |
| 127 | $redirect['query'] = _remove_qs_args_if_not_in_url( |
| 128 | $redirect['query'], |
| 129 | array( 'p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type' ), |
| 130 | $redirect_url |
| 131 | ); |
| 132 | } |
114 | 133 | } |
115 | 134 | } |
116 | 135 | } |
… |
… |
|
120 | 139 | |
121 | 140 | // Redirect ?page_id, ?p=, ?attachment_id= to their respective url's |
122 | 141 | $id = max( get_query_var( 'p' ), get_query_var( 'page_id' ), get_query_var( 'attachment_id' ) ); |
123 | | if ( $id && $redirect_post = get_post( $id ) ) { |
124 | | $post_type_obj = get_post_type_object( $redirect_post->post_type ); |
125 | | if ( $post_type_obj->public && 'auto-draft' != $redirect_post->post_status ) { |
126 | | $redirect_url = get_permalink( $redirect_post ); |
127 | | $redirect['query'] = _remove_qs_args_if_not_in_url( $redirect['query'], array( 'p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type' ), $redirect_url ); |
| 142 | if ( $id ) { |
| 143 | $redirect_post = get_post( $id ); |
| 144 | if ( ! empty( $redirect_post ) ) { |
| 145 | $post_type_obj = get_post_type_object( $redirect_post->post_type ); |
| 146 | if ( $post_type_obj->public && 'auto-draft' !== $redirect_post->post_status ) { |
| 147 | $redirect_url = get_permalink( $redirect_post ); |
| 148 | $redirect['query'] = _remove_qs_args_if_not_in_url( |
| 149 | $redirect['query'], |
| 150 | array( 'p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type' ), |
| 151 | $redirect_url |
| 152 | ); |
| 153 | } |
128 | 154 | } |
129 | 155 | } |
130 | 156 | |
… |
… |
|
143 | 169 | } |
144 | 170 | |
145 | 171 | if ( ! $redirect_url ) { |
146 | | if ( $redirect_url = redirect_guess_404_permalink() ) { |
147 | | $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 ); |
| 172 | $redirect_url = redirect_guess_404_permalink(); |
| 173 | if ( ! empty( $redirect_url ) && is_string( $redirect_url ) ) { |
| 174 | $redirect['query'] = _remove_qs_args_if_not_in_url( |
| 175 | $redirect['query'], |
| 176 | array( 'page', 'feed', 'p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type' ), |
| 177 | $redirect_url |
| 178 | ); |
148 | 179 | } |
149 | 180 | } |
150 | 181 | |
… |
… |
|
168 | 199 | $redirect_url = get_attachment_link(); |
169 | 200 | } |
170 | 201 | } elseif ( is_single() && ! empty( $_GET['p'] ) && ! $redirect_url ) { |
171 | | if ( $redirect_url = get_permalink( get_query_var( 'p' ) ) ) { |
| 202 | $redirect_url = get_permalink( get_query_var( 'p' ) ); |
| 203 | if ( ! empty( $redirect_url ) && is_string( $redirect_url ) ) { |
172 | 204 | $redirect['query'] = remove_query_arg( array( 'p', 'post_type' ), $redirect['query'] ); |
173 | 205 | } |
174 | 206 | } elseif ( is_single() && ! empty( $_GET['name'] ) && ! $redirect_url ) { |
175 | | if ( $redirect_url = get_permalink( $wp_query->get_queried_object_id() ) ) { |
| 207 | $redirect_url = get_permalink( $wp_query->get_queried_object_id() ); |
| 208 | if ( ! empty( $redirect_url ) && is_string( $redirect_url ) ) { |
176 | 209 | $redirect['query'] = remove_query_arg( 'name', $redirect['query'] ); |
177 | 210 | } |
178 | 211 | } elseif ( is_page() && ! empty( $_GET['page_id'] ) && ! $redirect_url ) { |
179 | | if ( $redirect_url = get_permalink( get_query_var( 'page_id' ) ) ) { |
| 212 | $redirect_url = get_permalink( get_query_var( 'page_id' ) ); |
| 213 | if ( ! empty( $redirect_url ) && is_string( $redirect_url ) ) { |
180 | 214 | $redirect['query'] = remove_query_arg( 'page_id', $redirect['query'] ); |
181 | 215 | } |
182 | 216 | } elseif ( is_page() && ! is_feed() && 'page' == get_option( 'show_on_front' ) && get_queried_object_id() == get_option( 'page_on_front' ) && ! $redirect_url ) { |
183 | 217 | $redirect_url = home_url( '/' ); |
184 | 218 | } 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 ) { |
185 | | if ( $redirect_url = get_permalink( get_option( 'page_for_posts' ) ) ) { |
| 219 | $redirect_url = get_permalink( get_option( 'page_for_posts' ) ); |
| 220 | if ( ! empty( $redirect_url ) && is_string( $redirect_url ) ) { |
186 | 221 | $redirect['query'] = remove_query_arg( 'page_id', $redirect['query'] ); |
187 | 222 | } |
188 | 223 | } elseif ( ! empty( $_GET['m'] ) && ( is_year() || is_month() || is_day() ) ) { |
… |
… |
|
203 | 238 | } |
204 | 239 | // now moving on to non ?m=X year/month/day links |
205 | 240 | } elseif ( is_day() && get_query_var( 'year' ) && get_query_var( 'monthnum' ) && ! empty( $_GET['day'] ) ) { |
206 | | if ( $redirect_url = get_day_link( get_query_var( 'year' ), get_query_var( 'monthnum' ), get_query_var( 'day' ) ) ) { |
| 241 | $redirect_url = get_day_link( |
| 242 | get_query_var( 'year' ), |
| 243 | get_query_var( 'monthnum' ), |
| 244 | get_query_var( 'day' ) |
| 245 | ); |
| 246 | if ( ! empty( $redirect_url ) && is_string( $redirect_url ) ) { |
207 | 247 | $redirect['query'] = remove_query_arg( array( 'year', 'monthnum', 'day' ), $redirect['query'] ); |
208 | 248 | } |
209 | 249 | } elseif ( is_month() && get_query_var( 'year' ) && ! empty( $_GET['monthnum'] ) ) { |
210 | | if ( $redirect_url = get_month_link( get_query_var( 'year' ), get_query_var( 'monthnum' ) ) ) { |
| 250 | $redirect_url = get_month_link( get_query_var( 'year' ), get_query_var( 'monthnum' ) ); |
| 251 | if ( ! empty( $redirect_url ) && is_string( $redirect_url ) ) { |
211 | 252 | $redirect['query'] = remove_query_arg( array( 'year', 'monthnum' ), $redirect['query'] ); |
212 | 253 | } |
213 | 254 | } elseif ( is_year() && ! empty( $_GET['year'] ) ) { |
214 | | if ( $redirect_url = get_year_link( get_query_var( 'year' ) ) ) { |
| 255 | $redirect_url = get_year_link( get_query_var( 'year' ) ); |
| 256 | if ( ! empty( $redirect_url ) && is_string( $redirect_url ) ) { |
215 | 257 | $redirect['query'] = remove_query_arg( 'year', $redirect['query'] ); |
216 | 258 | } |
217 | 259 | } elseif ( is_author() && ! empty( $_GET['author'] ) && preg_match( '|^[0-9]+$|', $_GET['author'] ) ) { |
218 | 260 | $author = get_userdata( get_query_var( 'author' ) ); |
219 | 261 | 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 ) ) ) { |
220 | | if ( $redirect_url = get_author_posts_url( $author->ID, $author->user_nicename ) ) { |
| 262 | $redirect_url = get_author_posts_url( $author->ID, $author->user_nicename ); |
| 263 | if ( ! empty( $redirect_url ) && is_string( $redirect_url ) ) { |
221 | 264 | $redirect['query'] = remove_query_arg( 'author', $redirect['query'] ); |
222 | 265 | } |
223 | 266 | } |
… |
… |
|
229 | 272 | } |
230 | 273 | |
231 | 274 | $obj = $wp_query->get_queried_object(); |
232 | | if ( $term_count <= 1 && ! empty( $obj->term_id ) && ( $tax_url = get_term_link( (int) $obj->term_id, $obj->taxonomy ) ) && ! is_wp_error( $tax_url ) ) { |
233 | | if ( ! empty( $redirect['query'] ) ) { |
| 275 | if ( $term_count <= 1 && ! empty( $obj->term_id ) ) { |
| 276 | $tax_url = get_term_link( (int) $obj->term_id, $obj->taxonomy ); |
| 277 | if ( ! empty( $tax_url ) && ! is_wp_error( $tax_url ) && ! empty( $redirect['query'] ) ) { |
234 | 278 | // Strip taxonomy query vars off the url. |
235 | 279 | $qv_remove = array( 'term', 'taxonomy' ); |
236 | 280 | if ( is_category() ) { |
… |
… |
|
252 | 296 | $redirect['query'] = remove_query_arg( $qv_remove, $redirect['query'] ); //Remove all of the per-tax qv's |
253 | 297 | |
254 | 298 | // Create the destination url for this taxonomy |
255 | | $tax_url = parse_url( $tax_url ); |
| 299 | $tax_url = wp_parse_url( $tax_url ); |
256 | 300 | if ( ! empty( $tax_url['query'] ) ) { // Taxonomy accessible via ?taxonomy=..&term=.. or any custom qv.. |
257 | 301 | parse_str( $tax_url['query'], $query_vars ); |
258 | 302 | $redirect['query'] = add_query_arg( $query_vars, $redirect['query'] ); |
… |
… |
|
268 | 312 | } |
269 | 313 | } |
270 | 314 | } |
271 | | } elseif ( is_single() && strpos( $wp_rewrite->permalink_structure, '%category%' ) !== false && $cat = get_query_var( 'category_name' ) ) { |
272 | | $category = get_category_by_path( $cat ); |
273 | | if ( ( ! $category || is_wp_error( $category ) ) || ! has_term( $category->term_id, 'category', $wp_query->get_queried_object_id() ) ) { |
274 | | $redirect_url = get_permalink( $wp_query->get_queried_object_id() ); |
| 315 | } elseif ( is_single() && strpos( $wp_rewrite->permalink_structure, '%category%' ) !== false ) { |
| 316 | $cat = get_query_var( 'category_name' ); |
| 317 | if ( ! empty( $cat ) ) { |
| 318 | $category = get_category_by_path( $cat ); |
| 319 | if ( ( ! $category || is_wp_error( $category ) ) |
| 320 | || ! has_term( $category->term_id, 'category', $wp_query->get_queried_object_id() ) |
| 321 | ) { |
| 322 | $redirect_url = get_permalink( $wp_query->get_queried_object_id() ); |
| 323 | } |
275 | 324 | } |
276 | 325 | } |
277 | 326 | |
… |
… |
|
378 | 427 | $redirect['query'] = preg_replace( '#^\??&*?#', '', $redirect['query'] ); |
379 | 428 | if ( $redirect_url && ! empty( $redirect['query'] ) ) { |
380 | 429 | parse_str( $redirect['query'], $_parsed_query ); |
381 | | $redirect = @parse_url( $redirect_url ); |
| 430 | $redirect = wp_parse_url( $redirect_url ); |
382 | 431 | |
383 | 432 | if ( ! empty( $_parsed_query['name'] ) && ! empty( $redirect['query'] ) ) { |
384 | 433 | parse_str( $redirect['query'], $_parsed_redirect_query ); |
… |
… |
|
393 | 442 | } |
394 | 443 | |
395 | 444 | if ( $redirect_url ) { |
396 | | $redirect = @parse_url( $redirect_url ); |
| 445 | $redirect = wp_parse_url( $redirect_url ); |
397 | 446 | } |
398 | 447 | |
399 | 448 | // www.example.com vs example.com |
400 | | $user_home = @parse_url( home_url() ); |
| 449 | $user_home = wp_parse_url( home_url() ); |
401 | 450 | if ( ! empty( $user_home['host'] ) ) { |
402 | 451 | $redirect['host'] = $user_home['host']; |
403 | 452 | } |
… |
… |
|
603 | 652 | * @return string The altered query string |
604 | 653 | */ |
605 | 654 | function _remove_qs_args_if_not_in_url( $query_string, array $args_to_check, $url ) { |
606 | | $parsed_url = @parse_url( $url ); |
| 655 | $parsed_url = wp_parse_url( $url ); |
607 | 656 | if ( ! empty( $parsed_url['query'] ) ) { |
608 | 657 | parse_str( $parsed_url['query'], $parsed_query ); |
609 | 658 | foreach ( $args_to_check as $qv ) { |
… |
… |
|
626 | 675 | * @return string The altered URL. |
627 | 676 | */ |
628 | 677 | function strip_fragment_from_url( $url ) { |
629 | | $parsed_url = @parse_url( $url ); |
| 678 | $parsed_url = wp_parse_url( $url ); |
630 | 679 | if ( ! empty( $parsed_url['host'] ) ) { |
631 | 680 | // This mirrors code in redirect_canonical(). It does not handle every case. |
632 | 681 | $url = $parsed_url['scheme'] . '://' . $parsed_url['host']; |
… |
… |
|
665 | 714 | if ( get_query_var( 'post_type' ) ) { |
666 | 715 | $where .= $wpdb->prepare( ' AND post_type = %s', get_query_var( 'post_type' ) ); |
667 | 716 | } else { |
668 | | $where .= " AND post_type IN ('" . implode( "', '", get_post_types( array( 'public' => true ) ) ) . "')"; |
| 717 | // Fetch the variables needed to place in the post_types query. |
| 718 | $post_types = get_post_types( array( 'public' => true ) ); |
| 719 | if ( is_array( $post_types ) && ! array() === $post_types ) { |
| 720 | // Create placeholders for all the variables. |
| 721 | $placeholders = implode( ', ', array_fill( 0, count( $post_types ), '%s' ) ); |
| 722 | |
| 723 | /* |
| 724 | * Add the statement to the where condition. |
| 725 | * |
| 726 | * The ignore is needed because the placeholders are inside a variable, which is concatinated to the |
| 727 | * where statement, but the sniff is not picking it up correctly yet. |
| 728 | * |
| 729 | * This is a WPCS problem and has been fixed in the following PR |
| 730 | * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/pull/515 |
| 731 | */ |
| 732 | $post_type_where = sprintf( ' AND post_type IN ( %s )', $placeholders ); |
| 733 | $where .= $wpdb->prepare( |
| 734 | $post_type_where, // phpcs:ignore WordPress.WP.PreparedSQL.NotPrepared |
| 735 | $post_types |
| 736 | ); |
| 737 | } |
669 | 738 | } |
670 | 739 | |
671 | 740 | if ( get_query_var( 'year' ) ) { |
… |
… |
|
678 | 747 | $where .= $wpdb->prepare( ' AND DAYOFMONTH(post_date) = %d', get_query_var( 'day' ) ); |
679 | 748 | } |
680 | 749 | |
681 | | $post_id = $wpdb->get_var( "SELECT ID FROM $wpdb->posts WHERE $where AND post_status = 'publish'" ); |
| 750 | /* |
| 751 | * Build the compelte SQL statement and execute it. |
| 752 | * |
| 753 | * The ignore has been added because all of the variables used are being prepared in the above lines. |
| 754 | */ |
| 755 | $post_id = $wpdb->get_var( "SELECT ID FROM $wpdb->posts WHERE $where AND post_status = 'publish'" ); // phpcs:ignore WordPress.WP.PreparedSQL.NotPrepared |
682 | 756 | if ( ! $post_id ) { |
683 | 757 | return false; |
684 | 758 | } |