add_shortcode('ff_entries_view', function ($atts) { if (post_password_required()) { return ''; } global $wpdb; $atts = shortcode_atts([ 'form_id' => 0, 'fields' => '', 'labels' => '', 'limit' => 100 ], $atts); $form_id = absint($atts['form_id']); $limit = min(absint($atts['limit']), 300); if (!$form_id || empty($atts['fields'])) { return 'Form ID atau fields belum diatur.'; } $fields = array_map('trim', explode(',', $atts['fields'])); $labels = array_map('trim', explode(',', $atts['labels'])); $table = $wpdb->prefix . 'fluentform_submissions'; $rows = $wpdb->get_results( $wpdb->prepare( "SELECT id, response, created_at FROM {$table} WHERE form_id = %d AND status != 'trashed' ORDER BY id DESC LIMIT %d", $form_id, $limit ) ); if (!$rows) { return 'Belum ada data.'; } ob_start(); echo '
'; echo ''; echo ''; echo ''; foreach ($fields as $i => $field) { $label = $labels[$i] ?? $field; echo ''; } echo ''; echo ''; $no = 1; foreach ($rows as $row) { $data = json_decode($row->response, true); echo ''; echo ''; foreach ($fields as $field) { $value = $data[$field] ?? ''; if (is_array($value)) { $value = implode(', ', array_map('sanitize_text_field', $value)); } echo ''; } echo ''; echo ''; } echo '
No' . esc_html($label) . 'Tanggal
' . esc_html($no++) . '' . esc_html($value) . '' . esc_html($row->created_at) . '
'; echo '
'; return ob_get_clean(); });