wp-admin/edit-comments.php


Lines:

1 to 100 of 388
<?php

/**
 * Edit Comments Administration Screen.
 *
 * @package WordPress
 * @subpackage Administration
 */


/** WordPress Administration Bootstrap */
require_once __DIR__ . '/admin.php';
if ( ! current_user_can( 'edit_posts' ) ) {
  wp_die(
    '<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' .
    '<p>' . __( 'Sorry, you are not allowed to edit comments.' ) . '</p>',
    403
  );
}

$wp_list_table = _get_list_table( 'WP_Comments_List_Table' );
$pagenum       = $wp_list_table->get_pagenum();

$doaction = $wp_list_table->current_action();

if ( $doaction ) {
  check_admin_referer( 'bulk-comments' );

  if ( 'delete_all' === $doaction && ! empty( $_REQUEST['pagegen_timestamp'] ) ) {
    
/**
 * @global wpdb $wpdb WordPress database abstraction object.
 */
    global $wpdb;

    $comment_status = wp_unslash( $_REQUEST['comment_status'] );
    $delete_time    = wp_unslash( $_REQUEST['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 ) );
    $doaction       = 'delete';
  } elseif ( isset( $_REQUEST['delete_comments'] ) ) {
    $comment_ids = $_REQUEST['delete_comments'];
    $doaction    = $_REQUEST['action'];
  } elseif ( isset( $_REQUEST['ids'] ) ) {
    $comment_ids = array_map( 'absint', explode( ',', $_REQUEST['ids'] ) );
  } elseif ( wp_get_referer() ) {
    wp_safe_redirect( wp_get_referer() );
    exit;
  }

  $approved   = 0;
  $unapproved = 0;
  $spammed    = 0;
  $unspammed  = 0;
  $trashed    = 0;
  $untrashed  = 0;
  $deleted    = 0;

  $redirect_to = remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'spammed', 'unspammed', 'approved', 'unapproved', 'ids' ), wp_get_referer() );
  $redirect_to = add_query_arg( 'paged', $pagenum, $redirect_to );

  wp_defer_comment_counting( true );

  foreach ( $comment_ids as $comment_id ) { // Check the permissions on each.
    if ( ! current_user_can( 'edit_comment', $comment_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':
        wp_spam_comment( $comment_id );
        $spammed++;
        break;
      case 'unspam':
        wp_unspam_comment( $comment_id );
        $unspammed++;
        break;
      case 'trash':
        wp_trash_comment( $comment_id );
        $trashed++;
        break;
      case 'untrash':
        wp_untrash_comment( $comment_id );
        $untrashed++;
        break;
      case 'delete':
        wp_delete_comment( $comment_id );
        $deleted++;
        break;
    }
  }

  if ( ! in_array( $doaction, array( 'approve', 'unapprove', 'spam', 'unspam', 'trash', 'delete' ), true ) ) {

 View on GitHub View on Trac

Called by

    Invoked by

      Calls

      API Letters: ,,,,