wp/wp-admin/edit.php
changeset 7 cf61fcea0001
parent 5 5e2f62d02dcd
child 9 177826044cd9
equal deleted inserted replaced
6:490d5cc509ed 7:cf61fcea0001
     8 
     8 
     9 /** WordPress Administration Bootstrap */
     9 /** WordPress Administration Bootstrap */
    10 require_once( dirname( __FILE__ ) . '/admin.php' );
    10 require_once( dirname( __FILE__ ) . '/admin.php' );
    11 
    11 
    12 if ( ! $typenow )
    12 if ( ! $typenow )
    13 	wp_die( __( 'Invalid post type' ) );
    13 	wp_die( __( 'Invalid post type.' ) );
       
    14 
       
    15 if ( ! in_array( $typenow, get_post_types( array( 'show_ui' => true ) ) ) ) {
       
    16 	wp_die( __( 'Sorry, you are not allowed to edit posts in this post type.' ) );
       
    17 }
    14 
    18 
    15 if ( 'attachment' === $typenow ) {
    19 if ( 'attachment' === $typenow ) {
    16 	if ( wp_redirect( admin_url( 'upload.php' ) ) ) {
    20 	if ( wp_redirect( admin_url( 'upload.php' ) ) ) {
    17 		exit;
    21 		exit;
    18 	}
    22 	}
    19 }
    23 }
    20 
    24 
       
    25 /**
       
    26  * @global string       $post_type
       
    27  * @global WP_Post_Type $post_type_object
       
    28  */
    21 global $post_type, $post_type_object;
    29 global $post_type, $post_type_object;
    22 
    30 
    23 $post_type = $typenow;
    31 $post_type = $typenow;
    24 $post_type_object = get_post_type_object( $post_type );
    32 $post_type_object = get_post_type_object( $post_type );
    25 
    33 
    26 if ( ! $post_type_object )
    34 if ( ! $post_type_object )
    27 	wp_die( __( 'Invalid post type' ) );
    35 	wp_die( __( 'Invalid post type.' ) );
    28 
    36 
    29 if ( ! current_user_can( $post_type_object->cap->edit_posts ) )
    37 if ( ! current_user_can( $post_type_object->cap->edit_posts ) ) {
    30 	wp_die( __( 'Cheatin’ uh?' ), 403 );
    38 	wp_die(
       
    39 		'<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' .
       
    40 		'<p>' . __( 'Sorry, you are not allowed to edit posts in this post type.' ) . '</p>',
       
    41 		403
       
    42 	);
       
    43 }
    31 
    44 
    32 $wp_list_table = _get_list_table('WP_Posts_List_Table');
    45 $wp_list_table = _get_list_table('WP_Posts_List_Table');
    33 $pagenum = $wp_list_table->get_pagenum();
    46 $pagenum = $wp_list_table->get_pagenum();
    34 
    47 
    35 // Back-compat for viewing comments of an entry
    48 // Back-compat for viewing comments of an entry
    86 
    99 
    87 	switch ( $doaction ) {
   100 	switch ( $doaction ) {
    88 		case 'trash':
   101 		case 'trash':
    89 			$trashed = $locked = 0;
   102 			$trashed = $locked = 0;
    90 
   103 
    91 			foreach( (array) $post_ids as $post_id ) {
   104 			foreach ( (array) $post_ids as $post_id ) {
    92 				if ( !current_user_can( 'delete_post', $post_id) )
   105 				if ( !current_user_can( 'delete_post', $post_id) )
    93 					wp_die( __('You are not allowed to move this item to the Trash.') );
   106 					wp_die( __('Sorry, you are not allowed to move this item to the Trash.') );
    94 
   107 
    95 				if ( wp_check_post_lock( $post_id ) ) {
   108 				if ( wp_check_post_lock( $post_id ) ) {
    96 					$locked++;
   109 					$locked++;
    97 					continue;
   110 					continue;
    98 				}
   111 				}
   105 
   118 
   106 			$sendback = add_query_arg( array('trashed' => $trashed, 'ids' => join(',', $post_ids), 'locked' => $locked ), $sendback );
   119 			$sendback = add_query_arg( array('trashed' => $trashed, 'ids' => join(',', $post_ids), 'locked' => $locked ), $sendback );
   107 			break;
   120 			break;
   108 		case 'untrash':
   121 		case 'untrash':
   109 			$untrashed = 0;
   122 			$untrashed = 0;
   110 			foreach( (array) $post_ids as $post_id ) {
   123 			foreach ( (array) $post_ids as $post_id ) {
   111 				if ( !current_user_can( 'delete_post', $post_id) )
   124 				if ( !current_user_can( 'delete_post', $post_id) )
   112 					wp_die( __('You are not allowed to restore this item from the Trash.') );
   125 					wp_die( __('Sorry, you are not allowed to restore this item from the Trash.') );
   113 
   126 
   114 				if ( !wp_untrash_post($post_id) )
   127 				if ( !wp_untrash_post($post_id) )
   115 					wp_die( __('Error in restoring from Trash.') );
   128 					wp_die( __('Error in restoring from Trash.') );
   116 
   129 
   117 				$untrashed++;
   130 				$untrashed++;
   118 			}
   131 			}
   119 			$sendback = add_query_arg('untrashed', $untrashed, $sendback);
   132 			$sendback = add_query_arg('untrashed', $untrashed, $sendback);
   120 			break;
   133 			break;
   121 		case 'delete':
   134 		case 'delete':
   122 			$deleted = 0;
   135 			$deleted = 0;
   123 			foreach( (array) $post_ids as $post_id ) {
   136 			foreach ( (array) $post_ids as $post_id ) {
   124 				$post_del = get_post($post_id);
   137 				$post_del = get_post($post_id);
   125 
   138 
   126 				if ( !current_user_can( 'delete_post', $post_id ) )
   139 				if ( !current_user_can( 'delete_post', $post_id ) )
   127 					wp_die( __('You are not allowed to delete this item.') );
   140 					wp_die( __('Sorry, you are not allowed to delete this item.') );
   128 
   141 
   129 				if ( $post_del->post_type == 'attachment' ) {
   142 				if ( $post_del->post_type == 'attachment' ) {
   130 					if ( ! wp_delete_attachment($post_id) )
   143 					if ( ! wp_delete_attachment($post_id) )
   131 						wp_die( __('Error in deleting.') );
   144 						wp_die( __('Error in deleting.') );
   132 				} else {
   145 				} else {
   147 					$done['locked'] = count( $done['locked'] );
   160 					$done['locked'] = count( $done['locked'] );
   148 					$sendback = add_query_arg( $done, $sendback );
   161 					$sendback = add_query_arg( $done, $sendback );
   149 				}
   162 				}
   150 			}
   163 			}
   151 			break;
   164 			break;
       
   165 		default:
       
   166 			/** This action is documented in wp-admin/edit-comments.php */
       
   167 			$sendback = apply_filters( 'handle_bulk_actions-' . get_current_screen()->id, $sendback, $doaction, $post_ids );
       
   168 			break;
   152 	}
   169 	}
   153 
   170 
   154 	$sendback = remove_query_arg( array('action', 'action2', 'tags_input', 'post_author', 'comment_status', 'ping_status', '_status', 'post', 'bulk_edit', 'post_view'), $sendback );
   171 	$sendback = remove_query_arg( array('action', 'action2', 'tags_input', 'post_author', 'comment_status', 'ping_status', '_status', 'post', 'bulk_edit', 'post_view'), $sendback );
   155 
   172 
   156 	wp_redirect($sendback);
   173 	wp_redirect($sendback);
   179 	'title'		=> __('Screen Content'),
   196 	'title'		=> __('Screen Content'),
   180 	'content'	=>
   197 	'content'	=>
   181 		'<p>' . __('You can customize the display of this screen&#8217;s contents in a number of ways:') . '</p>' .
   198 		'<p>' . __('You can customize the display of this screen&#8217;s contents in a number of ways:') . '</p>' .
   182 		'<ul>' .
   199 		'<ul>' .
   183 			'<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>' .
   200 			'<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>' .
   184 			'<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>' .
   201 			'<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>' .
   185 			'<li>' . __('You can view posts in a simple title list or with an excerpt. Choose the view you prefer by clicking on the icons at the top of the list on the right.') . '</li>' .
   202 			'<li>' . __('You can view posts in a simple title list or with an excerpt using the Screen Options tab.') . '</li>' .
   186 			'<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>' .
   203 			'<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>' .
   187 		'</ul>'
   204 		'</ul>'
   188 	) );
   205 	) );
   189 	get_current_screen()->add_help_tab( array(
   206 	get_current_screen()->add_help_tab( array(
   190 	'id'		=> 'action-links',
   207 	'id'		=> 'action-links',
   206 				'<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>'
   223 				'<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>'
   207 	) );
   224 	) );
   208 
   225 
   209 	get_current_screen()->set_help_sidebar(
   226 	get_current_screen()->set_help_sidebar(
   210 	'<p><strong>' . __('For more information:') . '</strong></p>' .
   227 	'<p><strong>' . __('For more information:') . '</strong></p>' .
   211 	'<p>' . __('<a href="https://codex.wordpress.org/Posts_Screen" target="_blank">Documentation on Managing Posts</a>') . '</p>' .
   228 	'<p>' . __('<a href="https://codex.wordpress.org/Posts_Screen">Documentation on Managing Posts</a>') . '</p>' .
   212 	'<p>' . __('<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
   229 	'<p>' . __('<a href="https://wordpress.org/support/">Support Forums</a>') . '</p>'
   213 	);
   230 	);
   214 
   231 
   215 } elseif ( 'page' == $post_type ) {
   232 } elseif ( 'page' == $post_type ) {
   216 	get_current_screen()->add_help_tab( array(
   233 	get_current_screen()->add_help_tab( array(
   217 	'id'		=> 'overview',
   234 	'id'		=> 'overview',
   227 		'<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>'
   244 		'<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>'
   228 	) );
   245 	) );
   229 
   246 
   230 	get_current_screen()->set_help_sidebar(
   247 	get_current_screen()->set_help_sidebar(
   231 	'<p><strong>' . __('For more information:') . '</strong></p>' .
   248 	'<p><strong>' . __('For more information:') . '</strong></p>' .
   232 	'<p>' . __('<a href="https://codex.wordpress.org/Pages_Screen" target="_blank">Documentation on Managing Pages</a>') . '</p>' .
   249 	'<p>' . __('<a href="https://codex.wordpress.org/Pages_Screen">Documentation on Managing Pages</a>') . '</p>' .
   233 	'<p>' . __('<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
   250 	'<p>' . __('<a href="https://wordpress.org/support/">Support Forums</a>') . '</p>'
   234 	);
   251 	);
   235 }
   252 
       
   253 }
       
   254 
       
   255 get_current_screen()->set_screen_reader_content( array(
       
   256 	'heading_views'      => $post_type_object->labels->filter_items_list,
       
   257 	'heading_pagination' => $post_type_object->labels->items_list_navigation,
       
   258 	'heading_list'       => $post_type_object->labels->items_list,
       
   259 ) );
   236 
   260 
   237 add_screen_option( 'per_page', array( 'default' => 20, 'option' => 'edit_' . $post_type . '_per_page' ) );
   261 add_screen_option( 'per_page', array( 'default' => 20, 'option' => 'edit_' . $post_type . '_per_page' ) );
   238 
   262 
   239 $bulk_counts = array(
   263 $bulk_counts = array(
   240 	'updated'   => isset( $_REQUEST['updated'] )   ? absint( $_REQUEST['updated'] )   : 0,
   264 	'updated'   => isset( $_REQUEST['updated'] )   ? absint( $_REQUEST['updated'] )   : 0,
   261 	'trashed'   => _n( '%s page moved to the Trash.', '%s pages moved to the Trash.', $bulk_counts['trashed'] ),
   285 	'trashed'   => _n( '%s page moved to the Trash.', '%s pages moved to the Trash.', $bulk_counts['trashed'] ),
   262 	'untrashed' => _n( '%s page restored from the Trash.', '%s pages restored from the Trash.', $bulk_counts['untrashed'] ),
   286 	'untrashed' => _n( '%s page restored from the Trash.', '%s pages restored from the Trash.', $bulk_counts['untrashed'] ),
   263 );
   287 );
   264 
   288 
   265 /**
   289 /**
   266  * Filter the bulk action updated messages.
   290  * Filters the bulk action updated messages.
   267  *
   291  *
   268  * By default, custom post types use the messages for the 'post' post type.
   292  * By default, custom post types use the messages for the 'post' post type.
   269  *
   293  *
   270  * @since 3.7.0
   294  * @since 3.7.0
   271  *
   295  *
   277 $bulk_counts = array_filter( $bulk_counts );
   301 $bulk_counts = array_filter( $bulk_counts );
   278 
   302 
   279 require_once( ABSPATH . 'wp-admin/admin-header.php' );
   303 require_once( ABSPATH . 'wp-admin/admin-header.php' );
   280 ?>
   304 ?>
   281 <div class="wrap">
   305 <div class="wrap">
   282 <h2><?php
   306 <h1 class="wp-heading-inline"><?php
   283 echo esc_html( $post_type_object->labels->name );
   307 echo esc_html( $post_type_object->labels->name );
   284 if ( current_user_can( $post_type_object->cap->create_posts ) )
   308 ?></h1>
   285 	echo ' <a href="' . esc_url( admin_url( $post_new_file ) ) . '" class="add-new-h2">' . esc_html( $post_type_object->labels->add_new ) . '</a>';
   309 
   286 if ( ! empty( $_REQUEST['s'] ) )
   310 <?php
   287 	printf( ' <span class="subtitle">' . __('Search results for &#8220;%s&#8221;') . '</span>', get_search_query() );
   311 if ( current_user_can( $post_type_object->cap->create_posts ) ) {
   288 ?></h2>
   312 	echo ' <a href="' . esc_url( admin_url( $post_new_file ) ) . '" class="page-title-action">' . esc_html( $post_type_object->labels->add_new ) . '</a>';
       
   313 }
       
   314 
       
   315 if ( isset( $_REQUEST['s'] ) && strlen( $_REQUEST['s'] ) ) {
       
   316 	/* translators: %s: search keywords */
       
   317 	printf( ' <span class="subtitle">' . __( 'Search results for &#8220;%s&#8221;' ) . '</span>', get_search_query() );
       
   318 }
       
   319 ?>
       
   320 
       
   321 <hr class="wp-header-end">
   289 
   322 
   290 <?php
   323 <?php
   291 // If we have a bulk message to issue:
   324 // If we have a bulk message to issue:
   292 $messages = array();
   325 $messages = array();
   293 foreach ( $bulk_counts as $message => $count ) {
   326 foreach ( $bulk_counts as $message => $count ) {
   315 
   348 
   316 <?php $wp_list_table->search_box( $post_type_object->labels->search_items, 'post' ); ?>
   349 <?php $wp_list_table->search_box( $post_type_object->labels->search_items, 'post' ); ?>
   317 
   350 
   318 <input type="hidden" name="post_status" class="post_status_page" value="<?php echo !empty($_REQUEST['post_status']) ? esc_attr($_REQUEST['post_status']) : 'all'; ?>" />
   351 <input type="hidden" name="post_status" class="post_status_page" value="<?php echo !empty($_REQUEST['post_status']) ? esc_attr($_REQUEST['post_status']) : 'all'; ?>" />
   319 <input type="hidden" name="post_type" class="post_type_page" value="<?php echo $post_type; ?>" />
   352 <input type="hidden" name="post_type" class="post_type_page" value="<?php echo $post_type; ?>" />
       
   353 
       
   354 <?php if ( ! empty( $_REQUEST['author'] ) ) { ?>
       
   355 <input type="hidden" name="author" value="<?php echo esc_attr( $_REQUEST['author'] ); ?>" />
       
   356 <?php } ?>
       
   357 
   320 <?php if ( ! empty( $_REQUEST['show_sticky'] ) ) { ?>
   358 <?php if ( ! empty( $_REQUEST['show_sticky'] ) ) { ?>
   321 <input type="hidden" name="show_sticky" value="1" />
   359 <input type="hidden" name="show_sticky" value="1" />
   322 <?php } ?>
   360 <?php } ?>
   323 
   361 
   324 <?php $wp_list_table->display(); ?>
   362 <?php $wp_list_table->display(); ?>