WordPress build repository browser

source: branches/5.2/wp-admin/edit.php

Last change on this file was 44949, checked in by pento, 3 years ago

Help: Update support forum links.

There are a lot of places in Core that link to https://wordpress.org/support/ for the support forums, but that's now the URL for HelpHub. The new forums link is https://wordpress.org/support/forums/.

Props jitendrabanjara1991, dilipbheda, mukesh27, ianbelanger.
Fixes #46790.

Built from https://develop.svn.wordpress.org/trunk@45140

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 16.8 KB
Line 
1<?php
2/**
3 * Edit Posts Administration Screen.
4 *
5 * @package WordPress
6 * @subpackage Administration
7 */
8
9/** WordPress Administration Bootstrap */
10require_once( dirname( __FILE__ ) . '/admin.php' );
11
12if ( ! $typenow ) {
13        wp_die( __( 'Invalid post type.' ) );
14}
15
16if ( ! in_array( $typenow, get_post_types( array( 'show_ui' => true ) ) ) ) {
17        wp_die( __( 'Sorry, you are not allowed to edit posts in this post type.' ) );
18}
19
20if ( 'attachment' === $typenow ) {
21        if ( wp_redirect( admin_url( 'upload.php' ) ) ) {
22                exit;
23        }
24}
25
26/**
27 * @global string       $post_type
28 * @global WP_Post_Type $post_type_object
29 */
30global $post_type, $post_type_object;
31
32$post_type        = $typenow;
33$post_type_object = get_post_type_object( $post_type );
34
35if ( ! $post_type_object ) {
36        wp_die( __( 'Invalid post type.' ) );
37}
38
39if ( ! current_user_can( $post_type_object->cap->edit_posts ) ) {
40        wp_die(
41                '<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' .
42                '<p>' . __( 'Sorry, you are not allowed to edit posts in this post type.' ) . '</p>',
43                403
44        );
45}
46
47$wp_list_table = _get_list_table( 'WP_Posts_List_Table' );
48$pagenum       = $wp_list_table->get_pagenum();
49
50// Back-compat for viewing comments of an entry
51foreach ( array( 'p', 'attachment_id', 'page_id' ) as $_redirect ) {
52        if ( ! empty( $_REQUEST[ $_redirect ] ) ) {
53                wp_redirect( admin_url( 'edit-comments.php?p=' . absint( $_REQUEST[ $_redirect ] ) ) );
54                exit;
55        }
56}
57unset( $_redirect );
58
59if ( 'post' != $post_type ) {
60        $parent_file   = "edit.php?post_type=$post_type";
61        $submenu_file  = "edit.php?post_type=$post_type";
62        $post_new_file = "post-new.php?post_type=$post_type";
63} else {
64        $parent_file   = 'edit.php';
65        $submenu_file  = 'edit.php';
66        $post_new_file = 'post-new.php';
67}
68
69$doaction = $wp_list_table->current_action();
70
71if ( $doaction ) {
72        check_admin_referer( 'bulk-posts' );
73
74        $sendback = remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'locked', 'ids' ), wp_get_referer() );
75        if ( ! $sendback ) {
76                $sendback = admin_url( $parent_file );
77        }
78        $sendback = add_query_arg( 'paged', $pagenum, $sendback );
79        if ( strpos( $sendback, 'post.php' ) !== false ) {
80                $sendback = admin_url( $post_new_file );
81        }
82
83        if ( 'delete_all' == $doaction ) {
84                // Prepare for deletion of all posts with a specified post status (i.e. Empty trash).
85                $post_status = preg_replace( '/[^a-z0-9_-]+/i', '', $_REQUEST['post_status'] );
86                // Validate the post status exists.
87                if ( get_post_status_object( $post_status ) ) {
88                        $post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type=%s AND post_status = %s", $post_type, $post_status ) );
89                }
90                $doaction = 'delete';
91        } elseif ( isset( $_REQUEST['media'] ) ) {
92                $post_ids = $_REQUEST['media'];
93        } elseif ( isset( $_REQUEST['ids'] ) ) {
94                $post_ids = explode( ',', $_REQUEST['ids'] );
95        } elseif ( ! empty( $_REQUEST['post'] ) ) {
96                $post_ids = array_map( 'intval', $_REQUEST['post'] );
97        }
98
99        if ( ! isset( $post_ids ) ) {
100                wp_redirect( $sendback );
101                exit;
102        }
103
104        switch ( $doaction ) {
105                case 'trash':
106                        $trashed = $locked = 0;
107
108                        foreach ( (array) $post_ids as $post_id ) {
109                                if ( ! current_user_can( 'delete_post', $post_id ) ) {
110                                        wp_die( __( 'Sorry, you are not allowed to move this item to the Trash.' ) );
111                                }
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
122                                $trashed++;
123                        }
124
125                        $sendback = add_query_arg(
126                                array(
127                                        'trashed' => $trashed,
128                                        'ids'     => join( ',', $post_ids ),
129                                        'locked'  => $locked,
130                                ),
131                                $sendback
132                        );
133                        break;
134                case 'untrash':
135                        $untrashed = 0;
136                        foreach ( (array) $post_ids as $post_id ) {
137                                if ( ! current_user_can( 'delete_post', $post_id ) ) {
138                                        wp_die( __( 'Sorry, you are not allowed to restore this item from the Trash.' ) );
139                                }
140
141                                if ( ! wp_untrash_post( $post_id ) ) {
142                                        wp_die( __( 'Error in restoring from Trash.' ) );
143                                }
144
145                                $untrashed++;
146                        }
147                        $sendback = add_query_arg( 'untrashed', $untrashed, $sendback );
148                        break;
149                case 'delete':
150                        $deleted = 0;
151                        foreach ( (array) $post_ids as $post_id ) {
152                                $post_del = get_post( $post_id );
153
154                                if ( ! current_user_can( 'delete_post', $post_id ) ) {
155                                        wp_die( __( 'Sorry, you are not allowed to delete this item.' ) );
156                                }
157
158                                if ( $post_del->post_type == 'attachment' ) {
159                                        if ( ! wp_delete_attachment( $post_id ) ) {
160                                                wp_die( __( 'Error in deleting.' ) );
161                                        }
162                                } else {
163                                        if ( ! wp_delete_post( $post_id ) ) {
164                                                wp_die( __( 'Error in deleting.' ) );
165                                        }
166                                }
167                                $deleted++;
168                        }
169                        $sendback = add_query_arg( 'deleted', $deleted, $sendback );
170                        break;
171                case 'edit':
172                        if ( isset( $_REQUEST['bulk_edit'] ) ) {
173                                $done = bulk_edit_posts( $_REQUEST );
174
175                                if ( is_array( $done ) ) {
176                                        $done['updated'] = count( $done['updated'] );
177                                        $done['skipped'] = count( $done['skipped'] );
178                                        $done['locked']  = count( $done['locked'] );
179                                        $sendback        = add_query_arg( $done, $sendback );
180                                }
181                        }
182                        break;
183                default:
184                        /** This action is documented in wp-admin/edit-comments.php */
185                        $sendback = apply_filters( 'handle_bulk_actions-' . get_current_screen()->id, $sendback, $doaction, $post_ids );
186                        break;
187        }
188
189        $sendback = remove_query_arg( array( 'action', 'action2', 'tags_input', 'post_author', 'comment_status', 'ping_status', '_status', 'post', 'bulk_edit', 'post_view' ), $sendback );
190
191        wp_redirect( $sendback );
192        exit();
193} elseif ( ! empty( $_REQUEST['_wp_http_referer'] ) ) {
194        wp_redirect( remove_query_arg( array( '_wp_http_referer', '_wpnonce' ), wp_unslash( $_SERVER['REQUEST_URI'] ) ) );
195        exit;
196}
197
198$wp_list_table->prepare_items();
199
200wp_enqueue_script( 'inline-edit-post' );
201wp_enqueue_script( 'heartbeat' );
202
203if ( 'wp_block' === $post_type ) {
204        wp_enqueue_script( 'wp-list-reusable-blocks' );
205        wp_enqueue_style( 'wp-list-reusable-blocks' );
206}
207
208$title = $post_type_object->labels->name;
209
210if ( 'post' == $post_type ) {
211        get_current_screen()->add_help_tab(
212                array(
213                        'id'      => 'overview',
214                        'title'   => __( 'Overview' ),
215                        'content' =>
216                                         '<p>' . __( 'This screen provides access to all of your posts. You can customize the display of this screen to suit your workflow.' ) . '</p>',
217                )
218        );
219        get_current_screen()->add_help_tab(
220                array(
221                        'id'      => 'screen-content',
222                        'title'   => __( 'Screen Content' ),
223                        'content' =>
224                                         '<p>' . __( 'You can customize the display of this screen&#8217;s contents in a number of ways:' ) . '</p>' .
225                                         '<ul>' .
226                                                 '<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>' .
227                                                 '<li>' . __( 'You can filter the list of posts by post status using the text links above the posts list to only show posts with that status. The default view is to show all posts.' ) . '</li>' .
228                                                 '<li>' . __( 'You can view posts in a simple title list or with an excerpt using the Screen Options tab.' ) . '</li>' .
229                                                 '<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>' .
230                                         '</ul>',
231                )
232        );
233        get_current_screen()->add_help_tab(
234                array(
235                        'id'      => 'action-links',
236                        'title'   => __( 'Available Actions' ),
237                        'content' =>
238                                         '<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>' .
239                                         '<ul>' .
240                                                 '<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>' .
241                                                 '<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>' .
242                                                 '<li>' . __( '<strong>Trash</strong> removes your post from this list and places it in the trash, from which you can permanently delete it.' ) . '</li>' .
243                                                 '<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>' .
244                                         '</ul>',
245                )
246        );
247        get_current_screen()->add_help_tab(
248                array(
249                        'id'      => 'bulk-actions',
250                        'title'   => __( 'Bulk Actions' ),
251                        'content' =>
252                                         '<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>' .
253                                                         '<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>',
254                )
255        );
256
257        get_current_screen()->set_help_sidebar(
258                '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
259                '<p>' . __( '<a href="https://codex.wordpress.org/Posts_Screen">Documentation on Managing Posts</a>' ) . '</p>' .
260                '<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
261        );
262
263} elseif ( 'page' == $post_type ) {
264        get_current_screen()->add_help_tab(
265                array(
266                        'id'      => 'overview',
267                        'title'   => __( 'Overview' ),
268                        'content' =>
269                                         '<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>',
270                )
271        );
272        get_current_screen()->add_help_tab(
273                array(
274                        'id'      => 'managing-pages',
275                        'title'   => __( 'Managing Pages' ),
276                        'content' =>
277                                         '<p>' . __( 'Managing pages is very similar to managing posts, and the screens can be customized in the same way.' ) . '</p>' .
278                                         '<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>',
279                )
280        );
281
282        get_current_screen()->set_help_sidebar(
283                '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
284                '<p>' . __( '<a href="https://codex.wordpress.org/Pages_Screen">Documentation on Managing Pages</a>' ) . '</p>' .
285                '<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
286        );
287
288}
289
290get_current_screen()->set_screen_reader_content(
291        array(
292                'heading_views'      => $post_type_object->labels->filter_items_list,
293                'heading_pagination' => $post_type_object->labels->items_list_navigation,
294                'heading_list'       => $post_type_object->labels->items_list,
295        )
296);
297
298add_screen_option(
299        'per_page',
300        array(
301                'default' => 20,
302                'option'  => 'edit_' . $post_type . '_per_page',
303        )
304);
305
306$bulk_counts = array(
307        'updated'   => isset( $_REQUEST['updated'] ) ? absint( $_REQUEST['updated'] ) : 0,
308        'locked'    => isset( $_REQUEST['locked'] ) ? absint( $_REQUEST['locked'] ) : 0,
309        'deleted'   => isset( $_REQUEST['deleted'] ) ? absint( $_REQUEST['deleted'] ) : 0,
310        'trashed'   => isset( $_REQUEST['trashed'] ) ? absint( $_REQUEST['trashed'] ) : 0,
311        'untrashed' => isset( $_REQUEST['untrashed'] ) ? absint( $_REQUEST['untrashed'] ) : 0,
312);
313
314$bulk_messages             = array();
315$bulk_messages['post']     = array(
316        'updated'   => _n( '%s post updated.', '%s posts updated.', $bulk_counts['updated'] ),
317        'locked'    => ( 1 == $bulk_counts['locked'] ) ? __( '1 post not updated, somebody is editing it.' ) :
318                                        _n( '%s post not updated, somebody is editing it.', '%s posts not updated, somebody is editing them.', $bulk_counts['locked'] ),
319        'deleted'   => _n( '%s post permanently deleted.', '%s posts permanently deleted.', $bulk_counts['deleted'] ),
320        'trashed'   => _n( '%s post moved to the Trash.', '%s posts moved to the Trash.', $bulk_counts['trashed'] ),
321        'untrashed' => _n( '%s post restored from the Trash.', '%s posts restored from the Trash.', $bulk_counts['untrashed'] ),
322);
323$bulk_messages['page']     = array(
324        'updated'   => _n( '%s page updated.', '%s pages updated.', $bulk_counts['updated'] ),
325        'locked'    => ( 1 == $bulk_counts['locked'] ) ? __( '1 page not updated, somebody is editing it.' ) :
326                                        _n( '%s page not updated, somebody is editing it.', '%s pages not updated, somebody is editing them.', $bulk_counts['locked'] ),
327        'deleted'   => _n( '%s page permanently deleted.', '%s pages permanently deleted.', $bulk_counts['deleted'] ),
328        'trashed'   => _n( '%s page moved to the Trash.', '%s pages moved to the Trash.', $bulk_counts['trashed'] ),
329        'untrashed' => _n( '%s page restored from the Trash.', '%s pages restored from the Trash.', $bulk_counts['untrashed'] ),
330);
331$bulk_messages['wp_block'] = array(
332        'updated'   => _n( '%s block updated.', '%s blocks updated.', $bulk_counts['updated'] ),
333        'locked'    => ( 1 == $bulk_counts['locked'] ) ? __( '1 block not updated, somebody is editing it.' ) : _n( '%s block not updated, somebody is editing it.', '%s blocks not updated, somebody is editing them.', $bulk_counts['locked'] ),
334        'deleted'   => _n( '%s block permanently deleted.', '%s blocks permanently deleted.', $bulk_counts['deleted'] ),
335        'trashed'   => _n( '%s block moved to the Trash.', '%s blocks moved to the Trash.', $bulk_counts['trashed'] ),
336        'untrashed' => _n( '%s block restored from the Trash.', '%s blocks restored from the Trash.', $bulk_counts['untrashed'] ),
337);
338
339/**
340 * Filters the bulk action updated messages.
341 *
342 * By default, custom post types use the messages for the 'post' post type.
343 *
344 * @since 3.7.0
345 *
346 * @param array[] $bulk_messages Arrays of messages, each keyed by the corresponding post type. Messages are
347 *                               keyed with 'updated', 'locked', 'deleted', 'trashed', and 'untrashed'.
348 * @param int[]   $bulk_counts   Array of item counts for each message, used to build internationalized strings.
349 */
350$bulk_messages = apply_filters( 'bulk_post_updated_messages', $bulk_messages, $bulk_counts );
351$bulk_counts   = array_filter( $bulk_counts );
352
353require_once( ABSPATH . 'wp-admin/admin-header.php' );
354?>
355<div class="wrap">
356<h1 class="wp-heading-inline">
357<?php
358echo esc_html( $post_type_object->labels->name );
359?>
360</h1>
361
362<?php
363if ( current_user_can( $post_type_object->cap->create_posts ) ) {
364        echo ' <a href="' . esc_url( admin_url( $post_new_file ) ) . '" class="page-title-action">' . esc_html( $post_type_object->labels->add_new ) . '</a>';
365}
366
367if ( isset( $_REQUEST['s'] ) && strlen( $_REQUEST['s'] ) ) {
368        /* translators: %s: search keywords */
369        printf( ' <span class="subtitle">' . __( 'Search results for &#8220;%s&#8221;' ) . '</span>', get_search_query() );
370}
371?>
372
373<hr class="wp-header-end">
374
375<?php
376// If we have a bulk message to issue:
377$messages = array();
378foreach ( $bulk_counts as $message => $count ) {
379        if ( isset( $bulk_messages[ $post_type ][ $message ] ) ) {
380                $messages[] = sprintf( $bulk_messages[ $post_type ][ $message ], number_format_i18n( $count ) );
381        } elseif ( isset( $bulk_messages['post'][ $message ] ) ) {
382                $messages[] = sprintf( $bulk_messages['post'][ $message ], number_format_i18n( $count ) );
383        }
384
385        if ( $message == 'trashed' && isset( $_REQUEST['ids'] ) ) {
386                $ids        = preg_replace( '/[^0-9,]/', '', $_REQUEST['ids'] );
387                $messages[] = '<a href="' . esc_url( wp_nonce_url( "edit.php?post_type=$post_type&doaction=undo&action=untrash&ids=$ids", 'bulk-posts' ) ) . '">' . __( 'Undo' ) . '</a>';
388        }
389}
390
391if ( $messages ) {
392        echo '<div id="message" class="updated notice is-dismissible"><p>' . join( ' ', $messages ) . '</p></div>';
393}
394unset( $messages );
395
396$_SERVER['REQUEST_URI'] = remove_query_arg( array( 'locked', 'skipped', 'updated', 'deleted', 'trashed', 'untrashed' ), $_SERVER['REQUEST_URI'] );
397?>
398
399<?php $wp_list_table->views(); ?>
400
401<form id="posts-filter" method="get">
402
403<?php $wp_list_table->search_box( $post_type_object->labels->search_items, 'post' ); ?>
404
405<input type="hidden" name="post_status" class="post_status_page" value="<?php echo ! empty( $_REQUEST['post_status'] ) ? esc_attr( $_REQUEST['post_status'] ) : 'all'; ?>" />
406<input type="hidden" name="post_type" class="post_type_page" value="<?php echo $post_type; ?>" />
407
408<?php if ( ! empty( $_REQUEST['author'] ) ) { ?>
409<input type="hidden" name="author" value="<?php echo esc_attr( $_REQUEST['author'] ); ?>" />
410<?php } ?>
411
412<?php if ( ! empty( $_REQUEST['show_sticky'] ) ) { ?>
413<input type="hidden" name="show_sticky" value="1" />
414<?php } ?>
415
416<?php $wp_list_table->display(); ?>
417
418</form>
419
420<?php
421if ( $wp_list_table->has_items() ) {
422        $wp_list_table->inline_edit();
423}
424?>
425
426<div id="ajax-response"></div>
427<br class="clear" />
428</div>
429
430<?php
431include( ABSPATH . 'wp-admin/admin-footer.php' );
Note: See TracBrowser for help on using the repository browser.