Last active
February 21, 2024 14:40
-
-
Save iriks-it/5c3eaf1221c8018486689d2e54929786 to your computer and use it in GitHub Desktop.
Wordpress shortcode to display a form 7 days before the event starts
This file contains 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 | |
/** | |
* Function that runs when the shortcode pf_show_event_form is called | |
* @return string | |
*/ | |
function pf_show_event_form() { | |
if (!is_singular('event')){ | |
// This should only ever be called on a event page | |
return ''; | |
} | |
$no_entry_message = '<p> Ghaha, je bent te laat... Houdoe! </p> LOL, ik kan geen HTML... Success hiermee Daphne!'; | |
$gravityform_id = 1; // Dit moet je ff checken welk ID het is. | |
$gravityform_title = false; //Check of je de title wilt weergeven | |
$gravityform_desc = false; //Check of je de omschrijving wilt weergeven | |
$gravityform_ajax = false; //Dit moet je ff checken of het een Ajax call moet zijn ja of nee | |
$praktische_informatie = get_field('praktische_informatie', get_the_ID()); | |
$date_string = $praktische_informatie['datum']; | |
$current = new \DateTime(); | |
$current->setTime(0,0,0); | |
$future_date = clone $current; | |
$future_date->modify('+7 days'); | |
$event_date = DateTime::createFromFormat( 'Ymd', $date_string ); | |
$event_date->setTime(0,0,0); | |
if($event_date > $current && $event_date > $future_date) { | |
return do_shortcode('[gravityform id="'.$gravityform_id.'" title="'.$gravityform_title.'" description="'.$gravityform_desc.'" ajax="'.$gravityform_ajax.'"]'); | |
} | |
return $no_entry_message; | |
} | |
/** | |
* Register the shortcode | |
*/ | |
add_shortcode('pf_show_event_form', 'pf_show_event_form'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment