[ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Edit Posts Administration Screen. 4 * 5 * @package WordPress 6 * @subpackage Administration 7 */ 8 9 /** WordPress Administration Bootstrap */ 10 require_once __DIR__ . '/admin.php'; 11 12 /** 13 * @global string $typenow The post type of the current screen. 14 */ 15 global $typenow; 16 17 if ( ! $typenow ) { 18 wp_die( __( 'Invalid post type.' ) ); 19 } 20 21 if ( ! in_array( $typenow, get_post_types( array( 'show_ui' => true ) ), true ) ) { 22 wp_die( __( 'Sorry, you are not allowed to edit posts in this post type.' ) ); 23 } 24 25 if ( 'attachment' === $typenow ) { 26 if ( wp_redirect( admin_url( 'upload.php' ) ) ) { 27 exit; 28 } 29 } 30 31 /** 32 * @global string $post_type Global post type. 33 * @global WP_Post_Type $post_type_object Global post type object. 34 */ 35 global $post_type, $post_type_object; 36 37 $post_type = $typenow; 38 $post_type_object = get_post_type_object( $post_type ); 39 40 if ( ! $post_type_object ) { 41 wp_die( __( 'Invalid post type.' ) ); 42 } 43 44 if ( ! current_user_can( $post_type_object->cap->edit_posts ) ) { 45 wp_die( 46 '<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' . 47 '<p>' . __( 'Sorry, you are not allowed to edit posts in this post type.' ) . '</p>', 48 403 49 ); 50 } 51 52 $wp_list_table = _get_list_table( 'WP_Posts_List_Table' ); 53 $pagenum = $wp_list_table->get_pagenum(); 54 55 // Back-compat for viewing comments of an entry. 56 foreach ( array( 'p', 'attachment_id', 'page_id' ) as $_redirect ) { 57 if ( ! empty( $_REQUEST[ $_redirect ] ) ) { 58 wp_redirect( admin_url( 'edit-comments.php?p=' . absint( $_REQUEST[ $_redirect ] ) ) ); 59 exit; 60 } 61 } 62 unset( $_redirect ); 63 64 if ( 'post' !== $post_type ) { 65 $parent_file = "edit.php?post_type=$post_type"; 66 $submenu_file = "edit.php?post_type=$post_type"; 67 $post_new_file = "post-new.php?post_type=$post_type"; 68 } else { 69 $parent_file = 'edit.php'; 70 $submenu_file = 'edit.php'; 71 $post_new_file = 'post-new.php'; 72 } 73 74 $doaction = $wp_list_table->current_action(); 75 76 if ( $doaction ) { 77 check_admin_referer( 'bulk-posts' ); 78 79 $sendback = remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'locked', 'ids' ), wp_get_referer() ); 80 if ( ! $sendback ) { 81 $sendback = admin_url( $parent_file ); 82 } 83 $sendback = add_query_arg( 'paged', $pagenum, $sendback ); 84 if ( str_contains( $sendback, 'post.php' ) ) { 85 $sendback = admin_url( $post_new_file ); 86 } 87 88 $post_ids = array(); 89 90 if ( 'delete_all' === $doaction ) { 91 // Prepare for deletion of all posts with a specified post status (i.e. Empty Trash). 92 $post_status = preg_replace( '/[^a-z0-9_-]+/i', '', $_REQUEST['post_status'] ); 93 // Validate the post status exists. 94 if ( get_post_status_object( $post_status ) ) { 95 /** 96 * @global wpdb $wpdb WordPress database abstraction object. 97 */ 98 global $wpdb; 99 100 $post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type=%s AND post_status = %s", $post_type, $post_status ) ); 101 } 102 $doaction = 'delete'; 103 } elseif ( isset( $_REQUEST['media'] ) ) { 104 $post_ids = $_REQUEST['media']; 105 } elseif ( isset( $_REQUEST['ids'] ) ) { 106 $post_ids = explode( ',', $_REQUEST['ids'] ); 107 } elseif ( ! empty( $_REQUEST['post'] ) ) { 108 $post_ids = array_map( 'intval', $_REQUEST['post'] ); 109 } 110 111 if ( empty( $post_ids ) ) { 112 wp_redirect( $sendback ); 113 exit; 114 } 115 116 switch ( $doaction ) { 117 case 'trash': 118 $trashed = 0; 119 $locked = 0; 120 121 foreach ( (array) $post_ids as $post_id ) { 122 if ( ! current_user_can( 'delete_post', $post_id ) ) { 123 wp_die( __( 'Sorry, you are not allowed to move this item to the Trash.' ) ); 124 } 125 126 if ( wp_check_post_lock( $post_id ) ) { 127 ++$locked; 128 continue; 129 } 130 131 if ( ! wp_trash_post( $post_id ) ) { 132 wp_die( __( 'Error in moving the item to Trash.' ) ); 133 } 134 135 ++$trashed; 136 } 137 138 $sendback = add_query_arg( 139 array( 140 'trashed' => $trashed, 141 'ids' => implode( ',', $post_ids ), 142 'locked' => $locked, 143 ), 144 $sendback 145 ); 146 break; 147 case 'untrash': 148 $untrashed = 0; 149 150 if ( isset( $_GET['doaction'] ) && ( 'undo' === $_GET['doaction'] ) ) { 151 add_filter( 'wp_untrash_post_status', 'wp_untrash_post_set_previous_status', 10, 3 ); 152 } 153 154 foreach ( (array) $post_ids as $post_id ) { 155 if ( ! current_user_can( 'delete_post', $post_id ) ) { 156 wp_die( __( 'Sorry, you are not allowed to restore this item from the Trash.' ) ); 157 } 158 159 if ( ! wp_untrash_post( $post_id ) ) { 160 wp_die( __( 'Error in restoring the item from Trash.' ) ); 161 } 162 163 ++$untrashed; 164 } 165 $sendback = add_query_arg( 'untrashed', $untrashed, $sendback ); 166 167 remove_filter( 'wp_untrash_post_status', 'wp_untrash_post_set_previous_status', 10 ); 168 169 break; 170 case 'delete': 171 $deleted = 0; 172 foreach ( (array) $post_ids as $post_id ) { 173 $post_del = get_post( $post_id ); 174 175 if ( ! current_user_can( 'delete_post', $post_id ) ) { 176 wp_die( __( 'Sorry, you are not allowed to delete this item.' ) ); 177 } 178 179 if ( 'attachment' === $post_del->post_type ) { 180 if ( ! wp_delete_attachment( $post_id ) ) { 181 wp_die( __( 'Error in deleting the attachment.' ) ); 182 } 183 } else { 184 if ( ! wp_delete_post( $post_id ) ) { 185 wp_die( __( 'Error in deleting the item.' ) ); 186 } 187 } 188 ++$deleted; 189 } 190 $sendback = add_query_arg( 'deleted', $deleted, $sendback ); 191 break; 192 case 'edit': 193 if ( isset( $_REQUEST['bulk_edit'] ) ) { 194 $done = bulk_edit_posts( $_REQUEST ); 195 196 if ( is_array( $done ) ) { 197 $done['updated'] = count( $done['updated'] ); 198 $done['skipped'] = count( $done['skipped'] ); 199 $done['locked'] = count( $done['locked'] ); 200 $sendback = add_query_arg( $done, $sendback ); 201 } 202 } 203 break; 204 default: 205 $screen = get_current_screen()->id; 206 207 /** 208 * Fires when a custom bulk action should be handled. 209 * 210 * The redirect link should be modified with success or failure feedback 211 * from the action to be used to display feedback to the user. 212 * 213 * The dynamic portion of the hook name, `$screen`, refers to the current screen ID. 214 * 215 * @since 4.7.0 216 * 217 * @param string $sendback The redirect URL. 218 * @param string $doaction The action being taken. 219 * @param array $items The items to take the action on. Accepts an array of IDs of posts, 220 * comments, terms, links, plugins, attachments, or users. 221 */ 222 $sendback = apply_filters( "handle_bulk_actions-{$screen}", $sendback, $doaction, $post_ids ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores 223 break; 224 } 225 226 $sendback = remove_query_arg( array( 'action', 'action2', 'tags_input', 'post_author', 'comment_status', 'ping_status', '_status', 'post', 'bulk_edit', 'post_view' ), $sendback ); 227 228 wp_redirect( $sendback ); 229 exit; 230 } elseif ( ! empty( $_REQUEST['_wp_http_referer'] ) ) { 231 wp_redirect( remove_query_arg( array( '_wp_http_referer', '_wpnonce' ), wp_unslash( $_SERVER['REQUEST_URI'] ) ) ); 232 exit; 233 } 234 235 $wp_list_table->prepare_items(); 236 237 wp_enqueue_script( 'inline-edit-post' ); 238 wp_enqueue_script( 'heartbeat' ); 239 240 if ( 'wp_block' === $post_type ) { 241 wp_enqueue_script( 'wp-list-reusable-blocks' ); 242 wp_enqueue_style( 'wp-list-reusable-blocks' ); 243 } 244 245 // Used in the HTML title tag. 246 $title = $post_type_object->labels->name; 247 248 if ( 'post' === $post_type ) { 249 get_current_screen()->add_help_tab( 250 array( 251 'id' => 'overview', 252 'title' => __( 'Overview' ), 253 'content' => 254 '<p>' . __( 'This screen provides access to all of your posts. You can customize the display of this screen to suit your workflow.' ) . '</p>', 255 ) 256 ); 257 get_current_screen()->add_help_tab( 258 array( 259 'id' => 'screen-content', 260 'title' => __( 'Screen Content' ), 261 'content' => 262 '<p>' . __( 'You can customize the display of this screen’s contents in a number of ways:' ) . '</p>' . 263 '<ul>' . 264 '<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>' . 265 '<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>' . 266 '<li>' . __( 'You can view posts in a simple title list or with an excerpt using the Screen Options tab.' ) . '</li>' . 267 '<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>' . 268 '</ul>', 269 ) 270 ); 271 get_current_screen()->add_help_tab( 272 array( 273 'id' => 'action-links', 274 'title' => __( 'Available Actions' ), 275 'content' => 276 '<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>' . 277 '<ul>' . 278 '<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>' . 279 '<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>' . 280 '<li>' . __( '<strong>Trash</strong> removes your post from this list and places it in the Trash, from which you can permanently delete it.' ) . '</li>' . 281 '<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’s status.' ) . '</li>' . 282 '</ul>', 283 ) 284 ); 285 get_current_screen()->add_help_tab( 286 array( 287 'id' => 'bulk-actions', 288 'title' => __( 'Bulk actions' ), 289 'content' => 290 '<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>' . 291 '<p>' . sprintf( 292 /* translators: %s: The dismiss dashicon used for buttons that dismiss or remove. */ 293 __( '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 %s<span class="screen-reader-text">remove</span> button next to its name in the Bulk Edit area that appears.' ), 294 '<span class="dashicons dashicons-dismiss" aria-hidden="true" style="font-size: 16px; width: 16px; vertical-align: middle;"></span>' 295 ) . '</p>', 296 ) 297 ); 298 299 get_current_screen()->set_help_sidebar( 300 '<p><strong>' . __( 'For more information:' ) . '</strong></p>' . 301 '<p>' . __( '<a href="https://wordpress.org/documentation/article/posts-screen/">Documentation on Managing Posts</a>' ) . '</p>' . 302 '<p>' . __( '<a href="https://wordpress.org/support/forums/">Support forums</a>' ) . '</p>' 303 ); 304 305 } elseif ( 'page' === $post_type ) { 306 get_current_screen()->add_help_tab( 307 array( 308 'id' => 'overview', 309 'title' => __( 'Overview' ), 310 'content' => 311 '<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 “Parent” of the other, creating a group of pages.' ) . '</p>', 312 ) 313 ); 314 get_current_screen()->add_help_tab( 315 array( 316 'id' => 'managing-pages', 317 'title' => __( 'Managing Pages' ), 318 'content' => 319 '<p>' . __( 'Managing pages is very similar to managing posts, and the screens can be customized in the same way.' ) . '</p>' . 320 '<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>', 321 ) 322 ); 323 324 get_current_screen()->set_help_sidebar( 325 '<p><strong>' . __( 'For more information:' ) . '</strong></p>' . 326 '<p>' . __( '<a href="https://wordpress.org/documentation/article/pages-screen/">Documentation on Managing Pages</a>' ) . '</p>' . 327 '<p>' . __( '<a href="https://wordpress.org/support/forums/">Support forums</a>' ) . '</p>' 328 ); 329 330 } 331 332 get_current_screen()->set_screen_reader_content( 333 array( 334 'heading_views' => $post_type_object->labels->filter_items_list, 335 'heading_pagination' => $post_type_object->labels->items_list_navigation, 336 'heading_list' => $post_type_object->labels->items_list, 337 ) 338 ); 339 340 add_screen_option( 341 'per_page', 342 array( 343 'default' => 20, 344 'option' => 'edit_' . $post_type . '_per_page', 345 ) 346 ); 347 348 $bulk_counts = array( 349 'updated' => isset( $_REQUEST['updated'] ) ? absint( $_REQUEST['updated'] ) : 0, 350 'locked' => isset( $_REQUEST['locked'] ) ? absint( $_REQUEST['locked'] ) : 0, 351 'deleted' => isset( $_REQUEST['deleted'] ) ? absint( $_REQUEST['deleted'] ) : 0, 352 'trashed' => isset( $_REQUEST['trashed'] ) ? absint( $_REQUEST['trashed'] ) : 0, 353 'untrashed' => isset( $_REQUEST['untrashed'] ) ? absint( $_REQUEST['untrashed'] ) : 0, 354 ); 355 356 $bulk_messages = array(); 357 $bulk_messages['post'] = array( 358 /* translators: %s: Number of posts. */ 359 'updated' => _n( '%s post updated.', '%s posts updated.', $bulk_counts['updated'] ), 360 'locked' => ( 1 === $bulk_counts['locked'] ) ? __( '1 post not updated, somebody is editing it.' ) : 361 /* translators: %s: Number of posts. */ 362 _n( '%s post not updated, somebody is editing it.', '%s posts not updated, somebody is editing them.', $bulk_counts['locked'] ), 363 /* translators: %s: Number of posts. */ 364 'deleted' => _n( '%s post permanently deleted.', '%s posts permanently deleted.', $bulk_counts['deleted'] ), 365 /* translators: %s: Number of posts. */ 366 'trashed' => _n( '%s post moved to the Trash.', '%s posts moved to the Trash.', $bulk_counts['trashed'] ), 367 /* translators: %s: Number of posts. */ 368 'untrashed' => _n( '%s post restored from the Trash.', '%s posts restored from the Trash.', $bulk_counts['untrashed'] ), 369 ); 370 $bulk_messages['page'] = array( 371 /* translators: %s: Number of pages. */ 372 'updated' => _n( '%s page updated.', '%s pages updated.', $bulk_counts['updated'] ), 373 'locked' => ( 1 === $bulk_counts['locked'] ) ? __( '1 page not updated, somebody is editing it.' ) : 374 /* translators: %s: Number of pages. */ 375 _n( '%s page not updated, somebody is editing it.', '%s pages not updated, somebody is editing them.', $bulk_counts['locked'] ), 376 /* translators: %s: Number of pages. */ 377 'deleted' => _n( '%s page permanently deleted.', '%s pages permanently deleted.', $bulk_counts['deleted'] ), 378 /* translators: %s: Number of pages. */ 379 'trashed' => _n( '%s page moved to the Trash.', '%s pages moved to the Trash.', $bulk_counts['trashed'] ), 380 /* translators: %s: Number of pages. */ 381 'untrashed' => _n( '%s page restored from the Trash.', '%s pages restored from the Trash.', $bulk_counts['untrashed'] ), 382 ); 383 $bulk_messages['wp_block'] = array( 384 /* translators: %s: Number of patterns. */ 385 'updated' => _n( '%s pattern updated.', '%s patterns updated.', $bulk_counts['updated'] ), 386 'locked' => ( 1 === $bulk_counts['locked'] ) ? __( '1 pattern not updated, somebody is editing it.' ) : 387 /* translators: %s: Number of patterns. */ 388 _n( '%s pattern not updated, somebody is editing it.', '%s patterns not updated, somebody is editing them.', $bulk_counts['locked'] ), 389 /* translators: %s: Number of patterns. */ 390 'deleted' => _n( '%s pattern permanently deleted.', '%s patterns permanently deleted.', $bulk_counts['deleted'] ), 391 /* translators: %s: Number of patterns. */ 392 'trashed' => _n( '%s pattern moved to the Trash.', '%s patterns moved to the Trash.', $bulk_counts['trashed'] ), 393 /* translators: %s: Number of patterns. */ 394 'untrashed' => _n( '%s pattern restored from the Trash.', '%s patterns restored from the Trash.', $bulk_counts['untrashed'] ), 395 ); 396 397 /** 398 * Filters the bulk action updated messages. 399 * 400 * By default, custom post types use the messages for the 'post' post type. 401 * 402 * @since 3.7.0 403 * 404 * @param array[] $bulk_messages Arrays of messages, each keyed by the corresponding post type. Messages are 405 * keyed with 'updated', 'locked', 'deleted', 'trashed', and 'untrashed'. 406 * @param int[] $bulk_counts Array of item counts for each message, used to build internationalized strings. 407 */ 408 $bulk_messages = apply_filters( 'bulk_post_updated_messages', $bulk_messages, $bulk_counts ); 409 $bulk_counts = array_filter( $bulk_counts ); 410 411 require_once ABSPATH . 'wp-admin/admin-header.php'; 412 ?> 413 <div class="wrap"> 414 <h1 class="wp-heading-inline"> 415 <?php 416 echo esc_html( $post_type_object->labels->name ); 417 ?> 418 </h1> 419 420 <?php 421 if ( current_user_can( $post_type_object->cap->create_posts ) ) { 422 echo ' <a href="' . esc_url( admin_url( $post_new_file ) ) . '" class="page-title-action">' . esc_html( $post_type_object->labels->add_new_item ) . '</a>'; 423 } 424 425 if ( isset( $_REQUEST['s'] ) && strlen( $_REQUEST['s'] ) ) { 426 echo '<span class="subtitle">'; 427 printf( 428 /* translators: %s: Search query. */ 429 __( 'Search results for: %s' ), 430 '<strong>' . get_search_query() . '</strong>' 431 ); 432 echo '</span>'; 433 } 434 ?> 435 436 <hr class="wp-header-end"> 437 438 <?php 439 // If we have a bulk message to issue: 440 $messages = array(); 441 foreach ( $bulk_counts as $message => $count ) { 442 if ( isset( $bulk_messages[ $post_type ][ $message ] ) ) { 443 $messages[] = sprintf( $bulk_messages[ $post_type ][ $message ], number_format_i18n( $count ) ); 444 } elseif ( isset( $bulk_messages['post'][ $message ] ) ) { 445 $messages[] = sprintf( $bulk_messages['post'][ $message ], number_format_i18n( $count ) ); 446 } 447 448 if ( 'trashed' === $message && isset( $_REQUEST['ids'] ) ) { 449 $ids = preg_replace( '/[^0-9,]/', '', $_REQUEST['ids'] ); 450 451 $messages[] = sprintf( 452 '<a href="%1$s">%2$s</a>', 453 esc_url( wp_nonce_url( "edit.php?post_type=$post_type&doaction=undo&action=untrash&ids=$ids", 'bulk-posts' ) ), 454 __( 'Undo' ) 455 ); 456 } 457 458 if ( 'untrashed' === $message && isset( $_REQUEST['ids'] ) ) { 459 $ids = explode( ',', $_REQUEST['ids'] ); 460 461 if ( 1 === count( $ids ) && current_user_can( 'edit_post', $ids[0] ) ) { 462 $messages[] = sprintf( 463 '<a href="%1$s">%2$s</a>', 464 esc_url( get_edit_post_link( $ids[0] ) ), 465 esc_html( get_post_type_object( get_post_type( $ids[0] ) )->labels->edit_item ) 466 ); 467 } 468 } 469 } 470 471 if ( $messages ) { 472 wp_admin_notice( 473 implode( ' ', $messages ), 474 array( 475 'id' => 'message', 476 'additional_classes' => array( 'updated' ), 477 'dismissible' => true, 478 ) 479 ); 480 } 481 unset( $messages ); 482 483 $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'locked', 'skipped', 'updated', 'deleted', 'trashed', 'untrashed' ), $_SERVER['REQUEST_URI'] ); 484 ?> 485 486 <?php $wp_list_table->views(); ?> 487 488 <form id="posts-filter" method="get"> 489 490 <?php $wp_list_table->search_box( $post_type_object->labels->search_items, 'post' ); ?> 491 492 <input type="hidden" name="post_status" class="post_status_page" value="<?php echo ! empty( $_REQUEST['post_status'] ) ? esc_attr( $_REQUEST['post_status'] ) : 'all'; ?>" /> 493 <input type="hidden" name="post_type" class="post_type_page" value="<?php echo esc_attr( $post_type ); ?>" /> 494 495 <?php if ( ! empty( $_REQUEST['author'] ) ) { ?> 496 <input type="hidden" name="author" value="<?php echo esc_attr( $_REQUEST['author'] ); ?>" /> 497 <?php } ?> 498 499 <?php if ( ! empty( $_REQUEST['show_sticky'] ) ) { ?> 500 <input type="hidden" name="show_sticky" value="1" /> 501 <?php } ?> 502 503 <?php $wp_list_table->display(); ?> 504 505 </form> 506 507 <?php 508 if ( $wp_list_table->has_items() ) { 509 $wp_list_table->inline_edit(); 510 } 511 ?> 512 513 <div id="ajax-response"></div> 514 <div class="clear"></div> 515 </div> 516 517 <?php 518 require_once ABSPATH . 'wp-admin/admin-footer.php';
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated : Sat Dec 21 08:20:01 2024 | Cross-referenced by PHPXref |