WordPress.org

Make WordPress Core

Changeset 14814


Ignore:
Timestamp:
05/23/2010 07:49:21 AM (9 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

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/template.php

    r14768 r14814  
    27632763
    27642764/**
    2765  * {@internal Missing Short Description}}
    2766  *
    2767  * @since unknown
    2768  */
    2769 function wp_remember_old_slug() {
    2770     global $post;
    2771     $name = esc_attr($post->post_name); // just in case
    2772     if ( strlen($name) )
    2773         echo '<input type="hidden" id="wp-old-slug" name="wp-old-slug" value="' . $name . '" />';
    2774 }
    2775 
    2776 /**
    27772765 * Add a meta box to an edit form.
    27782766 *
  • trunk/wp-includes/default-filters.php

    r14295 r14814  
    236236
    237237// Redirect Old Slugs
    238 add_action( 'template_redirect',  'wp_old_slug_redirect'       );
    239 add_action( 'edit_post',          'wp_check_for_changed_slugs' );
    240 add_action( 'edit_form_advanced', 'wp_remember_old_slug'       );
    241 add_action( 'init',               '_show_post_preview'         );
     238add_action( 'template_redirect', 'wp_old_slug_redirect'              );
     239add_action( 'post_updated',      'wp_check_for_changed_slugs', 12, 3 );
     240
     241// Nonce check for Post Previews
     242add_action( 'init', '_show_post_preview' );
    242243
    243244// Timezone
  • 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.