'entry', 'plural' => 'entries', 'ajax' => false ) ); $this->form = $form; } private function request( $key, $fallback = '' ) { return isset( $_REQUEST[ $key ] ) ? sanitize_text_field( wp_unslash( $_REQUEST[ $key ] ) ) : $fallback; // phpcs:ignore WordPress.Security.NonceVerification } public function get_columns() { $cols = array( 'cb' => '', 'created_at' => __( 'Received', 'pubforms' ) ); foreach ( array_slice( $this->form['fields'], 0, 3 ) as $field ) { $cols[ 'f_' . $field['id'] ] = $field['label']; } $cols['status'] = __( 'Status', 'pubforms' ); return $cols; } protected function get_sortable_columns() { return array( 'created_at' => array( 'created_at', true ), 'status' => array( 'status', false ) ); } protected function get_bulk_actions() { return array( 'mark_read' => __( 'Mark as read', 'pubforms' ), 'mark_unread' => __( 'Mark as unread', 'pubforms' ), 'delete' => __( 'Delete', 'pubforms' ), ); } protected function get_views() { $counts = pubforms_entry_counts( $this->form['id'] ); $current = $this->request( 'status' ); $partial = (int) $this->request( 'partial' ); $link = function ( $status, $label, $count ) use ( $current ) { return sprintf( '%s (%d)', esc_url( pubforms_entries_url( $this->form['id'], $status ? array( 'status' => $status ) : array() ) ), $current === $status && 0 === (int) $this->request( 'partial' ) ? 'current' : '', esc_html( $label ), (int) $count ); }; $views = array( 'all' => $link( '', __( 'All', 'pubforms' ), $counts['total'] ), 'unread' => $link( 'unread', __( 'Unread', 'pubforms' ), $counts['unread'] ), 'read' => $link( 'read', __( 'Read', 'pubforms' ), $counts['total'] - $counts['unread'] ), ); if ( $counts['partial'] ) { $views['partial'] = sprintf( '%s (%d)', esc_url( pubforms_entries_url( $this->form['id'], array( 'partial' => '1' ) ) ), 1 === $partial ? 'current' : '', esc_html__( 'Abandoned', 'pubforms' ), (int) $counts['partial'] ); } return $views; } public function prepare_items() { $per_page = 20; $result = pubforms_query_entries( $this->form['id'], array( 'status' => $this->request( 'status' ), 'partial' => (int) $this->request( 'partial' ) ? 1 : 0, 'search' => $this->request( 's' ), 'date_from' => $this->request( 'date_from' ), 'date_to' => $this->request( 'date_to' ), 'orderby' => $this->request( 'orderby', 'created_at' ), 'order' => $this->request( 'order', 'desc' ), 'per_page' => $per_page, 'paged' => $this->get_pagenum(), ) ); $this->_column_headers = array( $this->get_columns(), array(), $this->get_sortable_columns(), 'created_at' ); $this->items = $result['items']; $this->set_pagination_args( array( 'total_items' => $result['total'], 'per_page' => $per_page ) ); } public function no_items() { esc_html_e( 'No entries yet.', 'pubforms' ); } protected function column_cb( $entry ) { return ''; } protected function column_created_at( $entry ) { $when = get_date_from_gmt( $entry->created_at, get_option( 'date_format' ) . ' ' . get_option( 'time_format' ) ); $actions = array( 'view' => '' . esc_html__( 'View', 'pubforms' ) . '', 'delete' => '' . esc_html__( 'Delete', 'pubforms' ) . '', ); $title = '' . esc_html( $when ) . ''; return ( 'unread' === $entry->status ? '' . $title . '' : $title ) . $this->row_actions( $actions ); } protected function column_default( $entry, $column ) { if ( 'status' === $column ) { return 'unread' === $entry->status ? esc_html__( 'Unread', 'pubforms' ) : esc_html__( 'Read', 'pubforms' ); } if ( 0 === strpos( $column, 'f_' ) ) { return esc_html( wp_html_excerpt( pubforms_entry_value( $entry, substr( $column, 2 ) ), 80, '…' ) ); } return ''; } }