get_var( $countQuery );
$orderby = ( ! empty( $_GET['orderby'] ) ) ? $_GET['orderby'] : 'created_at';
$order = isset( $_GET['order'] ) ? strtoupper( trim( $_GET['order'] ) ) : 'DESC';
if ( $order !== null && $order !== 'ASC' && $order !== 'DESC' ) {
$order = null;
}
$query = "SELECT * FROM $table ORDER BY $orderby $order";
$per_page = 10;
$current_page = $this->get_pagenum();
$query .= $wpdb->prepare( " LIMIT %d, %d", $per_page * ( $current_page - 1 ), $per_page );
$items = $wpdb->get_results( $query, 'ARRAY_A' );
$this->items = $items;
$columns = $this->get_columns();
$hidden = array();
$sortable = $this->get_sortable_columns();
$this->_column_headers = [ $columns, $hidden, $sortable ];
$this->items = $items;
$this->set_pagination_args( array(
'total_items' => $count,
'per_page' => $per_page,
) );
}
/**
* {@inheritdoc}
*/
function no_items () {
_e( 'No emails uploaded yet.', 'anycomment' );
}
/**
* {@inheritdoc}
*/
function column_default ( $item, $column_name ) {
switch ( $column_name ) {
case 'post_ID':
$post = get_post( $item[ $column_name ] );
if ( $post === null ) {
return null;
}
$url = esc_url( add_query_arg( array(
'post' => $post->ID,
'action' => 'edit',
), admin_url( 'post.php' ) ) );
return sprintf( '%s', $url, $post->post_title );
case 'comment_ID':
$comment = get_comment( $item[ $column_name ] );
if ( ! $comment instanceof \WP_Comment ) {
return '';
}
// Set up the user editing link
$edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_comment_to_edit( $comment->ID ) ) );
if ( current_user_can( 'moderate_comments', $comment->ID ) ) {
$comment_html = $comment->comment_content . "
";
$comment_html .= "" . __( 'Edit' ) . '';;
} else {
$comment_html = " {$comment->comment_content}
";
}
return $comment_html;
case 'email':
$email = $item[ $column_name ];
if ( empty( $email ) ) {
return '';
}
$user = get_user_by( 'email', $email );
$to_display = $user instanceof \WP_User ? $user->user_login : $email;
$super_admin = '';
$user_html = '';
if ( $user instanceof \WP_User ) {
$user_html = get_avatar( $user->ID, 25 );
}
// Set up the user editing link
$edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user->ID ) ) );
if ( current_user_can( 'edit_user' ) ) {
$user_html .= " {$to_display}{$super_admin}
";
$actions['edit'] = '' . __( 'Edit' ) . '';
} else {
$user_html .= " {$to_display}{$super_admin}
";
}
return $user_html;
case 'subject':
return $item[ $column_name ];
case 'content':
return esc_html( $item[ $column_name ] );
case 'ip':
return $item[ $column_name ];
case 'url':
return sprintf( '%s', $item[ $column_name ], $item[ $column_name ] );
case 'is_sent':
return $item[ $column_name ];
case 'created_at':
$format = sprintf( "%s %s", get_option( 'date_format' ), get_option( 'time_format' ) );
return date( $format, strtotime( $item[ $column_name ] ) );
}
}
/**
* {@inheritdoc}
*/
function column_cb ( $item ) {
return sprintf(
'', $item['ID']
);
}
/**
* {@inheritdoc}
*/
function get_bulk_actions () {
$actions = array(
'delete' => __( 'Delete', 'anycomment' ),
);
return $actions;
}
/**
* {@inheritdoc}
*/
function get_sortable_columns () {
$sortable_columns = [
'post_ID' => [ 'post_ID', false ],
'comment_ID' => [ 'comment_ID', false ],
'is_sent' => [ 'is_sent', false ],
'ip' => [ 'ip', false ],
'created_at' => [ 'created_at', false ],
];
return $sortable_columns;
}
/**
* {@inheritdoc}
*/
public function get_columns () {
$c = array(
'cb' => '',
'post_ID' => __( 'Post', 'anycomment' ),
'comment_ID' => __( 'Comment', 'anycomment' ),
'email' => __( 'Email', 'anycomment' ),
'subject' => __( 'Subject', 'anycomment' ),
'content' => __( 'Content', 'anycomment' ),
'ip' => __( 'IP', 'anycomment' ),
'is_sent' => __( 'Is Sent?', 'anycomment' ),
'created_at' => __( 'Date', 'anycomment' ),
);
return $c;
}
}