Created
November 22, 2019 11:38
-
-
Save shivapoudel/14d25b7ec37daeb1633f7084bafe6b8c to your computer and use it in GitHub Desktop.
Everest Forms display form entries with a custom shortcode.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Does this still work? I need some help, would you be willing to help out?