Skip to content

Instantly share code, notes, and snippets.

@caseydriscoll
Created August 8, 2014 15:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caseydriscoll/8b4811d9010dd8d45a8f to your computer and use it in GitHub Desktop.
Save caseydriscoll/8b4811d9010dd8d45a8f to your computer and use it in GitHub Desktop.
Tribe: On Community Events Submission, redirect on update, change message on error
function ce_custom_error_msg( $errors ) {
// Don't filter if it is an 'update' or other type of message
if ( $errors[0]['type'] != 'error' ) return $errors;
$existing_errors = '';
$type = 'error';
if ( is_array( $errors ) ) {
$existing_errors = $errors[0]['message'];
$type = $errors[0]['type'];
}
// Set overall message by appending a heading to the front
$errors[0] = array(
'type' => $type,
'message' => '<h5>You did not do something critical</h5>' . $existing_errors
);
// User str_replace to choose a specific message to change
$errors[0]['message'] = str_replace( 'Event Title is required', 'You need to add a title', $errors[0]['message'] );
return $errors;
}
add_filter( 'tribe_community_events_form_errors', 'ce_redirect_after_submit', 10, 1 );
function ce_redirect_after_submit( $messages ) {
if ( is_array( $messages ) && !empty( $messages ) ) {
$messages = ce_custom_error_msg( $messages );
$first_message = reset( $messages );
if ( $first_message['type'] == 'update' ) {
add_action( 'parse_request', 'tribe_redirect_after_community_submission', 11, 1 );
}
}
return $messages;
}
function tribe_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() ); // Edit home_url() to whatever you page want
exit();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment