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: http://svn.automattic.com/wordpress/trunk@14814 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
24354ccdb4
commit
378f68a0a0
|
@ -2761,18 +2761,6 @@ function wp_import_upload_form( $action ) {
|
||||||
endif;
|
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.
|
* Add a meta box to an edit form.
|
||||||
*
|
*
|
||||||
|
|
|
@ -236,8 +236,9 @@ add_action( 'end_fetch_post_thumbnail_html', '_wp_post_thumbnail_class_filter_
|
||||||
|
|
||||||
// Redirect Old Slugs
|
// Redirect Old Slugs
|
||||||
add_action( 'template_redirect', 'wp_old_slug_redirect' );
|
add_action( 'template_redirect', 'wp_old_slug_redirect' );
|
||||||
add_action( 'edit_post', 'wp_check_for_changed_slugs' );
|
add_action( 'post_updated', 'wp_check_for_changed_slugs', 12, 3 );
|
||||||
add_action( 'edit_form_advanced', 'wp_remember_old_slug' );
|
|
||||||
|
// Nonce check for Post Previews
|
||||||
add_action( 'init', '_show_post_preview' );
|
add_action( 'init', '_show_post_preview' );
|
||||||
|
|
||||||
// Timezone
|
// Timezone
|
||||||
|
|
|
@ -1655,7 +1655,7 @@ function wp_match_mime_types($wildcard_mime_types, $real_mime_types) {
|
||||||
* @since 2.5.0
|
* @since 2.5.0
|
||||||
*
|
*
|
||||||
* @param string|array $mime_types List of mime types or comma separated string of mime types.
|
* @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.
|
* @return string The SQL AND clause for mime searching.
|
||||||
*/
|
*/
|
||||||
function wp_post_mime_type_where($post_mime_types, $table_alias = '') {
|
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 ) {
|
if ( $update ) {
|
||||||
$post_ID = (int) $ID;
|
$post_ID = (int) $ID;
|
||||||
$guid = get_post_field( 'guid', $post_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
|
// 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);
|
wp_transition_post_status($data['post_status'], $previous_status, $post);
|
||||||
|
|
||||||
if ( $update )
|
if ( $update ) {
|
||||||
do_action('edit_post', $post_ID, $post);
|
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('save_post', $post_ID, $post);
|
||||||
do_action('wp_insert_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.
|
* @param int $post_id Post ID.
|
||||||
* @return int Same as $post_id
|
* @return int Same as $post_id
|
||||||
*/
|
*/
|
||||||
function wp_check_for_changed_slugs($post_id) {
|
function wp_check_for_changed_slugs($post_id, $post, $post_before) {
|
||||||
if ( empty($_POST['wp-old-slug']) )
|
// dont bother if it hasnt changed
|
||||||
return $post_id;
|
if ( $post->post_name == $post_before->post_name )
|
||||||
|
return;
|
||||||
$post = &get_post($post_id);
|
|
||||||
|
|
||||||
// we're only concerned with published posts
|
// we're only concerned with published posts
|
||||||
if ( $post->post_status != 'publish' || $post->post_type != 'post' )
|
if ( $post->post_status != 'publish' || $post->post_type != 'post' )
|
||||||
return $post_id;
|
return;
|
||||||
|
|
||||||
// only bother if the slug has changed
|
|
||||||
if ( $post->post_name == $_POST['wp-old-slug'] )
|
|
||||||
return $post_id;
|
|
||||||
|
|
||||||
$old_slugs = (array) get_post_meta($post_id, '_wp_old_slug');
|
$old_slugs = (array) get_post_meta($post_id, '_wp_old_slug');
|
||||||
|
|
||||||
// if we haven't added this old slug before, add it now
|
// if we haven't added this old slug before, add it now
|
||||||
if ( !count($old_slugs) || !in_array($_POST['wp-old-slug'], $old_slugs) )
|
if ( !in_array($post_before->post_name, $old_slugs) )
|
||||||
add_post_meta($post_id, '_wp_old_slug', $_POST['wp-old-slug']);
|
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 the new slug was used previously, delete it from the list
|
||||||
if ( in_array($post->post_name, $old_slugs) )
|
if ( in_array($post->post_name, $old_slugs) )
|
||||||
delete_post_meta($post_id, '_wp_old_slug', $post->post_name);
|
delete_post_meta($post_id, '_wp_old_slug', $post->post_name);
|
||||||
|
|
||||||
return $post_id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue