0, 'id' => 0, 'fields' => '', 'per_page' => 20, 'status' => 'read,unread', 'search' => 'yes', 'user' => 'all', 'view' => 'yes', 'empty' => __( 'No entries yet.', 'fieldwren' ), ), (array) $atts, 'fwren_entries' ); $form_id = absint( $a['form'] ? $a['form'] : $a['id'] ); if ( ! Form::exists( $form_id ) ) { return current_user_can( 'fwren_manage_forms' ) ? '
' . esc_html__( 'Entries: form not found.', 'fieldwren' ) . '
' : ''; } $own = 'current' === $a['user']; if ( $own && ! is_user_logged_in() ) { return '' . esc_html__( 'Please log in to see your entries.', 'fieldwren' ) . ' ' . esc_html__( 'Log in', 'fieldwren' ) . '
'; } if ( ! $own && ! current_user_can( 'fwren_view_entries' ) ) { return ''; } wp_enqueue_style( 'fwren-front-entries' ); $schema = Schema::get( $form_id ); $keys = array_values( array_filter( array_map( 'sanitize_key', array_map( 'trim', explode( ',', (string) $a['fields'] ) ) ) ) ); $keys = array_values( array_filter( $keys, static function ( $k ) use ( $schema ) { return isset( $schema['fields'][ $k ] ) && empty( $schema['fields'][ $k ]['sensitive'] ); } ) ); if ( ! $keys ) { foreach ( $schema['order'] as $k ) { $f = $schema['fields'][ $k ]; if ( empty( $f['sensitive'] ) && 'hidden' !== $f['type'] && empty( $f['signature'] ) ) { $keys[] = $k; } if ( count( $keys ) >= 5 ) { break; } } } $statuses = array_values( array_intersect( array_map( 'trim', explode( ',', strtolower( (string) $a['status'] ) ) ), self::STATUSES ) ); $statuses = $statuses ? $statuses : array( 'read', 'unread' ); $per = max( 1, min( 100, (int) $a['per_page'] ) ); $sk = 'fwren_es_' . $form_id; $pk = 'fwren_ep_' . $form_id; $search = 'yes' === $a['search'] && isset( $_GET[ $sk ] ) ? sanitize_text_field( wp_unslash( $_GET[ $sk ] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification $page = max( 1, absint( $_GET[ $pk ] ?? 1 ) ); // phpcs:ignore WordPress.Security.NonceVerification list( $rows, $total ) = self::query( $form_id, $statuses, $own ? get_current_user_id() : 0, $search, $per, $page ); $h = '' . esc_html( $a['empty'] ) . '
| # | ' . esc_html__( 'Date', 'fieldwren' ) . ' | '; foreach ( $keys as $k ) { $h .= '' . esc_html( Schema::label( $schema['fields'][ $k ] ) ) . ' | '; } if ( 'yes' === $a['view'] ) { $h .= '' . esc_html__( 'View', 'fieldwren' ) . ' | '; } $h .= '
|---|---|---|---|
| ' . (int) $r['serial'] . ' | ' . esc_html( wp_date( $df, strtotime( $r['created_at'] . ' UTC' ) ) ) . ' | '; foreach ( $keys as $k ) { $f = $schema['fields'][ $k ]; $type = Fields::get( $f['type'] ); $v = $r['response'][ $k ] ?? ''; $h .= '' . ( $type ? wp_kses_post( $type->format( $v, $f, 'html' ) ) : esc_html( is_array( $v ) ? implode( ', ', $v ) : (string) $v ) ) . ' | '; } if ( 'yes' === $a['view'] ) { $h .= '' . esc_html__( 'View', 'fieldwren' ) . ' | '; } $h .= '
' . esc_html__( 'This link is invalid or the entry was removed.', 'fieldwren' ) . '
', 404 ); } $form_id = (int) $entry['form_id']; $schema = Schema::get( $form_id ); $date = wp_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), strtotime( $entry['created_at'] . ' UTC' ) ); $statuses = Entries::statuses(); /* translators: 1: entry number, 2: date */ $html = '' . Smartcodes::all_data( $schema, (array) $entry['response'], 'html' ); $html = apply_filters( 'fwren/front_entries/view_html', $html, $entry ); Helpers::page( get_the_title( $form_id ), $html ); } }