wp/wp-admin/edit.php
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
child 22 8c2e4d02f4ef
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
     7  */
     7  */
     8 
     8 
     9 /** WordPress Administration Bootstrap */
     9 /** WordPress Administration Bootstrap */
    10 require_once __DIR__ . '/admin.php';
    10 require_once __DIR__ . '/admin.php';
    11 
    11 
       
    12 /**
       
    13  * @global string $typenow The post type of the current screen.
       
    14  */
       
    15 global $typenow;
       
    16 
    12 if ( ! $typenow ) {
    17 if ( ! $typenow ) {
    13 	wp_die( __( 'Invalid post type.' ) );
    18 	wp_die( __( 'Invalid post type.' ) );
    14 }
    19 }
    15 
    20 
    16 if ( ! in_array( $typenow, get_post_types( array( 'show_ui' => true ) ), true ) ) {
    21 if ( ! in_array( $typenow, get_post_types( array( 'show_ui' => true ) ), true ) ) {
    22 		exit;
    27 		exit;
    23 	}
    28 	}
    24 }
    29 }
    25 
    30 
    26 /**
    31 /**
    27  * @global string       $post_type
    32  * @global string       $post_type        Global post type.
    28  * @global WP_Post_Type $post_type_object
    33  * @global WP_Post_Type $post_type_object Global post type object.
    29  */
    34  */
    30 global $post_type, $post_type_object;
    35 global $post_type, $post_type_object;
    31 
    36 
    32 $post_type        = $typenow;
    37 $post_type        = $typenow;
    33 $post_type_object = get_post_type_object( $post_type );
    38 $post_type_object = get_post_type_object( $post_type );
    74 	$sendback = remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'locked', 'ids' ), wp_get_referer() );
    79 	$sendback = remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'locked', 'ids' ), wp_get_referer() );
    75 	if ( ! $sendback ) {
    80 	if ( ! $sendback ) {
    76 		$sendback = admin_url( $parent_file );
    81 		$sendback = admin_url( $parent_file );
    77 	}
    82 	}
    78 	$sendback = add_query_arg( 'paged', $pagenum, $sendback );
    83 	$sendback = add_query_arg( 'paged', $pagenum, $sendback );
    79 	if ( strpos( $sendback, 'post.php' ) !== false ) {
    84 	if ( str_contains( $sendback, 'post.php' ) ) {
    80 		$sendback = admin_url( $post_new_file );
    85 		$sendback = admin_url( $post_new_file );
    81 	}
    86 	}
    82 
    87 
    83 	$post_ids = array();
    88 	$post_ids = array();
    84 
    89 
    85 	if ( 'delete_all' === $doaction ) {
    90 	if ( 'delete_all' === $doaction ) {
    86 		// Prepare for deletion of all posts with a specified post status (i.e. Empty Trash).
    91 		// Prepare for deletion of all posts with a specified post status (i.e. Empty Trash).
    87 		$post_status = preg_replace( '/[^a-z0-9_-]+/i', '', $_REQUEST['post_status'] );
    92 		$post_status = preg_replace( '/[^a-z0-9_-]+/i', '', $_REQUEST['post_status'] );
    88 		// Validate the post status exists.
    93 		// Validate the post status exists.
    89 		if ( get_post_status_object( $post_status ) ) {
    94 		if ( get_post_status_object( $post_status ) ) {
       
    95 			/**
       
    96 			 * @global wpdb $wpdb WordPress database abstraction object.
       
    97 			 */
       
    98 			global $wpdb;
       
    99 
    90 			$post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type=%s AND post_status = %s", $post_type, $post_status ) );
   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 ) );
    91 		}
   101 		}
    92 		$doaction = 'delete';
   102 		$doaction = 'delete';
    93 	} elseif ( isset( $_REQUEST['media'] ) ) {
   103 	} elseif ( isset( $_REQUEST['media'] ) ) {
    94 		$post_ids = $_REQUEST['media'];
   104 		$post_ids = $_REQUEST['media'];
   112 				if ( ! current_user_can( 'delete_post', $post_id ) ) {
   122 				if ( ! current_user_can( 'delete_post', $post_id ) ) {
   113 					wp_die( __( 'Sorry, you are not allowed to move this item to the Trash.' ) );
   123 					wp_die( __( 'Sorry, you are not allowed to move this item to the Trash.' ) );
   114 				}
   124 				}
   115 
   125 
   116 				if ( wp_check_post_lock( $post_id ) ) {
   126 				if ( wp_check_post_lock( $post_id ) ) {
   117 					$locked++;
   127 					++$locked;
   118 					continue;
   128 					continue;
   119 				}
   129 				}
   120 
   130 
   121 				if ( ! wp_trash_post( $post_id ) ) {
   131 				if ( ! wp_trash_post( $post_id ) ) {
   122 					wp_die( __( 'Error in moving the item to Trash.' ) );
   132 					wp_die( __( 'Error in moving the item to Trash.' ) );
   123 				}
   133 				}
   124 
   134 
   125 				$trashed++;
   135 				++$trashed;
   126 			}
   136 			}
   127 
   137 
   128 			$sendback = add_query_arg(
   138 			$sendback = add_query_arg(
   129 				array(
   139 				array(
   130 					'trashed' => $trashed,
   140 					'trashed' => $trashed,
   148 
   158 
   149 				if ( ! wp_untrash_post( $post_id ) ) {
   159 				if ( ! wp_untrash_post( $post_id ) ) {
   150 					wp_die( __( 'Error in restoring the item from Trash.' ) );
   160 					wp_die( __( 'Error in restoring the item from Trash.' ) );
   151 				}
   161 				}
   152 
   162 
   153 				$untrashed++;
   163 				++$untrashed;
   154 			}
   164 			}
   155 			$sendback = add_query_arg( 'untrashed', $untrashed, $sendback );
   165 			$sendback = add_query_arg( 'untrashed', $untrashed, $sendback );
   156 
   166 
   157 			remove_filter( 'wp_untrash_post_status', 'wp_untrash_post_set_previous_status', 10 );
   167 			remove_filter( 'wp_untrash_post_status', 'wp_untrash_post_set_previous_status', 10 );
   158 
   168 
   173 				} else {
   183 				} else {
   174 					if ( ! wp_delete_post( $post_id ) ) {
   184 					if ( ! wp_delete_post( $post_id ) ) {
   175 						wp_die( __( 'Error in deleting the item.' ) );
   185 						wp_die( __( 'Error in deleting the item.' ) );
   176 					}
   186 					}
   177 				}
   187 				}
   178 				$deleted++;
   188 				++$deleted;
   179 			}
   189 			}
   180 			$sendback = add_query_arg( 'deleted', $deleted, $sendback );
   190 			$sendback = add_query_arg( 'deleted', $deleted, $sendback );
   181 			break;
   191 			break;
   182 		case 'edit':
   192 		case 'edit':
   183 			if ( isset( $_REQUEST['bulk_edit'] ) ) {
   193 			if ( isset( $_REQUEST['bulk_edit'] ) ) {
   276 		array(
   286 		array(
   277 			'id'      => 'bulk-actions',
   287 			'id'      => 'bulk-actions',
   278 			'title'   => __( 'Bulk actions' ),
   288 			'title'   => __( 'Bulk actions' ),
   279 			'content' =>
   289 			'content' =>
   280 					'<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>' .
   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>' .
   281 							'<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>',
   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>',
   282 		)
   296 		)
   283 	);
   297 	);
   284 
   298 
   285 	get_current_screen()->set_help_sidebar(
   299 	get_current_screen()->set_help_sidebar(
   286 		'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
   300 		'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
   287 		'<p>' . __( '<a href="https://wordpress.org/support/article/posts-screen/">Documentation on Managing Posts</a>' ) . '</p>' .
   301 		'<p>' . __( '<a href="https://wordpress.org/documentation/article/posts-screen/">Documentation on Managing Posts</a>' ) . '</p>' .
   288 		'<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
   302 		'<p>' . __( '<a href="https://wordpress.org/support/forums/">Support forums</a>' ) . '</p>'
   289 	);
   303 	);
   290 
   304 
   291 } elseif ( 'page' === $post_type ) {
   305 } elseif ( 'page' === $post_type ) {
   292 	get_current_screen()->add_help_tab(
   306 	get_current_screen()->add_help_tab(
   293 		array(
   307 		array(
   307 		)
   321 		)
   308 	);
   322 	);
   309 
   323 
   310 	get_current_screen()->set_help_sidebar(
   324 	get_current_screen()->set_help_sidebar(
   311 		'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
   325 		'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
   312 		'<p>' . __( '<a href="https://wordpress.org/support/article/pages-screen/">Documentation on Managing Pages</a>' ) . '</p>' .
   326 		'<p>' . __( '<a href="https://wordpress.org/documentation/article/pages-screen/">Documentation on Managing Pages</a>' ) . '</p>' .
   313 		'<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
   327 		'<p>' . __( '<a href="https://wordpress.org/support/forums/">Support forums</a>' ) . '</p>'
   314 	);
   328 	);
   315 
   329 
   316 }
   330 }
   317 
   331 
   318 get_current_screen()->set_screen_reader_content(
   332 get_current_screen()->set_screen_reader_content(
   365 	'trashed'   => _n( '%s page moved to the Trash.', '%s pages moved to the Trash.', $bulk_counts['trashed'] ),
   379 	'trashed'   => _n( '%s page moved to the Trash.', '%s pages moved to the Trash.', $bulk_counts['trashed'] ),
   366 	/* translators: %s: Number of pages. */
   380 	/* translators: %s: Number of pages. */
   367 	'untrashed' => _n( '%s page restored from the Trash.', '%s pages restored from the Trash.', $bulk_counts['untrashed'] ),
   381 	'untrashed' => _n( '%s page restored from the Trash.', '%s pages restored from the Trash.', $bulk_counts['untrashed'] ),
   368 );
   382 );
   369 $bulk_messages['wp_block'] = array(
   383 $bulk_messages['wp_block'] = array(
   370 	/* translators: %s: Number of blocks. */
   384 	/* translators: %s: Number of patterns. */
   371 	'updated'   => _n( '%s block updated.', '%s blocks updated.', $bulk_counts['updated'] ),
   385 	'updated'   => _n( '%s pattern updated.', '%s patterns updated.', $bulk_counts['updated'] ),
   372 	'locked'    => ( 1 === $bulk_counts['locked'] ) ? __( '1 block not updated, somebody is editing it.' ) :
   386 	'locked'    => ( 1 === $bulk_counts['locked'] ) ? __( '1 pattern not updated, somebody is editing it.' ) :
   373 					/* translators: %s: Number of blocks. */
   387 					/* translators: %s: Number of patterns. */
   374 					_n( '%s block not updated, somebody is editing it.', '%s blocks not updated, somebody is editing them.', $bulk_counts['locked'] ),
   388 					_n( '%s pattern not updated, somebody is editing it.', '%s patterns not updated, somebody is editing them.', $bulk_counts['locked'] ),
   375 	/* translators: %s: Number of blocks. */
   389 	/* translators: %s: Number of patterns. */
   376 	'deleted'   => _n( '%s block permanently deleted.', '%s blocks permanently deleted.', $bulk_counts['deleted'] ),
   390 	'deleted'   => _n( '%s pattern permanently deleted.', '%s patterns permanently deleted.', $bulk_counts['deleted'] ),
   377 	/* translators: %s: Number of blocks. */
   391 	/* translators: %s: Number of patterns. */
   378 	'trashed'   => _n( '%s block moved to the Trash.', '%s blocks moved to the Trash.', $bulk_counts['trashed'] ),
   392 	'trashed'   => _n( '%s pattern moved to the Trash.', '%s patterns moved to the Trash.', $bulk_counts['trashed'] ),
   379 	/* translators: %s: Number of blocks. */
   393 	/* translators: %s: Number of patterns. */
   380 	'untrashed' => _n( '%s block restored from the Trash.', '%s blocks restored from the Trash.', $bulk_counts['untrashed'] ),
   394 	'untrashed' => _n( '%s pattern restored from the Trash.', '%s patterns restored from the Trash.', $bulk_counts['untrashed'] ),
   381 );
   395 );
   382 
   396 
   383 /**
   397 /**
   384  * Filters the bulk action updated messages.
   398  * Filters the bulk action updated messages.
   385  *
   399  *
   430 	} elseif ( isset( $bulk_messages['post'][ $message ] ) ) {
   444 	} elseif ( isset( $bulk_messages['post'][ $message ] ) ) {
   431 		$messages[] = sprintf( $bulk_messages['post'][ $message ], number_format_i18n( $count ) );
   445 		$messages[] = sprintf( $bulk_messages['post'][ $message ], number_format_i18n( $count ) );
   432 	}
   446 	}
   433 
   447 
   434 	if ( 'trashed' === $message && isset( $_REQUEST['ids'] ) ) {
   448 	if ( 'trashed' === $message && isset( $_REQUEST['ids'] ) ) {
   435 		$ids        = preg_replace( '/[^0-9,]/', '', $_REQUEST['ids'] );
   449 		$ids = preg_replace( '/[^0-9,]/', '', $_REQUEST['ids'] );
   436 		$messages[] = '<a href="' . esc_url( wp_nonce_url( "edit.php?post_type=$post_type&doaction=undo&action=untrash&ids=$ids", 'bulk-posts' ) ) . '">' . __( 'Undo' ) . '</a>';
   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 		);
   437 	}
   456 	}
   438 
   457 
   439 	if ( 'untrashed' === $message && isset( $_REQUEST['ids'] ) ) {
   458 	if ( 'untrashed' === $message && isset( $_REQUEST['ids'] ) ) {
   440 		$ids = explode( ',', $_REQUEST['ids'] );
   459 		$ids = explode( ',', $_REQUEST['ids'] );
   441 
   460 
   448 		}
   467 		}
   449 	}
   468 	}
   450 }
   469 }
   451 
   470 
   452 if ( $messages ) {
   471 if ( $messages ) {
   453 	echo '<div id="message" class="updated notice is-dismissible"><p>' . implode( ' ', $messages ) . '</p></div>';
   472 	wp_admin_notice(
       
   473 		implode( ' ', $messages ),
       
   474 		array(
       
   475 			'id'                 => 'message',
       
   476 			'additional_classes' => array( 'updated' ),
       
   477 			'dismissible'        => true,
       
   478 		)
       
   479 	);
   454 }
   480 }
   455 unset( $messages );
   481 unset( $messages );
   456 
   482 
   457 $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'locked', 'skipped', 'updated', 'deleted', 'trashed', 'untrashed' ), $_SERVER['REQUEST_URI'] );
   483 $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'locked', 'skipped', 'updated', 'deleted', 'trashed', 'untrashed' ), $_SERVER['REQUEST_URI'] );
   458 ?>
   484 ?>
   462 <form id="posts-filter" method="get">
   488 <form id="posts-filter" method="get">
   463 
   489 
   464 <?php $wp_list_table->search_box( $post_type_object->labels->search_items, 'post' ); ?>
   490 <?php $wp_list_table->search_box( $post_type_object->labels->search_items, 'post' ); ?>
   465 
   491 
   466 <input type="hidden" name="post_status" class="post_status_page" value="<?php echo ! empty( $_REQUEST['post_status'] ) ? esc_attr( $_REQUEST['post_status'] ) : 'all'; ?>" />
   492 <input type="hidden" name="post_status" class="post_status_page" value="<?php echo ! empty( $_REQUEST['post_status'] ) ? esc_attr( $_REQUEST['post_status'] ) : 'all'; ?>" />
   467 <input type="hidden" name="post_type" class="post_type_page" value="<?php echo $post_type; ?>" />
   493 <input type="hidden" name="post_type" class="post_type_page" value="<?php echo esc_attr( $post_type ); ?>" />
   468 
   494 
   469 <?php if ( ! empty( $_REQUEST['author'] ) ) { ?>
   495 <?php if ( ! empty( $_REQUEST['author'] ) ) { ?>
   470 <input type="hidden" name="author" value="<?php echo esc_attr( $_REQUEST['author'] ); ?>" />
   496 <input type="hidden" name="author" value="<?php echo esc_attr( $_REQUEST['author'] ); ?>" />
   471 <?php } ?>
   497 <?php } ?>
   472 
   498