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 | } |
… |
… |
|
120 | 120 | |
121 | 121 | // Redirect ?page_id, ?p=, ?attachment_id= to their respective url's |
122 | 122 | $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 ); |
| 123 | if ( $id ) { |
| 124 | $redirect_post = get_post( $id ); |
| 125 | if ( $redirect_post ) { |
| 126 | $post_type_obj = get_post_type_object( $redirect_post->post_type ); |
| 127 | if ( $post_type_obj->public && 'auto-draft' !== $redirect_post->post_status ) { |
| 128 | $redirect_url = get_permalink( $redirect_post ); |
| 129 | $redirect['query'] = _remove_qs_args_if_not_in_url( |
| 130 | $redirect['query'], |
| 131 | array( 'p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type' ), |
| 132 | $redirect_url |
| 133 | ); |
| 134 | } |
128 | 135 | } |
129 | 136 | } |
130 | 137 | |
… |
… |
|
143 | 150 | } |
144 | 151 | |
145 | 152 | 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 ); |
| 153 | $redirect_url = redirect_guess_404_permalink(); |
| 154 | if ( $redirect_url ) { |
| 155 | $redirect['query'] = _remove_qs_args_if_not_in_url( |
| 156 | $redirect['query'], |
| 157 | array( 'page', 'feed', 'p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type' ), |
| 158 | $redirect_url |
| 159 | ); |
148 | 160 | } |
149 | 161 | } |
150 | 162 | |
… |
… |
|
168 | 180 | $redirect_url = get_attachment_link(); |
169 | 181 | } |
170 | 182 | } elseif ( is_single() && ! empty( $_GET['p'] ) && ! $redirect_url ) { |
171 | | if ( $redirect_url = get_permalink( get_query_var( 'p' ) ) ) { |
| 183 | $redirect_url = get_permalink( get_query_var( 'p' ) ); |
| 184 | if ( $redirect_url ) { |
172 | 185 | $redirect['query'] = remove_query_arg( array( 'p', 'post_type' ), $redirect['query'] ); |
173 | 186 | } |
174 | 187 | } elseif ( is_single() && ! empty( $_GET['name'] ) && ! $redirect_url ) { |
175 | | if ( $redirect_url = get_permalink( $wp_query->get_queried_object_id() ) ) { |
| 188 | $redirect_url = get_permalink( $wp_query->get_queried_object_id() ); |
| 189 | if ( $redirect_url ) { |
176 | 190 | $redirect['query'] = remove_query_arg( 'name', $redirect['query'] ); |
177 | 191 | } |
178 | 192 | } elseif ( is_page() && ! empty( $_GET['page_id'] ) && ! $redirect_url ) { |
179 | | if ( $redirect_url = get_permalink( get_query_var( 'page_id' ) ) ) { |
| 193 | $redirect_url = get_permalink( get_query_var( 'page_id' ) ); |
| 194 | if ( $redirect_url ) { |
180 | 195 | $redirect['query'] = remove_query_arg( 'page_id', $redirect['query'] ); |
181 | 196 | } |
182 | 197 | } elseif ( is_page() && ! is_feed() && 'page' == get_option( 'show_on_front' ) && get_queried_object_id() == get_option( 'page_on_front' ) && ! $redirect_url ) { |
183 | 198 | $redirect_url = home_url( '/' ); |
184 | 199 | } 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' ) ) ) { |
| 200 | $redirect_url = get_permalink( get_option( 'page_for_posts' ) ); |
| 201 | if ( $redirect_url ) { |
186 | 202 | $redirect['query'] = remove_query_arg( 'page_id', $redirect['query'] ); |
187 | 203 | } |
188 | 204 | } elseif ( ! empty( $_GET['m'] ) && ( is_year() || is_month() || is_day() ) ) { |
… |
… |
|
203 | 219 | } |
204 | 220 | // now moving on to non ?m=X year/month/day links |
205 | 221 | } 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' ) ) ) { |
| 222 | $redirect_url = get_day_link( |
| 223 | get_query_var( 'year' ), |
| 224 | get_query_var( 'monthnum' ), |
| 225 | get_query_var( 'day' ) |
| 226 | ); |
| 227 | if ( $redirect_url ) { |
207 | 228 | $redirect['query'] = remove_query_arg( array( 'year', 'monthnum', 'day' ), $redirect['query'] ); |
208 | 229 | } |
209 | 230 | } 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' ) ) ) { |
| 231 | $redirect_url = get_month_link( get_query_var( 'year' ), get_query_var( 'monthnum' ) ); |
| 232 | if ( $redirect_url ) { |
211 | 233 | $redirect['query'] = remove_query_arg( array( 'year', 'monthnum' ), $redirect['query'] ); |
212 | 234 | } |
213 | 235 | } elseif ( is_year() && ! empty( $_GET['year'] ) ) { |
214 | | if ( $redirect_url = get_year_link( get_query_var( 'year' ) ) ) { |
| 236 | $redirect_url = get_year_link( get_query_var( 'year' ) ); |
| 237 | if ( $redirect_url ) { |
215 | 238 | $redirect['query'] = remove_query_arg( 'year', $redirect['query'] ); |
216 | 239 | } |
217 | 240 | } elseif ( is_author() && ! empty( $_GET['author'] ) && preg_match( '|^[0-9]+$|', $_GET['author'] ) ) { |
218 | 241 | $author = get_userdata( get_query_var( 'author' ) ); |
219 | 242 | 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 ) ) { |
| 243 | $redirect_url = get_author_posts_url( $author->ID, $author->user_nicename ); |
| 244 | if ( $redirect_url ) { |
221 | 245 | $redirect['query'] = remove_query_arg( 'author', $redirect['query'] ); |
222 | 246 | } |
223 | 247 | } |
… |
… |
|
229 | 253 | } |
230 | 254 | |
231 | 255 | $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'] ) ) { |
| 256 | if ( $term_count <= 1 && ! empty( $obj->term_id ) ) { |
| 257 | $tax_url = get_term_link( (int) $obj->term_id, $obj->taxonomy ); |
| 258 | if ( ! empty( $tax_url ) && ! is_wp_error( $tax_url ) && ! empty( $redirect['query'] ) ) { |
234 | 259 | // Strip taxonomy query vars off the url. |
235 | 260 | $qv_remove = array( 'term', 'taxonomy' ); |
236 | 261 | if ( is_category() ) { |
… |
… |
|
252 | 277 | $redirect['query'] = remove_query_arg( $qv_remove, $redirect['query'] ); //Remove all of the per-tax qv's |
253 | 278 | |
254 | 279 | // Create the destination url for this taxonomy |
255 | | $tax_url = parse_url( $tax_url ); |
| 280 | $tax_url = wp_parse_url( $tax_url ); |
256 | 281 | if ( ! empty( $tax_url['query'] ) ) { // Taxonomy accessible via ?taxonomy=..&term=.. or any custom qv.. |
257 | 282 | parse_str( $tax_url['query'], $query_vars ); |
258 | 283 | $redirect['query'] = add_query_arg( $query_vars, $redirect['query'] ); |
… |
… |
|
268 | 293 | } |
269 | 294 | } |
270 | 295 | } |
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() ); |
| 296 | } elseif ( is_single() && strpos( $wp_rewrite->permalink_structure, '%category%' ) !== false ) { |
| 297 | $cat = get_query_var( 'category_name' ); |
| 298 | if ( $cat ) { |
| 299 | $category = get_category_by_path( $cat ); |
| 300 | if ( ( ! $category || is_wp_error( $category ) ) |
| 301 | || ! has_term( $category->term_id, 'category', $wp_query->get_queried_object_id() ) |
| 302 | ) { |
| 303 | $redirect_url = get_permalink( $wp_query->get_queried_object_id() ); |
| 304 | } |
275 | 305 | } |
276 | 306 | } |
277 | 307 | |
… |
… |
|
378 | 408 | $redirect['query'] = preg_replace( '#^\??&*?#', '', $redirect['query'] ); |
379 | 409 | if ( $redirect_url && ! empty( $redirect['query'] ) ) { |
380 | 410 | parse_str( $redirect['query'], $_parsed_query ); |
381 | | $redirect = @parse_url( $redirect_url ); |
| 411 | $redirect = wp_parse_url( $redirect_url ); |
382 | 412 | |
383 | 413 | if ( ! empty( $_parsed_query['name'] ) && ! empty( $redirect['query'] ) ) { |
384 | 414 | parse_str( $redirect['query'], $_parsed_redirect_query ); |
… |
… |
|
396 | 426 | } |
397 | 427 | |
398 | 428 | if ( $redirect_url ) { |
399 | | $redirect = @parse_url( $redirect_url ); |
| 429 | $redirect = wp_parse_url( $redirect_url ); |
400 | 430 | } |
401 | 431 | |
402 | 432 | // www.example.com vs example.com |
403 | | $user_home = @parse_url( home_url() ); |
| 433 | $user_home = wp_parse_url( home_url() ); |
404 | 434 | if ( ! empty( $user_home['host'] ) ) { |
405 | 435 | $redirect['host'] = $user_home['host']; |
406 | 436 | } |
… |
… |
|
608 | 638 | * @return string The altered query string |
609 | 639 | */ |
610 | 640 | function _remove_qs_args_if_not_in_url( $query_string, array $args_to_check, $url ) { |
611 | | $parsed_url = @parse_url( $url ); |
| 641 | $parsed_url = wp_parse_url( $url ); |
612 | 642 | if ( ! empty( $parsed_url['query'] ) ) { |
613 | 643 | parse_str( $parsed_url['query'], $parsed_query ); |
614 | 644 | foreach ( $args_to_check as $qv ) { |
… |
… |
|
631 | 661 | * @return string The altered URL. |
632 | 662 | */ |
633 | 663 | function strip_fragment_from_url( $url ) { |
634 | | $parsed_url = @parse_url( $url ); |
| 664 | $parsed_url = wp_parse_url( $url ); |
635 | 665 | if ( ! empty( $parsed_url['host'] ) ) { |
636 | 666 | // This mirrors code in redirect_canonical(). It does not handle every case. |
637 | 667 | $url = $parsed_url['scheme'] . '://' . $parsed_url['host']; |
… |
… |
|
670 | 700 | if ( get_query_var( 'post_type' ) ) { |
671 | 701 | $where .= $wpdb->prepare( ' AND post_type = %s', get_query_var( 'post_type' ) ); |
672 | 702 | } else { |
673 | | $where .= " AND post_type IN ('" . implode( "', '", get_post_types( array( 'public' => true ) ) ) . "')"; |
| 703 | // Fetch the variables needed to place in the post_types query. |
| 704 | $post_types = get_post_types( array( 'public' => true ) ); |
| 705 | if ( is_array( $post_types ) && ! array() === $post_types ) { |
| 706 | // Create placeholders for all the variables. |
| 707 | $placeholders = implode( ', ', array_fill( 0, count( $post_types ), '%s' ) ); |
| 708 | |
| 709 | /* |
| 710 | * Add the statement to the where condition. |
| 711 | * |
| 712 | * The ignore is needed because the placeholders are inside a variable, which is concatinated to the |
| 713 | * where statement, but the sniff is not picking it up correctly yet. |
| 714 | * |
| 715 | * This is a WPCS problem and has been fixed in the following PR |
| 716 | * @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/pull/515 |
| 717 | */ |
| 718 | $post_type_where = sprintf( ' AND post_type IN ( %s )', $placeholders ); |
| 719 | $where .= $wpdb->prepare( |
| 720 | $post_type_where, // phpcs:ignore WordPress.WP.PreparedSQL.NotPrepared |
| 721 | $post_types |
| 722 | ); |
| 723 | } |
674 | 724 | } |
675 | 725 | |
676 | 726 | if ( get_query_var( 'year' ) ) { |
… |
… |
|
683 | 733 | $where .= $wpdb->prepare( ' AND DAYOFMONTH(post_date) = %d', get_query_var( 'day' ) ); |
684 | 734 | } |
685 | 735 | |
686 | | $post_id = $wpdb->get_var( "SELECT ID FROM $wpdb->posts WHERE $where AND post_status = 'publish'" ); |
| 736 | /* |
| 737 | * Build the compelte SQL statement and execute it. |
| 738 | * |
| 739 | * The ignore has been added because all of the variables used are being prepared in the above lines. |
| 740 | */ |
| 741 | $post_id = $wpdb->get_var( "SELECT ID FROM $wpdb->posts WHERE $where AND post_status = 'publish'" ); // phpcs:ignore WordPress.WP.PreparedSQL.NotPrepared |
687 | 742 | if ( ! $post_id ) { |
688 | 743 | return false; |
689 | 744 | } |