I was successfully able to disabled The Events Calendar plugin for users that are not logged in by using only filters (see below).
The dequeue_tec_scripts
function dequeues scripts loaded by the plugin.
The restricted_access_template
function, redirects the user to a custom template named ‘restricted_access.php’ or ‘404.php’ if the template file is not found.
I haven’t bothered trying to disable any other assets like css.
functions.php:
//
// Hide events from logged out users
//
add_filter('template_include', 'hide_events_for_logged_out_users', 99);
function hide_events_for_logged_out_users($template ) {
if (tribe_is_event_query() && (!is_user_logged_in() || !current_user_can('read_tribe_event'))) {
dequeue_tec_scripts();
return restricted_access_template();
}
return $template;
}
function dequeue_tec_scripts() {
wp_dequeue_script('tribe-events-calendar');
wp_dequeue_script('tribe-events-calendar-script');
wp_dequeue_script('tribe-events-bootstrap-datepicker');
wp_dequeue_script('tribe-events-admin');
wp_dequeue_script('tribe-events-settings');
wp_dequeue_script('tribe-events-ecp-plugins');
wp_dequeue_script('tribe-events-bar');
wp_dequeue_script('tribe-events-calendar');
wp_dequeue_script('tribe-events-list');
wp_dequeue_script('tribe-events-ajax-day');
wp_dequeue_script('tribe-mini-calendar');
wp_dequeue_script('tribe-events-pro-slimscroll');
wp_dequeue_script('tribe-events-pro-week');
wp_dequeue_script('tribe-events-pro-isotope');
wp_dequeue_script('tribe-events-pro-photo');
wp_dequeue_script('tribe-events-pro-geoloc');
wp_dequeue_script('tribe-meta-box');
wp_dequeue_script('tribe-jquery-ui');
wp_dequeue_script('tribe-jquery-ui');
wp_dequeue_script('tribe-timepicker');
wp_dequeue_script('tribe-fac');
wp_dequeue_script('tribe-events-pro');
}
function restricted_access_template() {
$template = locate_template(array('restricted_access.php'));
if ($template != '') {
return $template;
}
else {
global $wp_query;
$wp_query->set_404();
status_header(404);
return get_template_part(404);
}
}