3 * Edit Posts Administration Panel.
6 * @subpackage Administration
9 /** WordPress Administration Bootstrap */
10 require_once('admin.php');
12 if ( !current_user_can('edit_posts') )
13 wp_die(__('Cheatin’ uh?'));
15 // Back-compat for viewing comments of an entry
16 if ( $_redirect = intval( max( @$_GET['p'], @$_GET['attachment_id'], @$_GET['page_id'] ) ) ) {
17 wp_redirect( admin_url('edit-comments.php?p=' . $_redirect ) );
23 // Handle bulk actions
24 if ( isset($_GET['doaction']) || isset($_GET['doaction2']) || isset($_GET['delete_all']) || isset($_GET['delete_all2']) || isset($_GET['bulk_edit']) ) {
25 check_admin_referer('bulk-posts');
26 $sendback = remove_query_arg( array('trashed', 'untrashed', 'deleted', 'ids'), wp_get_referer() );
28 if ( strpos($sendback, 'post.php') !== false )
29 $sendback = admin_url('post-new.php');
31 if ( isset($_GET['delete_all']) || isset($_GET['delete_all2']) ) {
32 $post_status = preg_replace('/[^a-z0-9_-]+/i', '', $_GET['post_status']);
33 $post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='post' AND post_status = %s", $post_status ) );
35 } elseif ( ( $_GET['action'] != -1 || $_GET['action2'] != -1 ) && ( isset($_GET['post']) || isset($_GET['ids']) ) ) {
36 $post_ids = isset($_GET['post']) ? array_map( 'intval', (array) $_GET['post'] ) : explode(',', $_GET['ids']);
37 $doaction = ($_GET['action'] != -1) ? $_GET['action'] : $_GET['action2'];
39 wp_redirect( admin_url('edit.php') );
42 switch ( $doaction ) {
45 foreach( (array) $post_ids as $post_id ) {
46 if ( !current_user_can('delete_post', $post_id) )
47 wp_die( __('You are not allowed to move this post to the trash.') );
49 if ( !wp_trash_post($post_id) )
50 wp_die( __('Error in moving to trash...') );
54 $sendback = add_query_arg( array('trashed' => $trashed, 'ids' => join(',', $post_ids)), $sendback );
58 foreach( (array) $post_ids as $post_id ) {
59 if ( !current_user_can('delete_post', $post_id) )
60 wp_die( __('You are not allowed to restore this post from the trash.') );
62 if ( !wp_untrash_post($post_id) )
63 wp_die( __('Error in restoring from trash...') );
67 $sendback = add_query_arg('untrashed', $untrashed, $sendback);
71 foreach( (array) $post_ids as $post_id ) {
72 $post_del = & get_post($post_id);
74 if ( !current_user_can('delete_post', $post_id) )
75 wp_die( __('You are not allowed to delete this post.') );
77 if ( $post_del->post_type == 'attachment' ) {
78 if ( ! wp_delete_attachment($post_id) )
79 wp_die( __('Error in deleting...') );
81 if ( !wp_delete_post($post_id) )
82 wp_die( __('Error in deleting...') );
86 $sendback = add_query_arg('deleted', $deleted, $sendback);
89 $done = bulk_edit_posts($_GET);
91 if ( is_array($done) ) {
92 $done['updated'] = count( $done['updated'] );
93 $done['skipped'] = count( $done['skipped'] );
94 $done['locked'] = count( $done['locked'] );
95 $sendback = add_query_arg( $done, $sendback );
100 if ( isset($_GET['action']) )
101 $sendback = remove_query_arg( array('action', 'action2', 'cat', 'tags_input', 'post_author', 'comment_status', 'ping_status', '_status', 'post', 'bulk_edit', 'post_view', 'post_type'), $sendback );
103 wp_redirect($sendback);
105 } elseif ( isset($_GET['_wp_http_referer']) && ! empty($_GET['_wp_http_referer']) ) {
106 wp_redirect( remove_query_arg( array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI']) ) );
111 $title = __('Edit Posts');
112 $parent_file = 'edit.php';
113 wp_enqueue_script('inline-edit-post');
116 if ( !current_user_can('edit_others_posts') ) {
117 $user_posts_count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(1) FROM $wpdb->posts WHERE post_type = 'post' AND post_status != 'trash' AND post_author = %d", $current_user->ID) );
119 if ( $user_posts_count && empty($_GET['post_status']) && empty($_GET['all_posts']) && empty($_GET['author']) )
120 $_GET['author'] = $current_user->ID;
123 list($post_stati, $avail_post_stati) = wp_edit_posts_query();
125 require_once('admin-header.php');
127 if ( !isset( $_GET['paged'] ) )
130 if ( empty($_GET['mode']) )
133 $mode = esc_attr($_GET['mode']); ?>
136 <?php screen_icon(); ?>
137 <h2><?php echo esc_html( $title ); ?> <a href="post-new.php" class="button add-new-h2"><?php echo esc_html_x('Add New', 'post'); ?></a> <?php
138 if ( isset($_GET['s']) && $_GET['s'] )
139 printf( '<span class="subtitle">' . __('Search results for “%s”') . '</span>', esc_html( get_search_query() ) ); ?>
143 if ( isset($_GET['posted']) && $_GET['posted'] ) : $_GET['posted'] = (int) $_GET['posted']; ?>
144 <div id="message" class="updated fade"><p><strong><?php _e('Your post has been saved.'); ?></strong> <a href="<?php echo get_permalink( $_GET['posted'] ); ?>"><?php _e('View post'); ?></a> | <a href="<?php echo get_edit_post_link( $_GET['posted'] ); ?>"><?php _e('Edit post'); ?></a></p></div>
145 <?php $_SERVER['REQUEST_URI'] = remove_query_arg(array('posted'), $_SERVER['REQUEST_URI']);
148 <?php if ( isset($_GET['locked']) || isset($_GET['skipped']) || isset($_GET['updated']) || isset($_GET['deleted']) || isset($_GET['trashed']) || isset($_GET['untrashed']) ) { ?>
149 <div id="message" class="updated fade"><p>
150 <?php if ( isset($_GET['updated']) && (int) $_GET['updated'] ) {
151 printf( _n( '%s post updated.', '%s posts updated.', $_GET['updated'] ), number_format_i18n( $_GET['updated'] ) );
152 unset($_GET['updated']);
155 if ( isset($_GET['skipped']) && (int) $_GET['skipped'] )
156 unset($_GET['skipped']);
158 if ( isset($_GET['locked']) && (int) $_GET['locked'] ) {
159 printf( _n( '%s post not updated, somebody is editing it.', '%s posts not updated, somebody is editing them.', $_GET['locked'] ), number_format_i18n( $_GET['locked'] ) );
160 unset($_GET['locked']);
163 if ( isset($_GET['deleted']) && (int) $_GET['deleted'] ) {
164 printf( _n( 'Post permanently deleted.', '%s posts permanently deleted.', $_GET['deleted'] ), number_format_i18n( $_GET['deleted'] ) );
165 unset($_GET['deleted']);
168 if ( isset($_GET['trashed']) && (int) $_GET['trashed'] ) {
169 printf( _n( 'Post moved to the trash.', '%s posts moved to the trash.', $_GET['trashed'] ), number_format_i18n( $_GET['trashed'] ) );
170 $ids = isset($_GET['ids']) ? $_GET['ids'] : 0;
171 echo ' <a href="' . esc_url( wp_nonce_url( "edit.php?doaction=undo&action=untrash&ids=$ids", "bulk-posts" ) ) . '">' . __('Undo') . '</a><br />';
172 unset($_GET['trashed']);
175 if ( isset($_GET['untrashed']) && (int) $_GET['untrashed'] ) {
176 printf( _n( 'Post restored from the trash.', '%s posts restored from the trash.', $_GET['untrashed'] ), number_format_i18n( $_GET['untrashed'] ) );
177 unset($_GET['undeleted']);
180 $_SERVER['REQUEST_URI'] = remove_query_arg( array('locked', 'skipped', 'updated', 'deleted', 'trashed', 'untrashed'), $_SERVER['REQUEST_URI'] );
185 <form id="posts-filter" action="<?php echo admin_url('edit.php'); ?>" method="get">
187 <ul class="subsubsub">
189 if ( empty($locked_post_status) ) :
190 $status_links = array();
191 $num_posts = wp_count_posts( 'post', 'readable' );
196 if ( isset( $_GET['author'] ) && ( $_GET['author'] == $current_user->ID ) )
197 $class = ' class="current"';
198 $status_links[] = "<li><a href='edit.php?author=$current_user->ID'$class>" . sprintf( _nx( 'My Posts <span class="count">(%s)</span>', 'My Posts <span class="count">(%s)</span>', $user_posts_count, 'posts' ), number_format_i18n( $user_posts_count ) ) . '</a>';
199 $allposts = '?all_posts=1';
202 $total_posts = array_sum( (array) $num_posts ) - $num_posts->trash;
203 $class = empty($class) && empty($_GET['post_status']) ? ' class="current"' : '';
204 $status_links[] = "<li><a href='edit.php{$allposts}'$class>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_posts, 'posts' ), number_format_i18n( $total_posts ) ) . '</a>';
206 foreach ( $post_stati as $status => $label ) {
209 if ( !in_array( $status, $avail_post_stati ) )
212 if ( empty( $num_posts->$status ) )
215 if ( isset($_GET['post_status']) && $status == $_GET['post_status'] )
216 $class = ' class="current"';
218 $status_links[] = "<li><a href='edit.php?post_status=$status'$class>" . sprintf( _n( $label[2][0], $label[2][1], $num_posts->$status ), number_format_i18n( $num_posts->$status ) ) . '</a>';
220 echo implode( " |</li>\n", $status_links ) . '</li>';
221 unset( $status_links );
226 <p class="search-box">
227 <label class="screen-reader-text" for="post-search-input"><?php _e( 'Search Posts' ); ?>:</label>
228 <input type="text" id="post-search-input" name="s" value="<?php the_search_query(); ?>" />
229 <input type="submit" value="<?php esc_attr_e( 'Search Posts' ); ?>" class="button" />
232 <input type="hidden" name="post_status" class="post_status_page" value="<?php echo !empty($_GET['post_status']) ? esc_attr($_GET['post_status']) : 'all'; ?>" />
233 <input type="hidden" name="mode" value="<?php echo esc_attr($mode); ?>" />
235 <?php if ( have_posts() ) { ?>
237 <div class="tablenav">
239 $page_links = paginate_links( array(
240 'base' => add_query_arg( 'paged', '%#%' ),
242 'prev_text' => __('«'),
243 'next_text' => __('»'),
244 'total' => $wp_query->max_num_pages,
245 'current' => $_GET['paged']
248 $is_trash = isset($_GET['post_status']) && $_GET['post_status'] == 'trash';
252 <div class="alignleft actions">
253 <select name="action">
254 <option value="-1" selected="selected"><?php _e('Bulk Actions'); ?></option>
255 <?php if ( $is_trash ) { ?>
256 <option value="untrash"><?php _e('Restore'); ?></option>
258 <option value="edit"><?php _e('Edit'); ?></option>
259 <?php } if ( $is_trash || !EMPTY_TRASH_DAYS ) { ?>
260 <option value="delete"><?php _e('Delete Permanently'); ?></option>
262 <option value="trash"><?php _e('Move to Trash'); ?></option>
265 <input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction" id="doaction" class="button-secondary action" />
266 <?php wp_nonce_field('bulk-posts'); ?>
268 <?php // view filters
269 if ( !is_singular() ) {
270 $arc_query = "SELECT DISTINCT YEAR(post_date) AS yyear, MONTH(post_date) AS mmonth FROM $wpdb->posts WHERE post_type = 'post' ORDER BY post_date DESC";
272 $arc_result = $wpdb->get_results( $arc_query );
274 $month_count = count($arc_result);
276 if ( $month_count && !( 1 == $month_count && 0 == $arc_result[0]->mmonth ) ) {
277 $m = isset($_GET['m']) ? (int)$_GET['m'] : 0;
280 <option<?php selected( $m, 0 ); ?> value='0'><?php _e('Show all dates'); ?></option>
282 foreach ($arc_result as $arc_row) {
283 if ( $arc_row->yyear == 0 )
285 $arc_row->mmonth = zeroise( $arc_row->mmonth, 2 );
287 if ( $arc_row->yyear . $arc_row->mmonth == $m )
288 $default = ' selected="selected"';
292 echo "<option$default value='" . esc_attr("$arc_row->yyear$arc_row->mmonth") . "'>";
293 echo $wp_locale->get_month($arc_row->mmonth) . " $arc_row->yyear";
301 $dropdown_options = array('show_option_all' => __('View all categories'), 'hide_empty' => 0, 'hierarchical' => 1,
302 'show_count' => 0, 'orderby' => 'name', 'selected' => $cat);
303 wp_dropdown_categories($dropdown_options);
304 do_action('restrict_manage_posts');
306 <input type="submit" id="post-query-submit" value="<?php esc_attr_e('Filter'); ?>" class="button-secondary" />
309 if ( $is_trash && current_user_can('edit_others_posts') ) { ?>
310 <input type="submit" name="delete_all" id="delete_all" value="<?php esc_attr_e('Empty Trash'); ?>" class="button-secondary apply" />
314 <?php if ( $page_links ) { ?>
315 <div class="tablenav-pages"><?php $page_links_text = sprintf( '<span class="displaying-num">' . __( 'Displaying %s–%s of %s' ) . '</span>%s',
316 number_format_i18n( ( $_GET['paged'] - 1 ) * $wp_query->query_vars['posts_per_page'] + 1 ),
317 number_format_i18n( min( $_GET['paged'] * $wp_query->query_vars['posts_per_page'], $wp_query->found_posts ) ),
318 number_format_i18n( $wp_query->found_posts ),
320 ); echo $page_links_text; ?></div>
323 <div class="view-switch">
324 <a href="<?php echo esc_url(add_query_arg('mode', 'list', $_SERVER['REQUEST_URI'])) ?>"><img <?php if ( 'list' == $mode ) echo 'class="current"'; ?> id="view-switch-list" src="../wp-includes/images/blank.gif" width="20" height="20" title="<?php _e('List View') ?>" alt="<?php _e('List View') ?>" /></a>
325 <a href="<?php echo esc_url(add_query_arg('mode', 'excerpt', $_SERVER['REQUEST_URI'])) ?>"><img <?php if ( 'excerpt' == $mode ) echo 'class="current"'; ?> id="view-switch-excerpt" src="../wp-includes/images/blank.gif" width="20" height="20" title="<?php _e('Excerpt View') ?>" alt="<?php _e('Excerpt View') ?>" /></a>
328 <div class="clear"></div>
331 <div class="clear"></div>
333 <?php include( 'edit-post-rows.php' ); ?>
335 <div class="tablenav">
339 echo "<div class='tablenav-pages'>$page_links_text</div>";
342 <div class="alignleft actions">
343 <select name="action2">
344 <option value="-1" selected="selected"><?php _e('Bulk Actions'); ?></option>
345 <?php if ( $is_trash ) { ?>
346 <option value="untrash"><?php _e('Restore'); ?></option>
348 <option value="edit"><?php _e('Edit'); ?></option>
349 <?php } if ( $is_trash || !EMPTY_TRASH_DAYS ) { ?>
350 <option value="delete"><?php _e('Delete Permanently'); ?></option>
352 <option value="trash"><?php _e('Move to Trash'); ?></option>
355 <input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction2" id="doaction2" class="button-secondary action" />
356 <?php if ( $is_trash && current_user_can('edit_others_posts') ) { ?>
357 <input type="submit" name="delete_all2" id="delete_all2" value="<?php esc_attr_e('Empty Trash'); ?>" class="button-secondary apply" />
364 <?php } else { // have_posts() ?>
365 <div class="clear"></div>
367 if ( isset($_GET['post_status']) && 'trash' == $_GET['post_status'] )
368 _e('No posts found in the trash');
370 _e('No posts found');
376 <?php inline_edit_row( 'post' ); ?>
378 <div id="ajax-response"></div>
383 include('admin-footer.php');