'entry', 'plural' => 'entries', 'ajax' => false, ) ); } /** * Columns. * * @return array */ public function get_columns() { return array( 'cb' => '', 'summary' => __( 'Submission', 'alpeg-forms' ), 'form_title' => __( 'Form', 'alpeg-forms' ), 'created_at' => __( 'Received', 'alpeg-forms' ), ); } /** * Sortierbare Columns. * * @return array */ protected function get_sortable_columns() { return array( 'form_title' => array( 'form_title', false ), 'created_at' => array( 'created_at', true ), ); } /** * Bulk actions. * * @return array */ protected function get_bulk_actions() { return array( 'read' => __( 'Mark as read', 'alpeg-forms' ), 'unread' => __( 'Mark as unread', 'alpeg-forms' ), 'delete' => __( 'Delete', 'alpeg-forms' ), ); } /** * Views: All / Unread. * * @return array */ protected function get_views() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended $current = isset( $_GET['status'] ) ? sanitize_key( wp_unslash( $_GET['status'] ) ) : ''; $base = admin_url( 'admin.php?page=alpeg-forms' ); $all = Entries::count(); $unread = Entries::count( array( 'status' => 'unread' ) ); return array( 'all' => sprintf( '%s (%d)', esc_url( $base ), '' === $current ? ' class="current" aria-current="page"' : '', esc_html__( 'All', 'alpeg-forms' ), $all ), 'unread' => sprintf( '%s (%d)', esc_url( add_query_arg( 'status', 'unread', $base ) ), 'unread' === $current ? ' class="current" aria-current="page"' : '', esc_html__( 'Unread', 'alpeg-forms' ), $unread ), ); } /** * Form filter and export above the table. * * @param string $which top|bottom. */ protected function extra_tablenav( $which ) { if ( 'top' !== $which ) { return; } $forms = Entries::forms(); // phpcs:ignore WordPress.Security.NonceVerification.Recommended $current = isset( $_GET['form_id'] ) ? sanitize_key( wp_unslash( $_GET['form_id'] ) ) : ''; echo '
' . esc_html( wp_html_excerpt( $row['value'], 140, '…' ) ) . '
'; break; } } $icons = ''; if ( wp_list_filter( $item->data, array( 'type' => 'file' ) ) ) { $icons .= ' '; } if ( 'failed' === $item->mail_status ) { $icons .= ' '; } $unread = 'unread' === $item->status ? '' : ''; $del = wp_nonce_url( admin_url( 'admin-post.php?action=alpeg_forms_entry&do=delete&id=' . $item->id ), 'alpeg_forms_entry_' . $item->id ); $actions = array( 'view' => '' . esc_html__( 'View', 'alpeg-forms' ) . '', 'delete' => '' . esc_html__( 'Delete', 'alpeg-forms' ) . '', ); return $unread . '' . esc_html( $title ) . '' . $icons . $preview . $this->row_actions( $actions ); } /** * Form. * * @param object $item Zeile. * @return string */ protected function column_form_title( $item ) { return esc_html( $item->form_title ); } /** * Date. * * @param object $item Zeile. * @return string */ protected function column_created_at( $item ) { $ts = strtotime( $item->created_at . ' UTC' ); $diff = time() - $ts; $text = $diff < DAY_IN_SECONDS /* translators: %s: time span, e.g. "5 minutes" */ ? sprintf( __( '%s ago', 'alpeg-forms' ), human_time_diff( $ts ) ) : wp_date( get_option( 'date_format' ) . ', ' . get_option( 'time_format' ), $ts ); return ''; } /** * Text for an empty list (e.g. search without results). */ public function no_items() { esc_html_e( 'No matching submissions found.', 'alpeg-forms' ); } /** * Process bulk actions (runs before output). */ public static function process_bulk_action() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'You are not allowed to do this.', 'alpeg-forms' ), 403 ); } // phpcs:disable WordPress.Security.NonceVerification.Recommended $action = ''; if ( isset( $_GET['action'] ) && '-1' !== $_GET['action'] ) { $action = sanitize_key( wp_unslash( $_GET['action'] ) ); } elseif ( isset( $_GET['action2'] ) && '-1' !== $_GET['action2'] ) { $action = sanitize_key( wp_unslash( $_GET['action2'] ) ); } if ( ! in_array( $action, array( 'read', 'unread', 'delete' ), true ) || empty( $_GET['entry'] ) ) { return; } // phpcs:enable check_admin_referer( 'bulk-entries' ); $ids = array_map( 'absint', (array) wp_unslash( $_GET['entry'] ) ); if ( 'delete' === $action ) { $n = Entries::delete( $ids ); } else { Entries::set_status( $ids, $action ); $n = count( $ids ); } wp_safe_redirect( add_query_arg( array( 'page' => 'alpeg-forms', 'af_done' => 'delete' === $action ? 'deleted' : $action, 'af_n' => $n, ), admin_url( 'admin.php' ) ) ); exit; } }