1

I have just installed The Events Calendar Pro.

I am currently using the following custom template to hide any plugin related content and display a message and login link instead:

<?php if (current_user_can('read_tribe_event')): ?>
  <div id="tribe-events-pg-template">
    <?php tribe_events_before_html(); ?>
    <?php tribe_get_view(); ?>
    <?php tribe_events_after_html(); ?>
  </div> <!-- #tribe-events-pg-template -->

<?php else: ?>
  <?php echo get_template_part('restricted_access'); ?>
<?php endif; ?>

<?php get_footer(); ?>

What I am finding is that the javascript for the plugin is still being loaded and is throwing a exception, presumably because the content it expects to find is not there any more. This is stopping the javascript of another plugin from working.

I am now thinking that there may be some hook I can use to prevent The Events Calendar plugin from loading any of its content and load my content instead.

Does anyone know of the correct way to do this or have any other ideas?

3
  • 1
    Check the plugin code and find how scripts and stylesheets are included. If it is included using wp_enqueue_script then it can dequeued from theme. Check this function wp_dequeue_script – Nilambar Sharma Jun 18 '14 at 6:39
  • @Nilambar, thanks for the hint. What hook do I use to dequeue the script? – br3nt Jun 18 '14 at 7:00
  • Try wp_enqueue_scripts. If it does not work with default priority, try with higher number of priority value. – Nilambar Sharma Jun 18 '14 at 7:06
2

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);
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.