Skip to content

Instantly share code, notes, and snippets.

@aimahdi
Created June 5, 2025 09:05
Show Gist options
  • Save aimahdi/ca3c70fc52a44b35e238b3cfdf816fc9 to your computer and use it in GitHub Desktop.
Save aimahdi/ca3c70fc52a44b35e238b3cfdf816fc9 to your computer and use it in GitHub Desktop.
function get_fluentform_schedule_dates( $form_id ) {
global $wpdb;
if ( ! $form_id ) {
return 'Invalid form ID.';
}
$table_name = $wpdb->prefix . 'fluentform_form_meta';
// Get all meta for the form
$results = $wpdb->get_results(
$wpdb->prepare(
"SELECT meta_key, value FROM $table_name WHERE form_id = %d",
$form_id
),
ARRAY_A
);
if ( empty( $results ) ) {
return 'No meta data found for this form.';
}
$meta_data = [];
foreach ( $results as $row ) {
$meta_data[ $row['meta_key'] ] = maybe_unserialize( $row['value'] );
}
// The scheduling info is usually inside the $'form_settings' meta key
$form_settings = isset( $meta_data['formSettings'] ) ? json_decode($meta_data['formSettings']) : [];
$form_restrictions = $form_settings->restrictions;
$scheduleFormEnabled = $form_restrictions -> scheduleForm -> enabled;
if($scheduleFormEnabled){
$schedule_start = $form_restrictions -> scheduleForm -> start;
$schedule_end = $form_restrictions -> scheduleForm -> end;
ob_start();
echo "<div class='ffp-schedule-dates'>";
if ( $schedule_start ) {
echo "<strong>Submission Start:</strong> " . esc_html( (new DateTime($schedule_start))->format('F j, Y H:i \U\T\C') ) . "<br>";
} else {
echo "<strong>Submission Start:</strong> Not set.<br>";
}
if ( $schedule_end ) {
echo "<strong>Submission Start:</strong> " . esc_html( (new DateTime($schedule_end))->format('F j, Y H:i \U\T\C') ) . "<br>";
} else {
echo "<strong>Submission End:</strong> Not set.";
}
echo "</div>";
}
return ob_get_clean();
}
// Usage example via shortcode:
function ffp_schedule_shortcode( $atts ) {
$atts = shortcode_atts( [
'id' => 0,
], $atts );
return get_fluentform_schedule_dates( intval( $atts['id'] ) );
}
add_shortcode( 'ffp_schedule', 'ffp_schedule_shortcode' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment