Skip to content

Instantly share code, notes, and snippets.

@shivapoudel
Created November 22, 2019 11:38
Show Gist options
  • Save shivapoudel/14d25b7ec37daeb1633f7084bafe6b8c to your computer and use it in GitHub Desktop.
Save shivapoudel/14d25b7ec37daeb1633f7084bafe6b8c to your computer and use it in GitHub Desktop.

Revisions

  1. shivapoudel created this gist Nov 22, 2019.
    71 changes: 71 additions & 0 deletions functions.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,71 @@
    <?php
    /**
    * Custom shortcode to display form entries.
    *
    * Usage [everest_forms_entries_table id="FORMID"]
    *
    * @param array $atts Shortcode attributes.
    */
    function evf_entries_table( $atts ) {
    $atts = shortcode_atts(
    array(
    'id' => '',
    ),
    $atts
    );

    if ( empty( $atts['id'] ) || ! function_exists( 'EVF' ) ) {
    return;
    }

    $form = EVF()->form->get( absint( $atts['id'] ) );

    if ( empty( $form ) ) {
    return;
    }

    $form_data = ! empty( $form->post_content ) ? evf_decode( $form->post_content ) : '';
    $entry_ids = evf_search_entries(
    array(
    'limit' => -1,
    'order' => 'ASC',
    'form_id' => absint( $atts['id'] ),
    )
    );
    $entries = array_map( 'evf_get_entry', $entry_ids );
    $disallow = apply_filters( 'everest_forms_frontend_entries_table_disallow', array( 'divider', 'html', 'captcha' ) );
    $ids = array();
    ob_start();
    ?>
    <table class="everest-forms-frontend-entries">
    <thead>
    <tr>
    <?php
    foreach ( $form_data['form_fields'] as $field ) {
    if ( ! in_array( $field['type'], $disallow, true ) ) {
    $ids[] = $field['id'];
    echo '<th>' . sanitize_text_field( $field['label'] ) . '</th>';
    }
    }
    ?>
    </tr>
    </thead>
    <tbody>
    <?php
    foreach ( $entries as $entry ) {
    echo '<tr>';
    foreach ( $entry->meta as $meta_key => $meta_value ) {
    // if ( in_array( $meta_key, $ids, true ) ) {
    echo '<td>' . apply_filters( 'everest_forms_html_field_value', wp_strip_all_tags( $meta_value ), $meta_key, $form_data, 'entry-frontend-table' );
    // }
    }
    echo '</tr>';
    }
    ?>
    </tbody>
    </table>
    <?php

    return ob_get_clean();
    }
    add_shortcode( 'everest_forms_entries_table', 'evf_entries_table' );