Auto-Publish Events Submitted By Logged-In Users

In the Community Events settings, you can control the status of events that are submitted via the Add Event form. But perhaps you’d like a little more control over that.

The snippet below will auto-publish any event submitted by a registered, logged in user. Any other submitted events (i.e., those submitted by anonymous users) will go to whatever your default status is set to (e.g. Draft or Pending Review).

To add this auto-publishing feature, copy the snippet below into your theme’s functions.php file.

<?php
/**
 * Community Events (CE): If user is logged in, set post status to Published, else fallback to CE settings' default.
 *
 * Irrelevant if default post status in CE settings is Published or Anonymous Submissions are not allowed.
 *
 * @link https://support.theeventscalendar.com/420384-Auto-publish-events-submitted-by-logged-in-users Relevant help article.
 * @link https://gist.github.com/cliffordp/9b4dff692829ce5d9ddd46d849689dbb This snippet.
 *
 * @param mixed $option The option value.
 * @param mixed $default The fallback value.
 * @param mixed $optionName The name of the option.
 *
 * @return mixed
 */
function set_community_events_publication_status( $option, $default, $optionName ) {
	if (
	! class_exists( 'Tribe__Events__Community__Main' )
	|| 'defaultStatus' !== $optionName
	|| ! is_user_logged_in()
	) {
		return $option;
	}

	return 'publish';
}

add_filter( 'tribe_get_single_option', 'set_community_events_publication_status', 10, 3 );

Details

Report an issue