WordPress.org

Make WordPress Core

Changes between Initial Version and Version 2 of Ticket #37506


Ignore:
Timestamp:
07/29/2016 06:39:46 AM (5 years ago)
Author:
dd32
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #37506

    • Property Status changed from new to closed
    • Property Resolution changed from to invalid
  • Ticket #37506 – Description

    initial v2  
    44this is the code of the edit.php
    55
    6 <?php
    7 /**
    8  * Edit Posts Administration Screen.
    9  *
    10  * @package WordPress
    11  * @subpackage Administration
    12  */
    13 
    14 /** WordPress Administration Bootstrap */
    15 require_once( dirname( __FILE__ ) . '/admin.php' );
    16 
    17 if ( ! $typenow )
    18         wp_die( __( 'Invalid post type' ) );
    19 
    20 if ( ! in_array( $typenow, get_post_types( array( 'show_ui' => true ) ) ) ) {
    21         wp_die( __( 'You are not allowed to edit posts in this post type.' ) );
    22 }
    23 
    24 if ( 'attachment' === $typenow ) {
    25         if ( wp_redirect( admin_url( 'upload.php' ) ) ) {
    26                 exit;
    27         }
    28 }
    29 
    30 /**
    31  * @global string $post_type
    32  * @global object $post_type_object
    33  */
    34 global $post_type, $post_type_object;
    35 
    36 $post_type = $typenow;
    37 $post_type_object = get_post_type_object( $post_type );
    38 
    39 if ( ! $post_type_object )
    40         wp_die( __( 'Invalid post type' ) );
    41 
    42 if ( ! current_user_can( $post_type_object->cap->edit_posts ) ) {
    43         wp_die(
    44                 '<h1>' . __( 'Cheatin&#8217; uh?' ) . '</h1>' .
    45                 '<p>' . __( 'You are not allowed to edit posts in this post type.' ) . '</p>',
    46                 403
    47         );
    48 }
    49 
    50 $wp_list_table = _get_list_table('WP_Posts_List_Table');
    51 $pagenum = $wp_list_table->get_pagenum();
    52 
    53 // Back-compat for viewing comments of an entry
    54 foreach ( array( 'p', 'attachment_id', 'page_id' ) as $_redirect ) {
    55         if ( ! empty( $_REQUEST[ $_redirect ] ) ) {
    56                 wp_redirect( admin_url( 'edit-comments.php?p=' . absint( $_REQUEST[ $_redirect ] ) ) );
    57                 exit;
    58         }
    59 }
    60 unset( $_redirect );
    61 
    62 if ( 'post' != $post_type ) {
    63         $parent_file = "edit.php?post_type=$post_type";
    64         $submenu_file = "edit.php?post_type=$post_type";
    65         $post_new_file = "post-new.php?post_type=$post_type";
    66 } else {
    67         $parent_file = 'edit.php';
    68         $submenu_file = 'edit.php';
    69         $post_new_file = 'post-new.php';
    70 }
    71 
    72 $doaction = $wp_list_table->current_action();
    73 
    74 if ( $doaction ) {
    75         check_admin_referer('bulk-posts');
    76 
    77         $sendback = remove_query_arg( array('trashed', 'untrashed', 'deleted', 'locked', 'ids'), wp_get_referer() );
    78         if ( ! $sendback )
    79                 $sendback = admin_url( $parent_file );
    80         $sendback = add_query_arg( 'paged', $pagenum, $sendback );
    81         if ( strpos($sendback, 'post.php') !== false )
    82                 $sendback = admin_url($post_new_file);
    83 
    84         if ( 'delete_all' == $doaction ) {
    85                 // Prepare for deletion of all posts with a specified post status (i.e. Empty trash).
    86                 $post_status = preg_replace('/[^a-z0-9_-]+/i', '', $_REQUEST['post_status']);
    87                 // Validate the post status exists.
    88                 if ( get_post_status_object( $post_status ) ) {
    89                         $post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type=%s AND post_status = %s", $post_type, $post_status ) );
    90                 }
    91                 $doaction = 'delete';
    92         } elseif ( isset( $_REQUEST['media'] ) ) {
    93                 $post_ids = $_REQUEST['media'];
    94         } elseif ( isset( $_REQUEST['ids'] ) ) {
    95                 $post_ids = explode( ',', $_REQUEST['ids'] );
    96         } elseif ( !empty( $_REQUEST['post'] ) ) {
    97                 $post_ids = array_map('intval', $_REQUEST['post']);
    98         }
    99 
    100         if ( !isset( $post_ids ) ) {
    101                 wp_redirect( $sendback );
    102                 exit;
    103         }
    104 
    105         switch ( $doaction ) {
    106                 case 'trash':
    107                         $trashed = $locked = 0;
    108 
    109                         foreach ( (array) $post_ids as $post_id ) {
    110                                 if ( !current_user_can( 'delete_post', $post_id) )
    111                                         wp_die( __('You are not allowed to move this item to the Trash.') );
    112 
    113                                 if ( wp_check_post_lock( $post_id ) ) {
    114                                         $locked++;
    115                                         continue;
    116                                 }
    117 
    118                                 if ( !wp_trash_post($post_id) )
    119                                         wp_die( __('Error in moving to Trash.') );
    120 
    121                                 $trashed++;
    122                         }
    123 
    124                         $sendback = add_query_arg( array('trashed' => $trashed, 'ids' => join(',', $post_ids), 'locked' => $locked ), $sendback );
    125                         break;
    126                 case 'untrash':
    127                         $untrashed = 0;
    128                         foreach ( (array) $post_ids as $post_id ) {
    129                                 if ( !current_user_can( 'delete_post', $post_id) )
    130                                         wp_die( __('You are not allowed to restore this item from the Trash.') );
    131 
    132                                 if ( !wp_untrash_post($post_id) )
    133                                         wp_die( __('Error in restoring from Trash.') );
    134 
    135                                 $untrashed++;
    136                         }
    137                         $sendback = add_query_arg('untrashed', $untrashed, $sendback);
    138                         break;
    139                 case 'delete':
    140                         $deleted = 0;
    141                         foreach ( (array) $post_ids as $post_id ) {
    142                                 $post_del = get_post($post_id);
    143 
    144                                 if ( !current_user_can( 'delete_post', $post_id ) )
    145                                         wp_die( __('You are not allowed to delete this item.') );
    146 
    147                                 if ( $post_del->post_type == 'attachment' ) {
    148                                         if ( ! wp_delete_attachment($post_id) )
    149                                                 wp_die( __('Error in deleting.') );
    150                                 } else {
    151                                         if ( !wp_delete_post($post_id) )
    152                                                 wp_die( __('Error in deleting.') );
    153                                 }
    154                                 $deleted++;
    155                         }
    156                         $sendback = add_query_arg('deleted', $deleted, $sendback);
    157                         break;
    158                 case 'edit':
    159                         if ( isset($_REQUEST['bulk_edit']) ) {
    160                                 $done = bulk_edit_posts($_REQUEST);
    161 
    162                                 if ( is_array($done) ) {
    163                                         $done['updated'] = count( $done['updated'] );
    164                                         $done['skipped'] = count( $done['skipped'] );
    165                                         $done['locked'] = count( $done['locked'] );
    166                                         $sendback = add_query_arg( $done, $sendback );
    167                                 }
    168                         }
    169                         break;
    170         }
    171 
    172         $sendback = remove_query_arg( array('action', 'action2', 'tags_input', 'post_author', 'comment_status', 'ping_status', '_status', 'post', 'bulk_edit', 'post_view'), $sendback );
    173 
    174         wp_redirect($sendback);
    175         exit();
    176 } elseif ( ! empty($_REQUEST['_wp_http_referer']) ) {
    177          wp_redirect( remove_query_arg( array('_wp_http_referer', '_wpnonce'), wp_unslash($_SERVER['REQUEST_URI']) ) );
    178          exit;
    179 }
    180 
    181 $wp_list_table->prepare_items();
    182 
    183 wp_enqueue_script('inline-edit-post');
    184 wp_enqueue_script('heartbeat');
    185 
    186 $title = $post_type_object->labels->name;
    187 
    188 if ( 'post' == $post_type ) {
    189         get_current_screen()->add_help_tab( array(
    190         'id'            => 'overview',
    191         'title'         => __('Overview'),
    192         'content'       =>
    193                 '<p>' . __('This screen provides access to all of your posts. You can customize the display of this screen to suit your workflow.') . '</p>'
    194         ) );
    195         get_current_screen()->add_help_tab( array(
    196         'id'            => 'screen-content',
    197         'title'         => __('Screen Content'),
    198         'content'       =>
    199                 '<p>' . __('You can customize the display of this screen&#8217;s contents in a number of ways:') . '</p>' .
    200                 '<ul>' .
    201                         '<li>' . __('You can hide/display columns based on your needs and decide how many posts to list per screen using the Screen Options tab.') . '</li>' .
    202                         '<li>' . __('You can filter the list of posts by post status using the text links in the upper left to show All, Published, Draft, or Trashed posts. The default view is to show all posts.') . '</li>' .
    203                         '<li>' . __('You can view posts in a simple title list or with an excerpt using the Screen Options tab.') . '</li>' .
    204                         '<li>' . __('You can refine the list to show only posts in a specific category or from a specific month by using the dropdown menus above the posts list. Click the Filter button after making your selection. You also can refine the list by clicking on the post author, category or tag in the posts list.') . '</li>' .
    205                 '</ul>'
    206         ) );
    207         get_current_screen()->add_help_tab( array(
    208         'id'            => 'action-links',
    209         'title'         => __('Available Actions'),
    210         'content'       =>
    211                 '<p>' . __('Hovering over a row in the posts list will display action links that allow you to manage your post. You can perform the following actions:') . '</p>' .
    212                 '<ul>' .
    213                         '<li>' . __('<strong>Edit</strong> takes you to the editing screen for that post. You can also reach that screen by clicking on the post title.') . '</li>' .
    214                         '<li>' . __('<strong>Quick Edit</strong> provides inline access to the metadata of your post, allowing you to update post details without leaving this screen.') . '</li>' .
    215                         '<li>' . __('<strong>Trash</strong> removes your post from this list and places it in the trash, from which you can permanently delete it.') . '</li>' .
    216                         '<li>' . __('<strong>Preview</strong> will show you what your draft post will look like if you publish it. View will take you to your live site to view the post. Which link is available depends on your post&#8217;s status.') . '</li>' .
    217                 '</ul>'
    218         ) );
    219         get_current_screen()->add_help_tab( array(
    220         'id'            => 'bulk-actions',
    221         'title'         => __('Bulk Actions'),
    222         'content'       =>
    223                 '<p>' . __('You can also edit or move multiple posts to the trash at once. Select the posts you want to act on using the checkboxes, then select the action you want to take from the Bulk Actions menu and click Apply.') . '</p>' .
    224                                 '<p>' . __('When using Bulk Edit, you can change the metadata (categories, author, etc.) for all selected posts at once. To remove a post from the grouping, just click the x next to its name in the Bulk Edit area that appears.') . '</p>'
    225         ) );
    226 
    227         get_current_screen()->set_help_sidebar(
    228         '<p><strong>' . __('For more information:') . '</strong></p>' .
    229         '<p>' . __('<a href="https://codex.wordpress.org/Posts_Screen" target="_blank">Documentation on Managing Posts</a>') . '</p>' .
    230         '<p>' . __('<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
    231         );
    232 
    233 } elseif ( 'page' == $post_type ) {
    234         get_current_screen()->add_help_tab( array(
    235         'id'            => 'overview',
    236         'title'         => __('Overview'),
    237         'content'       =>
    238                 '<p>' . __('Pages are similar to posts in that they have a title, body text, and associated metadata, but they are different in that they are not part of the chronological blog stream, kind of like permanent posts. Pages are not categorized or tagged, but can have a hierarchy. You can nest pages under other pages by making one the &#8220;Parent&#8221; of the other, creating a group of pages.') . '</p>'
    239         ) );
    240         get_current_screen()->add_help_tab( array(
    241         'id'            => 'managing-pages',
    242         'title'         => __('Managing Pages'),
    243         'content'       =>
    244                 '<p>' . __('Managing pages is very similar to managing posts, and the screens can be customized in the same way.') . '</p>' .
    245                 '<p>' . __('You can also perform the same types of actions, including narrowing the list by using the filters, acting on a page using the action links that appear when you hover over a row, or using the Bulk Actions menu to edit the metadata for multiple pages at once.') . '</p>'
    246         ) );
    247 
    248         get_current_screen()->set_help_sidebar(
    249         '<p><strong>' . __('For more information:') . '</strong></p>' .
    250         '<p>' . __('<a href="https://codex.wordpress.org/Pages_Screen" target="_blank">Documentation on Managing Pages</a>') . '</p>' .
    251         '<p>' . __('<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
    252         );
    253 
    254 }
    255 
    256 get_current_screen()->set_screen_reader_content( array(
    257         'heading_views'      => $post_type_object->labels->filter_items_list,
    258         'heading_pagination' => $post_type_object->labels->items_list_navigation,
    259         'heading_list'       => $post_type_object->labels->items_list,
    260 ) );
    261 
    262 add_screen_option( 'per_page', array( 'default' => 20, 'option' => 'edit_' . $post_type . '_per_page' ) );
    263 
    264 $bulk_counts = array(
    265         'updated'   => isset( $_REQUEST['updated'] )   ? absint( $_REQUEST['updated'] )   : 0,
    266         'locked'    => isset( $_REQUEST['locked'] )    ? absint( $_REQUEST['locked'] )    : 0,
    267         'deleted'   => isset( $_REQUEST['deleted'] )   ? absint( $_REQUEST['deleted'] )   : 0,
    268         'trashed'   => isset( $_REQUEST['trashed'] )   ? absint( $_REQUEST['trashed'] )   : 0,
    269         'untrashed' => isset( $_REQUEST['untrashed'] ) ? absint( $_REQUEST['untrashed'] ) : 0,
    270 );
    271 
    272 $bulk_messages = array();
    273 $bulk_messages['post'] = array(
    274         'updated'   => _n( '%s post updated.', '%s posts updated.', $bulk_counts['updated'] ),
    275         'locked'    => ( 1 == $bulk_counts['locked'] ) ? __( '1 post not updated, somebody is editing it.' ) :
    276                            _n( '%s post not updated, somebody is editing it.', '%s posts not updated, somebody is editing them.', $bulk_counts['locked'] ),
    277         'deleted'   => _n( '%s post permanently deleted.', '%s posts permanently deleted.', $bulk_counts['deleted'] ),
    278         'trashed'   => _n( '%s post moved to the Trash.', '%s posts moved to the Trash.', $bulk_counts['trashed'] ),
    279         'untrashed' => _n( '%s post restored from the Trash.', '%s posts restored from the Trash.', $bulk_counts['untrashed'] ),
    280 );
    281 $bulk_messages['page'] = array(
    282         'updated'   => _n( '%s page updated.', '%s pages updated.', $bulk_counts['updated'] ),
    283         'locked'    => ( 1 == $bulk_counts['locked'] ) ? __( '1 page not updated, somebody is editing it.' ) :
    284                            _n( '%s page not updated, somebody is editing it.', '%s pages not updated, somebody is editing them.', $bulk_counts['locked'] ),
    285         'deleted'   => _n( '%s page permanently deleted.', '%s pages permanently deleted.', $bulk_counts['deleted'] ),
    286         'trashed'   => _n( '%s page moved to the Trash.', '%s pages moved to the Trash.', $bulk_counts['trashed'] ),
    287         'untrashed' => _n( '%s page restored from the Trash.', '%s pages restored from the Trash.', $bulk_counts['untrashed'] ),
    288 );
    289 
    290 /**
    291  * Filter the bulk action updated messages.
    292  *
    293  * By default, custom post types use the messages for the 'post' post type.
    294  *
    295  * @since 3.7.0
    296  *
    297  * @param array $bulk_messages Arrays of messages, each keyed by the corresponding post type. Messages are
    298  *                             keyed with 'updated', 'locked', 'deleted', 'trashed', and 'untrashed'.
    299  * @param array $bulk_counts   Array of item counts for each message, used to build internationalized strings.
    300  */
    301 $bulk_messages = apply_filters( 'bulk_post_updated_messages', $bulk_messages, $bulk_counts );
    302 $bulk_counts = array_filter( $bulk_counts );
    303 
    304 require_once( ABSPATH . 'wp-admin/admin-header.php' );
    305 ?>
    306 <div class="wrap">
    307 <h1><?php
    308 echo esc_html( $post_type_object->labels->name );
    309 if ( current_user_can( $post_type_object->cap->create_posts ) )
    310         echo ' <a href="' . esc_url( admin_url( $post_new_file ) ) . '" class="page-title-action">' . esc_html( $post_type_object->labels->add_new ) . '</a>';
    311 
    312 if ( isset( $_REQUEST['s'] ) && strlen( $_REQUEST['s'] ) ) {
    313         /* translators: %s: search keywords */
    314         printf( ' <span class="subtitle">' . __( 'Search results for &#8220;%s&#8221;' ) . '</span>', get_search_query() );
    315 }
    316 ?></h1>
    317 
    318 <?php
    319 // If we have a bulk message to issue:
    320 $messages = array();
    321 foreach ( $bulk_counts as $message => $count ) {
    322         if ( isset( $bulk_messages[ $post_type ][ $message ] ) )
    323                 $messages[] = sprintf( $bulk_messages[ $post_type ][ $message ], number_format_i18n( $count ) );
    324         elseif ( isset( $bulk_messages['post'][ $message ] ) )
    325                 $messages[] = sprintf( $bulk_messages['post'][ $message ], number_format_i18n( $count ) );
    326 
    327         if ( $message == 'trashed' && isset( $_REQUEST['ids'] ) ) {
    328                 $ids = preg_replace( '/[^0-9,]/', '', $_REQUEST['ids'] );
    329                 $messages[] = '<a href="' . esc_url( wp_nonce_url( "edit.php?post_type=$post_type&doaction=undo&action=untrash&ids=$ids", "bulk-posts" ) ) . '">' . __('Undo') . '</a>';
    330         }
    331 }
    332 
    333 if ( $messages )
    334         echo '<div id="message" class="updated notice is-dismissible"><p>' . join( ' ', $messages ) . '</p></div>';
    335 unset( $messages );
    336 
    337 $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'locked', 'skipped', 'updated', 'deleted', 'trashed', 'untrashed' ), $_SERVER['REQUEST_URI'] );
    338 ?>
    339 
    340 <?php $wp_list_table->views(); ?>
    341 
    342 <form id="posts-filter" method="get">
    343 
    344 <?php $wp_list_table->search_box( $post_type_object->labels->search_items, 'post' ); ?>
    345 
    346 <input type="hidden" name="post_status" class="post_status_page" value="<?php echo !empty($_REQUEST['post_status']) ? esc_attr($_REQUEST['post_status']) : 'all'; ?>" />
    347 <input type="hidden" name="post_type" class="post_type_page" value="<?php echo $post_type; ?>" />
    348 <?php if ( ! empty( $_REQUEST['show_sticky'] ) ) { ?>
    349 <input type="hidden" name="show_sticky" value="1" />
    350 <?php } ?>
    351 
    352 <?php $wp_list_table->display(); ?>
    353 
    354 </form>
    355 
    356 <?php
    357 if ( $wp_list_table->has_items() )
    358         $wp_list_table->inline_edit();
    359 ?>
    360 
    361 <div id="ajax-response"></div>
    362 <br class="clear" />
    363 </div>
    364 
    365 <?php
    366 include( ABSPATH . 'wp-admin/admin-footer.php' );
     6[removed the contents of wp-admin/edit.php from display]