WordPress.org

Make WordPress Core

Ticket #11863: 11863-1.patch

File 11863-1.patch, 5.8 KB (added by ericlewis, 6 years ago)

Add error messages when posts are restored from trash; give live post permalink precedence

  • wp-includes/post.php

     
    28592859        } elseif ( in_array( $post_type, $hierarchical_post_types ) ) {
    28602860                // Page slugs must be unique within their own trees. Pages are in a separate
    28612861                // namespace than posts so page slugs are allowed to overlap post slugs.
    2862                 $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";
     2862                $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";
    28632863                $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_ID, $post_parent ) );
    28642864
    28652865                if ( $post_name_check || in_array( $slug, $feeds ) || preg_match( "@^($wp_rewrite->pagination_base)?\d+$@", $slug )  || apply_filters( 'wp_unique_post_slug_is_bad_hierarchical_slug', false, $slug, $post_type, $post_parent ) ) {
     
    28732873                }
    28742874        } else {
    28752875                // Post slugs must be unique across all posts.
    2876                 $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND ID != %d LIMIT 1";
     2876                $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";
    28772877                $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_type, $post_ID ) );
    28782878
    28792879                if ( $post_name_check || in_array( $slug, $feeds ) || apply_filters( 'wp_unique_post_slug_is_bad_flat_slug', false, $slug, $post_type ) ) {
  • wp-admin/includes/post.php

     
    11141114                }
    11151115        }
    11161116
     1117        // Permalink conflict error messages.
     1118        if ( $new_slug && $new_slug != $post_name_abridged ) {
     1119                echo '<div id="message" class="error"><p>';
     1120                $conflicting_post = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->posts WHERE post_name = %s;",$new_slug));
     1121                if ( $conflicting_post->post_status == 'trash' ) {
     1122                        _e('There was a permalink conflict with the post "' . $post->post_title . '" in the trash. <a href="edit.php?post_status=trash&amp;post_type=' . $post->post_type . '">View Trash</a>');
     1123                } else {
     1124                        $conflicting_post_edit_link_url = get_edit_post_link($conflicting_post->ID);
     1125                        $post_type_obj = get_post_type_object( $post->post_type );
     1126                        $conflicting_post_edit_link_html = '<a class="post-edit-link" href="' . $conflicting_post_edit_link_url . '" title="' . esc_attr( $post_type_obj->labels->edit_item ) . '">' . $conflicting_post->post_title . '</a>'; 
     1127                        if ( !empty($conflicting_post) )
     1128                                _e('There was a permalink conflict with the post ' . $conflicting_post_edit_link_html . ', a unique numerical string has been appended to the permalink.');
     1129                }
     1130                echo '</p></div>';
     1131        }
     1132
    11171133        $post_name_html = '<span id="editable-post-name" title="' . $title . '">' . $post_name_abridged . '</span>';
    11181134        $display_link = str_replace(array('%pagename%','%postname%'), $post_name_html, $permalink);
    11191135        $view_link = str_replace(array('%pagename%','%postname%'), $post_name, $permalink);
  • wp-admin/post.php

     
    223223        if ( ! wp_untrash_post($post_id) )
    224224                wp_die( __('Error in restoring from Trash.') );
    225225
     226        $sendback = add_query_arg('ids', $post_id, $sendback);
     227       
    226228        wp_redirect( add_query_arg('untrashed', 1, $sendback) );
    227229        exit();
    228230        break;
  • wp-admin/edit.php

     
    9797                                        wp_die( __('Error in restoring from Trash.') );
    9898
    9999                                $untrashed++;
     100                                $untrashed_posts[] = $post_id;                         
    100101                        }
    101                         $sendback = add_query_arg('untrashed', $untrashed, $sendback);
     102                        $sendback = add_query_arg( 'ids', implode( '+', $untrashed_posts), $sendback );
     103                        $sendback = add_query_arg( 'untrashed', $untrashed, $sendback );
    102104                        break;
    103105                case 'delete':
    104106                        $deleted = 0;
     
    251253if ( isset( $_REQUEST['untrashed'] ) && $untrashed = absint( $_REQUEST['untrashed'] ) ) {
    252254        $messages[] = sprintf( _n( 'Item restored from the Trash.', '%s items restored from the Trash.', $untrashed ), number_format_i18n( $untrashed ) );
    253255}
    254 
    255256if ( $messages )
    256257        echo join( ' ', $messages );
    257258unset( $messages );
     
    259260$_SERVER['REQUEST_URI'] = remove_query_arg( array( 'locked', 'skipped', 'updated', 'deleted', 'trashed', 'untrashed' ), $_SERVER['REQUEST_URI'] );
    260261?>
    261262</p></div>
     263<?php
     264// Post permalink collision errors
     265if ( isset( $_REQUEST['untrashed'] ) && $untrashed = absint( $_REQUEST['untrashed'] ) && isset($_REQUEST['ids']) && $_REQUEST['ids'] ) {
     266        $posts_restored = explode( ' ', $_REQUEST['ids'] );
     267        foreach ( $posts_restored as $id ) {
     268                $post = get_post($id);
     269                if ( $post->post_name != sanitize_title($post->post_title) ) {?>
     270                        <div id="message" class="error"><p>
     271                        <?php printf( __( 'While restoring from trash, the post %s\'s slug was set to %s because of a permalink collision.'), $post->post_title, $post->post_name );
     272                        ?></p>
     273                        </div><?php
     274                }
     275        }
     276}
     277?>
    262278<?php } ?>
    263279
    264280<?php $wp_list_table->views(); ?>
  • wp-admin/css/wp-admin.dev.css

     
    29322932}
    29332933
    29342934#edit-slug-box {
    2935         height: 1em;
    29362935        margin-top: 8px;
    29372936        padding: 0 10px;
    29382937}