Home › Forums › Calendar Products › Events Calendar PRO › Requiring Admin Login to View Default Events Calendar
- This topic has 3 replies, 2 voices, and was last updated 9 years ago by Matthew.
-
AuthorPosts
-
April 2, 2015 at 12:18 am #952709Eric ReynoldsParticipant
How can I require a user to have admin status to view the default calendar at http://mydomain.com/events/? I am already using the The Events Calendar: Private Category plugin to privatize event categories. I just need to do the same for the events calendar.
Thanks in advance,
🙂 Eric
April 2, 2015 at 7:20 am #952764MatthewMemberHowdy Eric – excellent question!
I liked this question because I had to dig a little to find an answer!  While the solution that I have for you is technical, I think it might be useful 🙂 The list/day/month pages all output their content with a function called tribe_get_template_part() like so:
- tribe_get_template_part( ‘list/content’ )
- tribe_get_template_part( ‘day/content’ )
- tribe_get_template_part( ‘month/content’ )
For more information on where those lines can be found, you can check out our Themer’s Guide.  Well, those function calls output the events on the list/day/month pages respectively.  We have a super handy hook that allows you to change what is output! This is great news because you can change it to an “I’m sorry, you don’t have access.” message or something if the user isn’t an administrator 🙂  Here’s an example of how to do that for all of those views:
function my_event_content_access_restriction( $html, $template, $file, $slug, $name ) { $slugs_to_filter = array( 'list/content', 'day/content', 'month/content', ); if ( ! in_array( $slug, $slugs_to_filter ) ) { return $html; } if ( current_user_can( 'manage_options' ) ) { return $html; } return "<div>I'm sorry, you don't have access to view these events!</div>"; } add_filter( 'tribe_get_template_part_content', 'my_event_content_access_restriction', 10, 5 );
You would drop that right in your theme’s functions.php file. Here’s some helpful info about this solution:
- WordPress documentation on functions.php
- PHP documentation on in_array
- WordPress documentation on current_user_can
Let me know how it goes! 🙂
April 2, 2015 at 10:38 am #952854Eric ReynoldsParticipantThank you Matthew for digging. Your solution works like a charm! 🙂 Eric
April 2, 2015 at 1:03 pm #952905MatthewMemberWoo hoo! Glad to hear that the solution worked for you! I’ll go ahead and close out this ticket for you. If you come up with any more questions, feel free to post a new topic on the forums!
-
AuthorPosts
- The topic ‘Requiring Admin Login to View Default Events Calendar’ is closed to new replies.