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 '| No | ';
foreach ($fields as $i => $field) {
$label = $labels[$i] ?? $field;
echo '' . esc_html($label) . ' | ';
}
echo 'Tanggal | ';
echo '
';
$no = 1;
foreach ($rows as $row) {
$data = json_decode($row->response, true);
echo '';
echo '| ' . esc_html($no++) . ' | ';
foreach ($fields as $field) {
$value = $data[$field] ?? '';
if (is_array($value)) {
$value = implode(', ', array_map('sanitize_text_field', $value));
}
echo '' . esc_html($value) . ' | ';
}
echo '' . esc_html($row->created_at) . ' | ';
echo '
';
}
echo '
';
echo '
';
return ob_get_clean();
});