Created
September 25, 2013 01:32
-
-
Save jbrinley/6693934 to your computer and use it in GitHub Desktop.
Redirect a user after a successful community events submission.
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 | |
/** | |
* This actually does the redirect. If an event was submitted, and we're about | |
* to reload the submission page (with a message instead of a form), this will | |
* redirect to the home page. | |
* | |
* @param WP $wp | |
* @return void | |
*/ | |
function tribe_gist_redirect_after_community_submission( $wp ) { | |
if ( isset($wp->query_vars[WP_Router::QUERY_VAR]) && $wp->query_vars[WP_Router::QUERY_VAR] == 'ce-add-route' && !empty($_POST) ) { | |
wp_safe_redirect(home_url()); // you can change this URL to whatever you want | |
exit(); | |
} | |
} | |
/** | |
* This is where we check that an event was submitted or updated. It's a filter, | |
* not an action, so make sure to pass through the argument. | |
* | |
* @param array $messages | |
* @return array | |
*/ | |
function tribe_gist_check_for_community_submission( $messages ) { | |
if ( is_array($messages) && !empty($messages) ) { | |
$first_message = reset($messages); | |
if ( $first_message['type'] == 'updated' ) { | |
add_action( 'parse_request', 'tribe_gist_redirect_after_community_submission', 11, 1 ); | |
} | |
} | |
return $messages; | |
} | |
add_filter( 'tribe_community_events_form_errors', 'tribe_gist_check_for_community_submission', 10, 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This now exists: https://theeventscalendar.com/knowledgebase/redirect-to-different-url-after-event-submission/