Index: wp-admin/edit.php =================================================================== --- wp-admin/edit.php (revision 14044) +++ wp-admin/edit.php (working copy) @@ -203,9 +203,12 @@ unset($_GET['trashed']); } -if ( isset($_GET['untrashed']) && (int) $_GET['untrashed'] ) { +if ( isset($_GET['untrashed']) && (int) $_GET['untrashed'] && !$_GET['conflict']) { printf( _n( 'Item restored from the trash.', '%s items restored from the trash.', $_GET['untrashed'] ), number_format_i18n( $_GET['untrashed'] ) ); unset($_GET['undeleted']); +}elseif ( (isset($_GET['untrashed']) && (int) $_GET['untrashed']) && (isset($_GET['conflict']) && (int) $_GET['conflict']) ) { + printf( _n( 'Item restored from the trash, but there was a permalink conflict. The restored post\'s permalink was updated.', '%s items restored from the trash, but there was a permalink conflict.', $_GET['untrashed'] ), number_format_i18n( $_GET['untrashed'] ) ); + unset($_GET['undeleted']); } $_SERVER['REQUEST_URI'] = remove_query_arg( array('locked', 'skipped', 'updated', 'deleted', 'trashed', 'untrashed'), $_SERVER['REQUEST_URI'] ); Index: wp-admin/post.php =================================================================== --- wp-admin/post.php (revision 14044) +++ wp-admin/post.php (working copy) @@ -232,6 +232,8 @@ break; case 'untrash': + global $permalink_conflict; + check_admin_referer('untrash-' . $post_type . '_' . $post_id); if ( !current_user_can($post_type_object->delete_cap, $post_id) ) @@ -240,7 +242,12 @@ if ( ! wp_untrash_post($post_id) ) wp_die( __('Error in restoring from trash...') ); - wp_redirect( add_query_arg('untrashed', 1, $sendback) ); + If($permalink_conflict) { + wp_redirect( add_query_arg(array('untrashed' => 1,'conflict' => 1), $sendback) ); + }Else{ + wp_redirect( add_query_arg('untrashed', 1, $sendback) ); + } + exit(); break; Index: wp-includes/post.php =================================================================== --- wp-includes/post.php (revision 14044) +++ wp-includes/post.php (working copy) @@ -1750,6 +1750,8 @@ * @return mixed False on failure */ function wp_untrash_post($post_id = 0) { + global $permalink_conflict; + if ( !$post = wp_get_single_post($post_id, ARRAY_A) ) return $post; @@ -1765,8 +1767,14 @@ delete_post_meta($post_id, '_wp_trash_meta_status'); delete_post_meta($post_id, '_wp_trash_meta_time'); + $orig_permalink = get_permalink($post_id); + wp_insert_post($post); + If($orig_permalink != get_permalink($post_id)) { + $permalink_conflict = true; + } + wp_untrash_post_comments($post_id); do_action('untrashed_post', $post_id); @@ -2430,7 +2438,7 @@ } elseif ( in_array( $post_type, $hierarchical_post_types ) ) { // Page slugs must be unique within their own trees. Pages are in a separate // namespace than posts so page slugs are allowed to overlap post slugs. - $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type IN ( '" . implode( "', '", esc_sql( $hierarchical_post_types ) ) . "' ) AND ID != %d AND post_parent = %d LIMIT 1"; + $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type IN ( '" . implode( "', '", esc_sql( $hierarchical_post_types ) ) . "' ) AND ID != %d AND post_parent = %d AND post_status <> 'trash' LIMIT 1"; $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_ID, $post_parent ) ); if ( $post_name_check || in_array( $slug, $feeds ) || preg_match( '@^(page)?\d+$@', $slug ) ) { @@ -2444,7 +2452,7 @@ } } else { // Post slugs must be unique across all posts. - $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND ID != %d LIMIT 1"; + $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND ID != %d AND post_status <> 'trash' LIMIT 1"; $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_type, $post_ID ) ); if ( $post_name_check || in_array( $slug, $feeds ) ) {