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 files 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 'user_ID': $user_object = get_user_by( 'id', $item[ $column_name ] ); if ( ! $user_object instanceof WP_User ) { return ''; } $super_admin = ''; $userHtml = get_avatar( $user_object->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_object->ID ) ) ); if ( current_user_can( 'edit_user', $user_object->ID ) ) { $userHtml .= " {$user_object->user_login}{$super_admin}
"; $actions['edit'] = '' . __( 'Edit' ) . ''; } else { $userHtml .= " {$user_object->user_login}{$super_admin}
"; } return $userHtml; case 'ip': return $item[ $column_name ]; case 'url': return sprintf( '%s', $item[ $column_name ], $item[ $column_name ] ); case 'created_at': $format = sprintf( "%s %s", get_option( 'date_format' ), get_option( 'time_format' ) ); return date( $format, $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 ], 'user_ID' => [ 'user_ID', false ], 'created_at' => [ 'created_at', false ] ]; return $sortable_columns; } /** * {@inheritdoc} */ public function get_columns() { $c = array( 'cb' => '', 'post_ID' => __( 'Post', 'anycomment' ), 'user_ID' => __( 'User', 'anycomment' ), 'ip' => __( 'IP', 'anycomment' ), 'url' => __( 'URL', 'anycomment' ), 'created_at' => __( 'Date', 'anycomment' ), ); return $c; } }