Skip to content

Instantly share code, notes, and snippets.

@jbrinley
Created September 25, 2013 01:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbrinley/6693934 to your computer and use it in GitHub Desktop.
Save jbrinley/6693934 to your computer and use it in GitHub Desktop.
Redirect a user after a successful community events submission.
<?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