Created
April 30, 2018 17:02
-
-
Save joshfeck/02b6d1156f83ac27b7f489edf4580125 to your computer and use it in GitHub Desktop.
Adds a JavaScript redirect to the home page when the event is expired. Event Espresso 4
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 | |
//* Please do NOT include the opening php tag, except of course if you're starting with a blank file | |
function ee_add_redirect_expired_events() { | |
if ('espresso_events' == get_post_type() && is_single() ){ | |
$id = get_the_id(); | |
$event = EEH_Event_View::get_event( $id ); | |
if( $event instanceof EE_Event ) { | |
$where_params_for_event = array(array('EVT_ID' => $event->ID())); | |
if (EEM_Datetime::instance()->get_datetime_count_for_status(EE_Datetime::upcoming, $where_params_for_event) == 0 && | |
EEM_Datetime::instance()->get_datetime_count_for_status(EE_Datetime::expired, $where_params_for_event) > 0 | |
) { | |
?> | |
<script> | |
window.location.replace("<?php echo esc_url(home_url()); ?>"); | |
</script> | |
<?php | |
} | |
} | |
} | |
} | |
add_action( 'wp_print_footer_scripts', 'ee_add_redirect_expired_events', 20 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment