diff --git src/wp-includes/canonical.php src/wp-includes/canonical.php
index ad219c2..b2bba4b 100644
|
|
function redirect_canonical( $requested_url = null, $do_redirect = true ) { |
294 | 294 | |
295 | 295 | // paging and feeds |
296 | 296 | if ( get_query_var( 'paged' ) || is_feed() || get_query_var( 'cpage' ) ) { |
297 | | 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'] ) ) { |
| 297 | |
| 298 | $feeds = array(); |
| 299 | foreach ( $wp_rewrite->feeds as $_feed ) { |
| 300 | $feeds[] = preg_quote( $_feed, '#' ); |
| 301 | } |
| 302 | $feeds = implode( '|', $feeds ); |
| 303 | |
| 304 | while ( preg_match( "#/$wp_rewrite->pagination_base/?[0-9]+?(/+)?$#", $redirect['path'] ) || preg_match( "#/(comments/?)?($feeds)(/+)?$#", $redirect['path'] ) || preg_match( "#/{$wp_rewrite->comments_pagination_base}-[0-9]+(/+)?$#", $redirect['path'] ) ) { |
298 | 305 | // Strip off paging and feed |
299 | 306 | $redirect['path'] = preg_replace( "#/$wp_rewrite->pagination_base/?[0-9]+?(/+)?$#", '/', $redirect['path'] ); // strip off any existing paging |
300 | | $redirect['path'] = preg_replace( '#/(comments/?)?(feed|rss2?|rdf|atom)(/+|$)#', '/', $redirect['path'] ); // strip off feed endings |
| 307 | $redirect['path'] = preg_replace( "#/(comments/?)?($feeds)(/+|$)#", '/', $redirect['path'] ); // strip off feed endings |
301 | 308 | $redirect['path'] = preg_replace( "#/{$wp_rewrite->comments_pagination_base}-[0-9]+?(/+)?$#", '/', $redirect['path'] ); // strip off any existing comment paging |
302 | 309 | } |
303 | 310 | |
diff --git src/wp-includes/post.php src/wp-includes/post.php
index 39e1891..51b0698 100644
|
|
function wp_check_for_changed_slugs( $post_id, $post, $post_before ) { |
5708 | 5708 | } |
5709 | 5709 | |
5710 | 5710 | // We're only concerned with published, non-hierarchical objects. |
5711 | | if ( ! ( 'publish' === $post->post_status || ( 'attachment' === get_post_type( $post ) && 'inherit' === $post->post_status ) ) || is_post_type_hierarchical( $post->post_type ) ) { |
| 5711 | if ( ! ( 'publish' === $post->post_status || ( 'attachment' === get_post_type( $post ) && 'inherit' === $post->post_status ) ) ) { |
5712 | 5712 | return; |
5713 | 5713 | } |
5714 | 5714 | |
diff --git src/wp-includes/query.php src/wp-includes/query.php
index ced8e40..b840ce7 100644
|
|
function wp_old_slug_redirect() { |
953 | 953 | $post_type = get_query_var( 'post_type' ); |
954 | 954 | } elseif ( get_query_var( 'attachment' ) ) { |
955 | 955 | $post_type = 'attachment'; |
956 | | } elseif ( get_query_var( 'pagename' ) ) { |
957 | | $post_type = 'page'; |
958 | 956 | } else { |
959 | | $post_type = 'post'; |
| 957 | $post_type = ''; // Open to all options |
960 | 958 | } |
961 | 959 | |
962 | 960 | if ( is_array( $post_type ) ) { |
… |
… |
function wp_old_slug_redirect() { |
966 | 964 | $post_type = reset( $post_type ); |
967 | 965 | } |
968 | 966 | |
969 | | // Do not attempt redirect for hierarchical post types |
970 | | if ( is_post_type_hierarchical( $post_type ) ) { |
971 | | return; |
972 | | } |
973 | | |
974 | 967 | $id = _find_post_by_old_slug( $post_type ); |
975 | 968 | |
976 | 969 | if ( ! $id ) { |
… |
… |
function wp_old_slug_redirect() { |
1032 | 1025 | function _find_post_by_old_slug( $post_type ) { |
1033 | 1026 | global $wpdb; |
1034 | 1027 | |
1035 | | $query = $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta, $wpdb->posts WHERE ID = post_id AND post_type = %s AND meta_key = '_wp_old_slug' AND meta_value = %s", $post_type, get_query_var( 'name' ) ); |
| 1028 | $default_post_type_whitelist = array_keys( get_post_types( array( 'public' => true ) ) ); |
| 1029 | $post_type_whitelist = apply_filters( 'find_post_by_old_slug_post_types', $default_post_type_whitelist ); |
| 1030 | |
| 1031 | if ( $post_type && ! in_array( $post_type, $post_type_whitelist ) ) { |
| 1032 | return 0; |
| 1033 | } |
| 1034 | |
| 1035 | $query = "SELECT post_id FROM $wpdb->postmeta, $wpdb->posts WHERE ID = post_id"; |
| 1036 | if ( $post_type ) { |
| 1037 | $query .= $wpdb->prepare( " AND post_type = %s", $post_type ); |
| 1038 | } else { |
| 1039 | $placeholders = trim( str_repeat( '%s,', count( $post_type_whitelist ) ), ',' ); |
| 1040 | $query .= $wpdb->prepare( " AND post_type IN ($placeholders)", $post_type_whitelist ); |
| 1041 | } |
| 1042 | $query .= $wpdb->prepare( " AND meta_key = '_wp_old_slug' AND meta_value = %s", get_query_var( 'name' ) ); |
1036 | 1043 | |
1037 | 1044 | // if year, monthnum, or day have been specified, make our query more precise |
1038 | 1045 | // just in case there are multiple identical _wp_old_slug values |
… |
… |
function _find_post_by_old_slug( $post_type ) { |
1067 | 1074 | function _find_post_by_old_date( $post_type ) { |
1068 | 1075 | global $wpdb; |
1069 | 1076 | |
| 1077 | $default_post_type_whitelist = array_keys( get_post_types( array( 'public' => true ) ) ); |
| 1078 | $post_type_whitelist = apply_filters( 'find_post_by_old_slug_post_types', $default_post_type_whitelist ); |
| 1079 | |
| 1080 | if ( $post_type && ! in_array( $post_type, $post_type_whitelist ) ) { |
| 1081 | return 0; |
| 1082 | } |
| 1083 | |
1070 | 1084 | $date_query = ''; |
1071 | 1085 | if ( get_query_var( 'year' ) ) { |
1072 | 1086 | $date_query .= $wpdb->prepare( " AND YEAR(pm_date.meta_value) = %d", get_query_var( 'year' ) ); |
… |
… |
function _find_post_by_old_date( $post_type ) { |
1080 | 1094 | |
1081 | 1095 | $id = 0; |
1082 | 1096 | if ( $date_query ) { |
1083 | | $id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta AS pm_date, $wpdb->posts WHERE ID = post_id AND post_type = %s AND meta_key = '_wp_old_date' AND post_name = %s" . $date_query, $post_type, get_query_var( 'name' ) ) ); |
| 1097 | $query = "SELECT post_id FROM $wpdb->postmeta AS pm_date, $wpdb->posts WHERE ID = post_id"; |
| 1098 | if ( $post_type ) { |
| 1099 | $query .= $wpdb->prepare( " AND post_type = %s", $post_type ); |
| 1100 | } else { |
| 1101 | $placeholders = trim( str_repeat( '%s,', count( $post_type_whitelist ) ), ',' ); |
| 1102 | $query .= $wpdb->prepare( " AND post_type IN ($placeholders)", $post_type_whitelist ); |
| 1103 | } |
| 1104 | $query .= $wpdb->prepare( " AND meta_key = '_wp_old_date' AND post_name = %s" . $date_query, get_query_var( 'name' ) ); |
| 1105 | |
| 1106 | $id = (int) $wpdb->get_var( $query ); |
1084 | 1107 | |
1085 | 1108 | if ( ! $id ) { |
| 1109 | $query = "SELECT ID FROM $wpdb->posts, $wpdb->postmeta AS pm_slug, $wpdb->postmeta AS pm_date WHERE ID = pm_slug.post_id AND ID = pm_date.post_id"; |
| 1110 | if ( $post_type ) { |
| 1111 | $query .= $wpdb->prepare( " AND post_type = %s", $post_type ); |
| 1112 | } else { |
| 1113 | $placeholders = trim( str_repeat( '%s,', count( $post_type_whitelist ) ), ',' ); |
| 1114 | $query .= $wpdb->prepare( " AND post_type IN ($placeholders)", $post_type_whitelist ); |
| 1115 | } |
| 1116 | $query .= $wpdb->prepare( " AND pm_slug.meta_key = '_wp_old_slug' AND pm_slug.meta_value = %s AND pm_date.meta_key = '_wp_old_date'" . $date_query, get_query_var( 'name' ) ); |
| 1117 | |
1086 | 1118 | // Check to see if an old slug matches the old date |
1087 | | $id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts, $wpdb->postmeta AS pm_slug, $wpdb->postmeta AS pm_date WHERE ID = pm_slug.post_id AND ID = pm_date.post_id AND post_type = %s AND pm_slug.meta_key = '_wp_old_slug' AND pm_slug.meta_value = %s AND pm_date.meta_key = '_wp_old_date'" . $date_query, $post_type, get_query_var( 'name' ) ) ); |
| 1119 | $id = (int) $wpdb->get_var( $query ); |
1088 | 1120 | } |
1089 | 1121 | } |
1090 | 1122 | |