Introduce a 'post_updated' action, Fires when a post is updated, Post ID, Current and Previous post objects are passed. Updatewp_check_for_changed_slugs() to use new hook. See #12473

git-svn-id: https://develop.svn.wordpress.org/trunk@14814 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Dion Hulse 2010-05-23 07:49:21 +00:00
parent 3581129c1f
commit b93faecc52
3 changed files with 18 additions and 32 deletions

View File

@ -2761,18 +2761,6 @@ function wp_import_upload_form( $action ) {
endif;
}
/**
* {@internal Missing Short Description}}
*
* @since unknown
*/
function wp_remember_old_slug() {
global $post;
$name = esc_attr($post->post_name); // just in case
if ( strlen($name) )
echo '<input type="hidden" id="wp-old-slug" name="wp-old-slug" value="' . $name . '" />';
}
/**
* Add a meta box to an edit form.
*

View File

@ -235,10 +235,11 @@ add_action( 'begin_fetch_post_thumbnail_html', '_wp_post_thumbnail_class_filter_
add_action( 'end_fetch_post_thumbnail_html', '_wp_post_thumbnail_class_filter_remove' );
// Redirect Old Slugs
add_action( 'template_redirect', 'wp_old_slug_redirect' );
add_action( 'edit_post', 'wp_check_for_changed_slugs' );
add_action( 'edit_form_advanced', 'wp_remember_old_slug' );
add_action( 'init', '_show_post_preview' );
add_action( 'template_redirect', 'wp_old_slug_redirect' );
add_action( 'post_updated', 'wp_check_for_changed_slugs', 12, 3 );
// Nonce check for Post Previews
add_action( 'init', '_show_post_preview' );
// Timezone
add_filter( 'pre_option_gmt_offset','wp_timezone_override_offset' );

View File

@ -1655,7 +1655,7 @@ function wp_match_mime_types($wildcard_mime_types, $real_mime_types) {
* @since 2.5.0
*
* @param string|array $mime_types List of mime types or comma separated string of mime types.
* @param string $table_alias Optional. Specify a table alias, if needed. 
* @param string $table_alias Optional. Specify a table alias, if needed.
* @return string The SQL AND clause for mime searching.
*/
function wp_post_mime_type_where($post_mime_types, $table_alias = '') {
@ -2199,6 +2199,7 @@ function wp_insert_post($postarr = array(), $wp_error = false) {
if ( $update ) {
$post_ID = (int) $ID;
$guid = get_post_field( 'guid', $post_ID );
$post_before = get_post($post_ID);
}
// Don't allow contributors to set to set the post slug for pending review posts
@ -2374,8 +2375,11 @@ function wp_insert_post($postarr = array(), $wp_error = false) {
wp_transition_post_status($data['post_status'], $previous_status, $post);
if ( $update )
if ( $update ) {
do_action('edit_post', $post_ID, $post);
$post_after = get_post($post_ID);
do_action( 'post_updated', $post_ID, $post_after, $post_before);
}
do_action('save_post', $post_ID, $post);
do_action('wp_insert_post', $post_ID, $post);
@ -3778,31 +3782,24 @@ function wp_mime_type_icon( $mime = 0 ) {
* @param int $post_id Post ID.
* @return int Same as $post_id
*/
function wp_check_for_changed_slugs($post_id) {
if ( empty($_POST['wp-old-slug']) )
return $post_id;
$post = &get_post($post_id);
function wp_check_for_changed_slugs($post_id, $post, $post_before) {
// dont bother if it hasnt changed
if ( $post->post_name == $post_before->post_name )
return;
// we're only concerned with published posts
if ( $post->post_status != 'publish' || $post->post_type != 'post' )
return $post_id;
// only bother if the slug has changed
if ( $post->post_name == $_POST['wp-old-slug'] )
return $post_id;
return;
$old_slugs = (array) get_post_meta($post_id, '_wp_old_slug');
// if we haven't added this old slug before, add it now
if ( !count($old_slugs) || !in_array($_POST['wp-old-slug'], $old_slugs) )
add_post_meta($post_id, '_wp_old_slug', $_POST['wp-old-slug']);
if ( !in_array($post_before->post_name, $old_slugs) )
add_post_meta($post_id, '_wp_old_slug', $post_before->post_name);
// if the new slug was used previously, delete it from the list
if ( in_array($post->post_name, $old_slugs) )
delete_post_meta($post_id, '_wp_old_slug', $post->post_name);
return $post_id;
}
/**