Password Protecting the Calendar

Home Forums Ticket Products Event Tickets Plus Password Protecting the Calendar

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #957989
    kirstyburgoine
    Participant

    Hi,
    I’m using this on a multisite install where the theme gives you the option to protect all of the content on the site or not by using the advanced custom fields plugin from Elliot Condon. It is as simple as if this site should be private a radio button is selected and then in my theme all content is hidden if it is selected. This works perfectly for everything except for the events calendar which always displays no matter what.

    I thought maybe it was just a case of not modifying the right template, but nothing seems to work. I’ve even tried selecting my own templates from within the events settings and the calendar still displays even when it shouldn’t. IS this not possible or am I missing something.

    Here is the calendar working: http://telford-webdesign.co.uk/events/
    Here is a different site where it should not display because you are not logged in: http://richmond.telford-webdesign.co.uk/events/

    (This domain is my staging area for myechef.co.uk – which is registered – and once this works will be pushed to that domian)

    I have this set up to use the default events template, which I copied from /plugins/the-events-calendar/views/default-template.php and copied to /themes/my-theme/tribe-events/views/default-template.php

    My code is:

    <?php
    /**
    * Default Events Template
    * This file is the basic wrapper template for all the views if ‘Default Events Template’
    * is selected in Events -> Settings -> Template -> Events Template.
    *
    * Override this template in your own theme by creating a file at [your-theme]/tribe-events/default-template.php
    *
    * @package TribeEventsCalendar
    *
    */

    // Get the value of the radio button
    $protected = get_field(‘protected’, ‘option’);
    // Make sure we know the blog ID to stop users from other sub domains accessing
    global $blog_id;

    if ( ! defined( ‘ABSPATH’ ) ) {
    die( ‘-1’ );
    }

    get_header(); ?>

    <div id=”tribe-events-pg-template”>

    <?php tribe_events_before_html(); ?>

    <?php
    //————————————————————————————————
    //————————————————————————————————
    // Check to see if this should be protected first
    // echo “test ” . $protected;

    if ( $protected == ‘Yes’) :
    //————————————————————————————————
    //————————————————————————————————
    // If so, check if someone is logged in and they have permissions for this blog
    if ( is_user_logged_in() && current_user_can_for_blog( $blog_id, “read” ) ) :

    ?>

    <?php tribe_get_view(); ?>

    <?php
    //————————————————————————————————
    //————————————————————————————————
    // If not logged in show error text from Options page in admin
    else : ?>

    <div class=”grid__item palm-one-whole lap-one-whole”>
    <?php
    $not_logged_in = get_field(‘not_logged_in’, ‘option’);
    echo $not_logged_in;
    ?>
    </div>

    <?php
    endif;
    // Ends if logged in and you have permission
    //————————————————————————————————
    //————————————————————————————————

    //————————————————————————————————
    //————————————————————————————————
    // Else the site is not protected so just show the standard content
    else : ?>

    <?php tribe_get_view(); ?>

    <?php
    endif;
    // Ends if the site should be protected or not
    //————————————————————————————————
    //————————————————————————————————
    ?>

    <?php tribe_events_after_html(); ?>

    </div> <!– #tribe-events-pg-template –>

    <?php get_footer(); ?>

    I have also tried adding this if logged in code to /themes/my-theme/tribe-events/views/month.php as well, but that didn’t work either. I know the code to check for the custom field is working because its been copied and pasted from other templates in my theme which do work as excpected.

    Can you help? I’m at a loss as to why this always displays. I must still have the wrong template surely?

    Thanks

    Kirsty

    #958228
    Brook
    Participant

    Howdy Kristy,

    I am happy you reached out. Thanks for sharing your code. I think gives enough of a background for me to identify the likely cause.

    The variable, $protected, appears to be checking an individual post to see if has the protected post_meta set. However, in WP Archive views, such as tag or cateogyr page, or our very own events page, you are not seeing a single post. Rather, a list of many posts is loaded for display. In such a scenario it seems like that your $protected logic is not being set, because an individual post is not present.

    I can not say for sure without seeing all of your code. In fairness though full code critiques are well outside of our scope of support. However, I think I can get you pointed in the right direction. I wrote a snippet a while back that does nearly exactly what you want. This snippet hides events from selectable user roles. In that example it checks if the user is an administrator via current_user_can(), and if they are not an administrator then it specifically excludes a certain category of events with the slug “exclude-slug” from front-end queries. Thus, some minor modifications could make it function similarly to your code. Instead of hiding events from a certain category, you could hide them based on whether or not protected is set in the database.

    Does that snippet I shared help? Does it give you a better idea of how to exclude select posts including events from a WP Archive page’s WP_Query? Please let me know.

    Cheers!

    – Brook

    #958358
    kirstyburgoine
    Participant

    Hi Brook,

    Thanks so much for coming back to me, I really appreciate it. I’m not sure thats quite what I’m after though.

    The variable $protected is a site option and not saved within an individual post or pages meta_data and does work on all archive pages as well. This particular approach should mean that I don’t have to amend $WP_Query at all and really is as simple as… “If this is yes show the content if no, don’t”.

    The code I included is the same on every template within my theme, which I included just so you could see my approach (Totally understand about code reviews and wasn’t expecting that level of help 🙂 ) and does work everywhere else which is why I thought maybe I’ve edited the wrong template files for the calendar?

    #958361
    kirstyburgoine
    Participant

    As an additional update…

    I have the settings for the events calendar set to use the default events template and the file I am editing is: /themes/my-theme/tribe-events/views/default-template.php

    I have also tried adding this to the top of the page:
    echo “default = ” . $protected;

    Which, if nothing else should print the word “default” to the screen at the very top of the page even if there is a problem with my variable, but it doesn’t. So it must be something to do with editing the wrong template? If thats the case, which is the right one?

    Thanks

    Kirsty

    #958641
    Brook
    Participant

    That makes more sense. I just looked up the ACF API and that helped clarify how your code is behaving.

    That template only shows when it is selected in Events -> Settings -> Template -> Events Template. If you go to your WP Admin and then visit that page, which template is selected? If it’s anything other than Default Events Template, this logic will not be loaded.

    Does that make sense? Is that the issue?

    – Brook

    #958825
    kirstyburgoine
    Participant

    Hi Brook,

    The theme is using the default events template, so as far as I can tell it should be working. It is set to show Month view though so maybe I’m editing the wrong template or saving it in the wrong place in my theme?

    I am editing: /themes/my-theme/tribe-events/views/default-template.php I have also tried editing: /themes/my-theme/tribe-events/views/month.php which hasn’t worked either.

    Here is a screen grab of my settings for the template usage: http://cl.ly/image/3p073D1V2q0p?_ga=1.94628188.1709651499.1430211226

    #958913
    Brook
    Participant

    Thanks for double checking Kristy. 🙂

    I am glad you mentioned the location of those files again. That appears to be the culprit. The current location of your override is:

    /themes/my-theme/tribe-events/views/default-template.php

    But it should be:

    /themes/my-theme/tribe-events/default-template.php

    The views are the only thing you can override, so you do not need to include the views folder in your theme structure.

    Did that work? Thanks!

    – Brook

    #959038
    kirstyburgoine
    Participant

    Yes, that fixed it! Thank you so much!

    For some reason I had misread the themer’s guide and got the path wrong and didn’t notice. Thank you for all of your help 🙂

    #959046
    Brook
    Participant

    You are super welcome. I wished I would have noticed sooner. Thanks for bearing with me!

    – Brook

Viewing 9 posts - 1 through 9 (of 9 total)
  • The topic ‘Password Protecting the Calendar’ is closed to new replies.