cliff
11/15/2017 - 3:01 AM

The Events Calendar: Block access to Events, Organizers, and Venues except to Administrators and the E/O/V's author. If user is logged out,

The Events Calendar: Block access to Events, Organizers, and Venues except to Administrators and the E/O/V's author. If user is logged out, redirect to wp-login.php.

<?php

/**
 * The Events Calendar: Block access to Events, Organizers, and Venues except
 * to Administrators and the E/O/V's author. If user is logged out, redirect
 * to wp-login.php.
 *
 * Note: May result in 404s, like if an Event links to a Venue page (only in
 * PRO) but the Venue author is not the same as the Event author.
 *
 * @link https://gist.github.com/cliffordp/f4a0e9d93c09860203929be21f3a31ff
 */
add_action( 'tribe_events_pre_get_posts', 'cliff_tec_hard_core_lockdown_to_own', 100 );
function cliff_tec_hard_core_lockdown_to_own( $query ) {
	// redirect to login page if not yet logged in
	if ( ! is_user_logged_in() ) {
		wp_redirect( esc_url_raw( wp_login_url() ) );
		exit;
	}

	// let admins see everything
	if ( current_user_can( 'create_users' ) ) {
		return;
	}

	// limit to the logged-in user's events
	$query->set( 'author', get_current_user_id() );
}