Changeset 4556
- Timestamp:
- 11/30/2006 08:48:56 AM (18 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/admin-functions.php
r4552 r4556 2070 2070 } 2071 2071 2072 2073 function wp_check_for_changed_slugs($post_id) { 2074 if ( !strlen($_POST['wp-old-slug']) ) 2075 return $post_id; 2076 2077 $post = &get_post($post_id); 2078 2079 // we're only concerned with published posts 2080 if ( $post->post_status != 'publish' || $post->post_type != 'post' ) 2081 return $post_id; 2082 2083 // only bother if the slug has changed 2084 if ( $post->post_name == $_POST['wp-old-slug'] ) 2085 return $post_id; 2086 2087 $old_slugs = get_post_meta($post_id, '_wp_old_slug'); 2088 2089 // if we haven't added this old slug before, add it now 2090 if ( !count($old_slugs) || !in_array($_POST['wp-old-slug'], $old_slugs) ) 2091 add_post_meta($post_id, '_wp_old_slug', $_POST['wp-old-slug']); 2092 2093 // if the new slug was used previously, delete it from the list 2094 if ( in_array($post->post_name, $old_slugs) ) 2095 delete_post_meta($post_id, '_wp_old_slug', $post->post_name); 2096 2097 return $post_id; 2098 } 2099 2100 2101 function wp_remember_old_slug() { 2102 global $post; 2103 $name = wp_specialchars($post->post_name); // just in case 2104 if ( strlen($name) ) 2105 echo '<input type="hidden" id="wp-old-slug" name="wp-old-slug" value="' . $name . '" />'; 2106 } 2107 2108 2072 2109 // If siteurl or home changed, reset cookies and flush rewrite rules. 2073 2110 function update_home_siteurl( $old_value, $value ) { -
trunk/wp-admin/upgrade-functions.php
r4495 r4556 175 175 if ( $wp_current_db_version < 3845 ) 176 176 upgrade_210(); 177 178 if ( $wp_current_db_version < 4351 ) 179 upgrade_old_slugs(); 177 180 178 181 $wp_rewrite->flush_rules(); … … 544 547 } 545 548 } 549 550 function upgrade_old_slugs() { 551 // upgrade people who were using the Redirect Old Slugs plugin 552 global $wpdb; 553 $wpdb->query("UPDATE $wpdb->postmeta SET meta_key = '_wp_old_slug' WHERE meta_key = 'old_slug'"); 554 } 555 546 556 547 557 // The functions we use to actually do stuff -
trunk/wp-includes/default-filters.php
r4265 r4556 147 147 add_filter('mce_buttons', '_mce_add_direction_buttons'); 148 148 149 // Redirect Old Slugs 150 add_action('template_redirect', 'wp_old_slug_redirect'); 151 add_action('edit_post', 'wp_check_for_changed_slugs'); 152 add_action('edit_form_advanced', 'wp_remember_old_slug'); 153 149 154 // Actions 150 155 add_action('wp_head', 'rsd_link'); -
trunk/wp-includes/query.php
r4517 r4556 1117 1117 } 1118 1118 1119 1120 // Redirect old slugs 1121 function wp_old_slug_redirect () { 1122 global $wp_query; 1123 if ( is_404() && '' != $wp_query->query_vars['name'] ) : 1124 global $wpdb; 1125 1126 $query = "SELECT post_id FROM $wpdb->postmeta, $wpdb->posts WHERE ID = post_id AND meta_key = '_wp_old_slug' AND meta_value='" . $wp_query->query_vars['name'] . "'"; 1127 1128 // if year, monthnum, or day have been specified, make our query more precise 1129 // just in case there are multiple identical _wp_old_slug values 1130 if ( '' != $wp_query->query_vars['year'] ) 1131 $query .= " AND YEAR(post_date) = '{$wp_query->query_vars['year']}'"; 1132 if ( '' != $wp_query->query_vars['monthnum'] ) 1133 $query .= " AND MONTH(post_date) = '{$wp_query->query_vars['monthnum']}'"; 1134 if ( '' != $wp_query->query_vars['day'] ) 1135 $query .= " AND DAYOFMONTH(post_date) = '{$wp_query->query_vars['day']}'"; 1136 1137 $id = (int) $wpdb->get_var($query); 1138 1139 if ( !$id ) 1140 return; 1141 1142 $link = get_permalink($id); 1143 1144 if ( !$link ) 1145 return; 1146 1147 wp_redirect($link, '301'); // Permanent redirect 1148 exit; 1149 endif; 1150 } 1151 1152 1119 1153 // 1120 1154 // Private helper functions -
trunk/wp-includes/version.php
r4551 r4556 4 4 5 5 $wp_version = '2.1-alpha3'; 6 $wp_db_version = 435 0;6 $wp_db_version = 4351; 7 7 8 8 ?>
Note: See TracChangeset
for help on using the changeset viewer.