wp/wp-admin/edit.php
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
equal deleted inserted replaced
4:346c88efed21 5:5e2f62d02dcd
    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 
    14 
       
    15 if ( 'attachment' === $typenow ) {
       
    16 	if ( wp_redirect( admin_url( 'upload.php' ) ) ) {
       
    17 		exit;
       
    18 	}
       
    19 }
       
    20 
       
    21 global $post_type, $post_type_object;
       
    22 
    15 $post_type = $typenow;
    23 $post_type = $typenow;
    16 $post_type_object = get_post_type_object( $post_type );
    24 $post_type_object = get_post_type_object( $post_type );
    17 
    25 
    18 if ( ! $post_type_object )
    26 if ( ! $post_type_object )
    19 	wp_die( __( 'Invalid post type' ) );
    27 	wp_die( __( 'Invalid post type' ) );
    20 
    28 
    21 if ( ! current_user_can( $post_type_object->cap->edit_posts ) )
    29 if ( ! current_user_can( $post_type_object->cap->edit_posts ) )
    22 	wp_die( __( 'Cheatin’ uh?' ) );
    30 	wp_die( __( 'Cheatin’ uh?' ), 403 );
    23 
    31 
    24 $wp_list_table = _get_list_table('WP_Posts_List_Table');
    32 $wp_list_table = _get_list_table('WP_Posts_List_Table');
    25 $pagenum = $wp_list_table->get_pagenum();
    33 $pagenum = $wp_list_table->get_pagenum();
    26 
    34 
    27 // Back-compat for viewing comments of an entry
    35 // Back-compat for viewing comments of an entry
    54 	$sendback = add_query_arg( 'paged', $pagenum, $sendback );
    62 	$sendback = add_query_arg( 'paged', $pagenum, $sendback );
    55 	if ( strpos($sendback, 'post.php') !== false )
    63 	if ( strpos($sendback, 'post.php') !== false )
    56 		$sendback = admin_url($post_new_file);
    64 		$sendback = admin_url($post_new_file);
    57 
    65 
    58 	if ( 'delete_all' == $doaction ) {
    66 	if ( 'delete_all' == $doaction ) {
       
    67 		// Prepare for deletion of all posts with a specified post status (i.e. Empty trash).
    59 		$post_status = preg_replace('/[^a-z0-9_-]+/i', '', $_REQUEST['post_status']);
    68 		$post_status = preg_replace('/[^a-z0-9_-]+/i', '', $_REQUEST['post_status']);
    60 		if ( get_post_status_object($post_status) ) // Check the post status exists first
    69 		// Validate the post status exists.
       
    70 		if ( get_post_status_object( $post_status ) ) {
    61 			$post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type=%s AND post_status = %s", $post_type, $post_status ) );
    71 			$post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type=%s AND post_status = %s", $post_type, $post_status ) );
       
    72 		}
    62 		$doaction = 'delete';
    73 		$doaction = 'delete';
    63 	} elseif ( isset( $_REQUEST['media'] ) ) {
    74 	} elseif ( isset( $_REQUEST['media'] ) ) {
    64 		$post_ids = $_REQUEST['media'];
    75 		$post_ids = $_REQUEST['media'];
    65 	} elseif ( isset( $_REQUEST['ids'] ) ) {
    76 	} elseif ( isset( $_REQUEST['ids'] ) ) {
    66 		$post_ids = explode( ',', $_REQUEST['ids'] );
    77 		$post_ids = explode( ',', $_REQUEST['ids'] );
   150 }
   161 }
   151 
   162 
   152 $wp_list_table->prepare_items();
   163 $wp_list_table->prepare_items();
   153 
   164 
   154 wp_enqueue_script('inline-edit-post');
   165 wp_enqueue_script('inline-edit-post');
       
   166 wp_enqueue_script('heartbeat');
   155 
   167 
   156 $title = $post_type_object->labels->name;
   168 $title = $post_type_object->labels->name;
   157 
   169 
   158 if ( 'post' == $post_type ) {
   170 if ( 'post' == $post_type ) {
   159 	get_current_screen()->add_help_tab( array(
   171 	get_current_screen()->add_help_tab( array(
   194 				'<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>'
   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>'
   195 	) );
   207 	) );
   196 
   208 
   197 	get_current_screen()->set_help_sidebar(
   209 	get_current_screen()->set_help_sidebar(
   198 	'<p><strong>' . __('For more information:') . '</strong></p>' .
   210 	'<p><strong>' . __('For more information:') . '</strong></p>' .
   199 	'<p>' . __('<a href="http://codex.wordpress.org/Posts_Screen" target="_blank">Documentation on Managing Posts</a>') . '</p>' .
   211 	'<p>' . __('<a href="https://codex.wordpress.org/Posts_Screen" target="_blank">Documentation on Managing Posts</a>') . '</p>' .
   200 	'<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
   212 	'<p>' . __('<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
   201 	);
   213 	);
   202 
   214 
   203 } elseif ( 'page' == $post_type ) {
   215 } elseif ( 'page' == $post_type ) {
   204 	get_current_screen()->add_help_tab( array(
   216 	get_current_screen()->add_help_tab( array(
   205 	'id'		=> 'overview',
   217 	'id'		=> 'overview',
   215 		'<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>'
   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>'
   216 	) );
   228 	) );
   217 
   229 
   218 	get_current_screen()->set_help_sidebar(
   230 	get_current_screen()->set_help_sidebar(
   219 	'<p><strong>' . __('For more information:') . '</strong></p>' .
   231 	'<p><strong>' . __('For more information:') . '</strong></p>' .
   220 	'<p>' . __('<a href="http://codex.wordpress.org/Pages_Screen" target="_blank">Documentation on Managing Pages</a>') . '</p>' .
   232 	'<p>' . __('<a href="https://codex.wordpress.org/Pages_Screen" target="_blank">Documentation on Managing Pages</a>') . '</p>' .
   221 	'<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
   233 	'<p>' . __('<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
   222 	);
   234 	);
   223 }
   235 }
   224 
   236 
   225 add_screen_option( 'per_page', array( 'label' => $title, 'default' => 20, 'option' => 'edit_' . $post_type . '_per_page' ) );
   237 add_screen_option( 'per_page', array( 'default' => 20, 'option' => 'edit_' . $post_type . '_per_page' ) );
   226 
   238 
   227 $bulk_counts = array(
   239 $bulk_counts = array(
   228 	'updated'   => isset( $_REQUEST['updated'] )   ? absint( $_REQUEST['updated'] )   : 0,
   240 	'updated'   => isset( $_REQUEST['updated'] )   ? absint( $_REQUEST['updated'] )   : 0,
   229 	'locked'    => isset( $_REQUEST['locked'] )    ? absint( $_REQUEST['locked'] )    : 0,
   241 	'locked'    => isset( $_REQUEST['locked'] )    ? absint( $_REQUEST['locked'] )    : 0,
   230 	'deleted'   => isset( $_REQUEST['deleted'] )   ? absint( $_REQUEST['deleted'] )   : 0,
   242 	'deleted'   => isset( $_REQUEST['deleted'] )   ? absint( $_REQUEST['deleted'] )   : 0,
   233 );
   245 );
   234 
   246 
   235 $bulk_messages = array();
   247 $bulk_messages = array();
   236 $bulk_messages['post'] = array(
   248 $bulk_messages['post'] = array(
   237 	'updated'   => _n( '%s post updated.', '%s posts updated.', $bulk_counts['updated'] ),
   249 	'updated'   => _n( '%s post updated.', '%s posts updated.', $bulk_counts['updated'] ),
   238 	'locked'    => _n( '%s post not updated, somebody is editing it.', '%s posts not updated, somebody is editing them.', $bulk_counts['locked'] ),
   250 	'locked'    => ( 1 == $bulk_counts['locked'] ) ? __( '1 post not updated, somebody is editing it.' ) :
       
   251 	                   _n( '%s post not updated, somebody is editing it.', '%s posts not updated, somebody is editing them.', $bulk_counts['locked'] ),
   239 	'deleted'   => _n( '%s post permanently deleted.', '%s posts permanently deleted.', $bulk_counts['deleted'] ),
   252 	'deleted'   => _n( '%s post permanently deleted.', '%s posts permanently deleted.', $bulk_counts['deleted'] ),
   240 	'trashed'   => _n( '%s post moved to the Trash.', '%s posts moved to the Trash.', $bulk_counts['trashed'] ),
   253 	'trashed'   => _n( '%s post moved to the Trash.', '%s posts moved to the Trash.', $bulk_counts['trashed'] ),
   241 	'untrashed' => _n( '%s post restored from the Trash.', '%s posts restored from the Trash.', $bulk_counts['untrashed'] ),
   254 	'untrashed' => _n( '%s post restored from the Trash.', '%s posts restored from the Trash.', $bulk_counts['untrashed'] ),
   242 );
   255 );
   243 $bulk_messages['page'] = array(
   256 $bulk_messages['page'] = array(
   244 	'updated'   => _n( '%s page updated.', '%s pages updated.', $bulk_counts['updated'] ),
   257 	'updated'   => _n( '%s page updated.', '%s pages updated.', $bulk_counts['updated'] ),
   245 	'locked'    => _n( '%s page not updated, somebody is editing it.', '%s pages not updated, somebody is editing them.', $bulk_counts['locked'] ),
   258 	'locked'    => ( 1 == $bulk_counts['locked'] ) ? __( '1 page not updated, somebody is editing it.' ) :
       
   259 	                   _n( '%s page not updated, somebody is editing it.', '%s pages not updated, somebody is editing them.', $bulk_counts['locked'] ),
   246 	'deleted'   => _n( '%s page permanently deleted.', '%s pages permanently deleted.', $bulk_counts['deleted'] ),
   260 	'deleted'   => _n( '%s page permanently deleted.', '%s pages permanently deleted.', $bulk_counts['deleted'] ),
   247 	'trashed'   => _n( '%s page moved to the Trash.', '%s pages moved to the Trash.', $bulk_counts['trashed'] ),
   261 	'trashed'   => _n( '%s page moved to the Trash.', '%s pages moved to the Trash.', $bulk_counts['trashed'] ),
   248 	'untrashed' => _n( '%s page restored from the Trash.', '%s pages restored from the Trash.', $bulk_counts['untrashed'] ),
   262 	'untrashed' => _n( '%s page restored from the Trash.', '%s pages restored from the Trash.', $bulk_counts['untrashed'] ),
   249 );
   263 );
   250 
   264 
   263 $bulk_counts = array_filter( $bulk_counts );
   277 $bulk_counts = array_filter( $bulk_counts );
   264 
   278 
   265 require_once( ABSPATH . 'wp-admin/admin-header.php' );
   279 require_once( ABSPATH . 'wp-admin/admin-header.php' );
   266 ?>
   280 ?>
   267 <div class="wrap">
   281 <div class="wrap">
   268 <?php screen_icon(); ?>
       
   269 <h2><?php
   282 <h2><?php
   270 echo esc_html( $post_type_object->labels->name );
   283 echo esc_html( $post_type_object->labels->name );
   271 if ( current_user_can( $post_type_object->cap->create_posts ) )
   284 if ( current_user_can( $post_type_object->cap->create_posts ) )
   272 	echo ' <a href="' . esc_url( admin_url( $post_new_file ) ) . '" class="add-new-h2">' . esc_html( $post_type_object->labels->add_new ) . '</a>';
   285 	echo ' <a href="' . esc_url( admin_url( $post_new_file ) ) . '" class="add-new-h2">' . esc_html( $post_type_object->labels->add_new ) . '</a>';
   273 if ( ! empty( $_REQUEST['s'] ) )
   286 if ( ! empty( $_REQUEST['s'] ) )
   288 		$messages[] = '<a href="' . esc_url( wp_nonce_url( "edit.php?post_type=$post_type&doaction=undo&action=untrash&ids=$ids", "bulk-posts" ) ) . '">' . __('Undo') . '</a>';
   301 		$messages[] = '<a href="' . esc_url( wp_nonce_url( "edit.php?post_type=$post_type&doaction=undo&action=untrash&ids=$ids", "bulk-posts" ) ) . '">' . __('Undo') . '</a>';
   289 	}
   302 	}
   290 }
   303 }
   291 
   304 
   292 if ( $messages )
   305 if ( $messages )
   293 	echo '<div id="message" class="updated"><p>' . join( ' ', $messages ) . '</p></div>';
   306 	echo '<div id="message" class="updated notice is-dismissible"><p>' . join( ' ', $messages ) . '</p></div>';
   294 unset( $messages );
   307 unset( $messages );
   295 
   308 
   296 $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'locked', 'skipped', 'updated', 'deleted', 'trashed', 'untrashed' ), $_SERVER['REQUEST_URI'] );
   309 $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'locked', 'skipped', 'updated', 'deleted', 'trashed', 'untrashed' ), $_SERVER['REQUEST_URI'] );
   297 ?>
   310 ?>
   298 
   311 
   299 <?php $wp_list_table->views(); ?>
   312 <?php $wp_list_table->views(); ?>
   300 
   313 
   301 <form id="posts-filter" action="" method="get">
   314 <form id="posts-filter" method="get">
   302 
   315 
   303 <?php $wp_list_table->search_box( $post_type_object->labels->search_items, 'post' ); ?>
   316 <?php $wp_list_table->search_box( $post_type_object->labels->search_items, 'post' ); ?>
   304 
   317 
   305 <input type="hidden" name="post_status" class="post_status_page" value="<?php echo !empty($_REQUEST['post_status']) ? esc_attr($_REQUEST['post_status']) : 'all'; ?>" />
   318 <input type="hidden" name="post_status" class="post_status_page" value="<?php echo !empty($_REQUEST['post_status']) ? esc_attr($_REQUEST['post_status']) : 'all'; ?>" />
   306 <input type="hidden" name="post_type" class="post_type_page" value="<?php echo $post_type; ?>" />
   319 <input type="hidden" name="post_type" class="post_type_page" value="<?php echo $post_type; ?>" />