Make WordPress Core


Ignore:
Timestamp:
05/23/2010 07:49:21 AM (16 years ago)
Author:
dd32
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/post.php

    r14713 r14814  
    16561656 *
    16571657 * @param string|array $mime_types List of mime types or comma separated string of mime types.
    1658  * @param string $table_alias Optional. Specify a table alias, if needed. 
     1658 * @param string $table_alias Optional. Specify a table alias, if needed.
    16591659 * @return string The SQL AND clause for mime searching.
    16601660 */
    … …  
    22002200                $post_ID = (int) $ID;
    22012201                $guid = get_post_field( 'guid', $post_ID );
     2202                $post_before = get_post($post_ID);
    22022203        }
    22032204
    … …  
    23752376        wp_transition_post_status($data['post_status'], $previous_status, $post);
    23762377
    2377         if ( $update )
     2378        if ( $update ) {
    23782379                do_action('edit_post', $post_ID, $post);
     2380                $post_after = get_post($post_ID);
     2381                do_action( 'post_updated', $post_ID, $post_after, $post_before);
     2382        }
    23792383
    23802384        do_action('save_post', $post_ID, $post);
    … …  
    37793783 * @return int Same as $post_id
    37803784 */
    3781 function wp_check_for_changed_slugs($post_id) {
    3782         if ( empty($_POST['wp-old-slug']) )
    3783                 return $post_id;
    3784 
    3785         $post = &get_post($post_id);
     3785function wp_check_for_changed_slugs($post_id, $post, $post_before) {
     3786        // dont bother if it hasnt changed
     3787        if ( $post->post_name == $post_before->post_name )
     3788                return;
    37863789
    37873790        // we're only concerned with published posts
    37883791        if ( $post->post_status != 'publish' || $post->post_type != 'post' )
    3789                 return $post_id;
    3790 
    3791         // only bother if the slug has changed
    3792         if ( $post->post_name == $_POST['wp-old-slug'] )
    3793                 return $post_id;
     3792                return;
    37943793
    37953794        $old_slugs = (array) get_post_meta($post_id, '_wp_old_slug');
    37963795
    37973796        // if we haven't added this old slug before, add it now
    3798         if ( !count($old_slugs) || !in_array($_POST['wp-old-slug'], $old_slugs) )
    3799                 add_post_meta($post_id, '_wp_old_slug', $_POST['wp-old-slug']);
     3797        if ( !in_array($post_before->post_name, $old_slugs) )
     3798                add_post_meta($post_id, '_wp_old_slug', $post_before->post_name);
    38003799
    38013800        // if the new slug was used previously, delete it from the list
    38023801        if ( in_array($post->post_name, $old_slugs) )
    38033802                delete_post_meta($post_id, '_wp_old_slug', $post->post_name);
    3804 
    3805         return $post_id;
    38063803}
    38073804
Note: See TracChangeset for help on using the changeset viewer.