base = $base; $this->admin = $base->admin; $this->post_id = isset($_REQUEST['p']) ? intval($_REQUEST['p']) : 0; $this->referer = remove_query_arg( array('approved', 'unapproved', 'spammed', 'unspammed', 'trashed', 'untrashed', 'deleted', 'ids'), $this->base->strip_host($this->admin->get_referer()) ); if ( isset( $_REQUEST['delete_all'] ) && !empty( $_REQUEST['pagegen_timestamp'] ) ) { check_admin_referer('bulk-comments'); $comment_status = isset($_POST['comment_status']) ? $_POST['comment_status'] : $_GET['comment_status']; $delete_time = isset($_POST['pagegen_timestamp']) ? $_POST['pagegen_timestamp'] : $_GET['pagegen_timestamp']; $comment_ids = $wpdb->get_col($wpdb->prepare("SELECT comment_ID FROM `$wpdb->comments` WHERE comment_approved = %s AND %s> comment_date_gmt", $comment_status, $delete_time)); $this->bulk_comments('delete', $comment_id); exit; } elseif ( isset($_REQUEST['delete_comments']) && -1 != $_REQUEST['action'] ) { check_admin_referer('bulk-comments'); $this->bulk_comments($_REQUEST['action'], $_REQUEST['delete_comments']); exit; } elseif ( $_REQUEST['doaction'] == 'undo' && isset($_REQUEST['ids']) ) { $comment_ids = array_map( 'absint', explode(',', $_REQUEST['ids']) ); $this->bulk_comments($_REQUEST['action'], $comment_ids); exit; } elseif ( isset($_GET['_wp_http_referer']) && ! empty($_GET['_wp_http_referer']) ) { $this->admin->redirect( remove_query_arg( array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI']) ) ); exit; } $this->output(); include dirname(__FILE__) . '/admin-footer.php'; } // ================================================== private function bulk_comments($doaction, $comment_ids) { global $wpdb; $approved = $unapproved = $spammed = $unspammed = $trashed = $untrashed = $deleted = 0; foreach ( (array) $comment_ids as $comment_id) : // Check the permissions on each $_post_id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT comment_post_ID FROM $wpdb->comments WHERE comment_ID = %d", $comment_id) ); if ( !current_user_can('edit_post', $_post_id) ) { continue; } switch( $doaction ) { case 'approve' : wp_set_comment_status($comment_id, 'approve'); $approved++; break; case 'unapprove' : wp_set_comment_status($comment_id, 'hold'); $unapproved++; break; case 'spam' : case 'markspam' : if (function_exists('wp_spam_coment')) { wp_spam_comment($comment_id); } else { wp_set_comment_status($comment_id, 'spam'); } $spammed++; break; case 'unspam' : if (function_exists('wp_unspam_comment')) { wp_unspam_comment($comment_id); $unspammed++; } break; case 'trash' : if (function_exists('wp_trash_comment')) { wp_trash_comment($comment_id); $trashed++; } break; case 'untrash' : if (function_exists('wp_untrash_comment')) { wp_untrash_comment($comment_id); $untrashed++; } break; case 'delete' : if (function_exists('wp_delete_comment')) { wp_delete_comment($comment_id); } else { wp_set_comment_status($comment_id, 'delete'); } $deleted++; break; } endforeach; $redirect_to = $this->referer; if ( false === strpos($redirect_to, 'edit-comments.php') ) { $redirect_to = 'edit-comments.php'; } if ( $approved ) $redirect_to = add_query_arg( 'approved', $approved, $redirect_to ); if ( $unapproved ) $redirect_to = add_query_arg( 'unapproved', $unapproved, $redirect_to ); if ( $spammed ) $redirect_to = add_query_arg( 'spammed', $spammed, $redirect_to ); if ( $unspammed ) $redirect_to = add_query_arg( 'unspammed', $unspammed, $redirect_to ); if ( $trashed ) $redirect_to = add_query_arg( 'trashed', $trashed, $redirect_to ); if ( $untrashed ) $redirect_to = add_query_arg( 'untrashed', $untrashed, $redirect_to ); if ( $deleted ) $redirect_to = add_query_arg( 'deleted', $deleted, $redirect_to ); if ( $trashed || $spammed ) $redirect_to = add_query_arg( 'ids', join(',', $comment_ids), $redirect_to ); if ( $this->post_id > 0 ) { $redirect_to = add_query_arg( 'p', $this->post_id, $redirect_to ); } if ( isset($_REQUEST['apage']) ) { $redirect_to = add_query_arg( 'apage', abs(intval($_REQUEST['apage'])), $redirect_to ); } if ( !empty($_REQUEST['mode']) ) { $redirect_to = add_query_arg('mode', $_REQUEST['mode'], $redirect_to); } if ( !empty($_REQUEST['comment_status']) ) { $redirect_to = add_query_arg('comment_status', $_REQUEST['comment_status'], $redirect_to); } if ( !empty($_REQUEST['s']) ) { $redirect_to = add_query_arg('s', $_REQUEST['s'], $redirect_to); } $this->admin->redirect($redirect_to); } // ================================================== private function comments_stati($num_comments, $comment_status, $comment_type) { $stati = array( 'all' => _n_noop('All', 'All'), // singular not used 'moderated' => _n_noop('Pending (%s)', 'Pending (%s)'), 'approved' => _n_noop('Approved', 'Approved'), // singular not used 'spam' => _n_noop('Spam (%s)', 'Spam (%s)'), ); if (function_exists('wp_trash_comment') && EMPTY_TRASH_DAYS > 0) { // must have _n_noop() $stati['trash'] = _n_noop('Trash (%s)', 'Trash (%s)'); } global $parent_file, $submenu, $submenu_file; $link = $submenu_file = 'edit-comments.php'; if ( !empty($comment_type) && 'all' != $comment_type ) $link = add_query_arg( 'comment_type', $comment_type, $link ); foreach ( $stati as $status => $label ) { if ( !isset( $num_comments->$status ) ) { $num_comments->$status = 10; } if ( 'all' != $status ) { $link = add_query_arg( 'comment_status', $status, $link ); } if ( $this->post_id ) $link = add_query_arg( 'p', abs(intval( $this->post_id )), $link ); $submenu[$parent_file][] = array(sprintf( _n( $label[0], $label[1], $num_comments->$status, 'ktai_style' ), number_format_i18n( $num_comments->$status )), 'edit_posts', $link); if ( str_replace( 'all', '', $status ) == $comment_status ) $submenu_file = $link; } return; } // ================================================== private function get_post_title($id) { if ($id > 0) { $post = get_post($id, OBJECT, 'display'); $post_title = esc_html( $post->post_title, 'double' ); $post_title = ('' == $post_title) ? "# $comment->comment_post_ID" : $post_title; } else { $post_title = NULL; } return $post_title; } // ================================================== private function comment_list_item($_comment) { global $comment; $comment = $_comment; $comment_status = wp_get_comment_status($comment->comment_ID); if ( 'unapproved' == $comment_status ) { $gray_start = ''; $gray_end = ''; } else { $gray_start = ''; $gray_end = ''; } $checkbox = ''; if (current_user_can('edit_post', $comment->comment_post_ID)) { $checkbox = ''; } echo '
';
if ( $approved > 0 ) {
printf( _n( '%s comment approved.', '%s comments approved.', $approved, 'ktai_style'), $approved );
echo '
';
}
if ( $spammed > 0 ) {
printf( _n( '%s comment marked as spam.', '%s comments marked as spam.', $spammed , 'ktai_style'), $spammed );
if (isset($_GET['ids']) && function_exists('wp_unspam_comment')) {
$undo_url = 'edit-comments.php?doaction=undo&action=unspam&ids=' . $_GET['ids'];
$undo_url = wp_nonce_url($undo_url, 'bulk-comments'); // does html escape
printf(' %s
', $undo_url, __('Undo'));
}
}
if ( $unspammed > 0 ) {
printf( _n( '%s comment restored from the spam', '%s comments restored from the spam', $unspammed , 'ktai_style'), $unspammed );
echo '
';
}
if ( $trashed > 0 ) {
printf( _n( '%s comment moved to the trash.', '%s comments moved to the trash.', $trashed , 'ktai_style'), $trashed );
if (isset($_GET['ids']) && function_exists('wp_untrash_comment')) {
$undo_url = 'edit-comments.php?doaction=undo&action=untrash&ids=' . $_GET['ids'];
$undo_url = wp_nonce_url($undo_url, 'bulk-comments'); // does html escape
printf('%s
', $undo_url, __('Undo'));
}
}
if ( $untrashed > 0 ) {
printf( _n( '%s comment restored from the trash.', '%s comments restored from the trash.', $untrashed, 'ktai_style'), $untrashed );
echo '
';
}
if ( $deleted > 0 ) {
printf( _n( '%s comment deleted.', '%s comments deleted.', $deleted, 'ktai_style'), $deleted );
echo '
';
}
echo '