Requiring Admin Login to View Default Events Calendar

Home Forums Calendar Products Events Calendar PRO Requiring Admin Login to View Default Events Calendar

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #952709
    Eric Reynolds
    Participant

    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

    #952764
    Matthew
    Member

    Howdy 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:

    Let me know how it goes! 🙂

    #952854
    Eric Reynolds
    Participant

    Thank you Matthew for digging. Your solution works like a charm! 🙂 Eric

    #952905
    Matthew
    Member

    Woo 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!

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘Requiring Admin Login to View Default Events Calendar’ is closed to new replies.