Our Community Events add-on for The Events Calendar adds a form for users to submit events to your WordPress calendar.
By default, submitted events are saved as drafts until they are published by an administrator. What this snippet does is notify the person who submitted the event once the event is published.
Usage
First off, this snippet requires an intermediate level of programming knowledge and access to your server.
Start by creating a new PHP file called events-community-notify-submitter.php
on your server at wp-content/plugins/
where WordPress is installed.
Paste the snippet into that file and save it:
<?php
/*
Plugin Name: Tribe Snippet: Send email notification when the event is approved
Requires PHP: 5.6
Version: 0.1
*/
add_action( 'transition_post_status', function ( $new_status, $old_status, $post ) {
// Early bail: We are looking for published posts only
if ( $new_status != 'publish' ) {
return;
}
// Early bail: Unexpected value
if ( ! $post instanceof WP_Post ) {
return;
}
// Early bail: We need the "tribe" function to be loaded
if ( ! function_exists( 'tribe' ) ) {
return;
}
$main = tribe( 'community.main' );
// Early bail: We could not get the desired class from the Container
if ( ! $main instanceof Tribe__Events__Community__Main ) {
return;
}
$default_status = $main->getOption( 'defaultStatus' );
// Early bail: Old status is not the default status
if ( $old_status != $default_status ) {
return;
}
// Early bail: We are just interested in Events
if ( $post->post_type != 'tribe_events' ) {
return;
}
$author = get_user_by( 'id', $post->post_author );
// Early bail: Author not available (eg: Anonymous submission)
if ( ! $author instanceof WP_User ) {
return;
}
$email = $author->user_email;
// Early bail: Invalid email
if ( ! filter_var( $email, FILTER_VALIDATE_EMAIL ) ) {
return;
}
$subject = sprintf( 'Congratulations! %s was published!', $post->post_title );
$message = sprintf( 'Congratulations, your event was published! Click <a href="%s">here</a> to view it!', esc_url( get_post_permalink( $post ) ) );
wp_mail(
$email,
esc_html__( $subject, 'tribe-events-community' ),
__( wp_kses_post_deep( $message ), 'tribe-events-community' ),
[ 'Content-Type: text/html; charset=UTF-8' ]
);
}, 10, 3 );
Next, go to your WordPress dashboard and activate the plugin. It will be called “Tribe Snippet: Send email notification when the event is approved” in the list of plugins.
That’s all there is to it! Now someone who has submitted an event to The Events Calendar will receive an email once their post has been published to the calendar.
Frequently asked questions
Edit line 57 of the snippet.
Edit line 58 of the snippet.
No. If you have the “Allow anonymous submissions” option checked (Events → Settings → Community), and a user submits an event without being logged into the site, then the snippet is unable to identify an email for that user and will not send a notification.
No. If the option “Default status for submitted events” (Events → Settings → Community) is set to “Published” then this snipped will not send any emails.