Skip to content

Instantly share code, notes, and snippets.

@ciaranmg
Last active August 29, 2015 13:57
Show Gist options
  • Save ciaranmg/9915292 to your computer and use it in GitHub Desktop.
Save ciaranmg/9915292 to your computer and use it in GitHub Desktop.
Check content access
<?php
/*
* You could work this into your template to check if a user has access to a page/post before showing a link to it.
* Or you could wrap this in a function and hook into a wordpress filter like the_title, or the_excerpt
*
*
* First check that the class exists
* This should allow your site to fail gracefully if the plugin is removed
*/
if(class_exists('agora_auth_container')){
// An auth container gets passed around to all the authentication methods until we know if the user can or can't see the content.
// The auth container needs to know the post ID to look at.
$auth_container = new agora_auth_container($post_id);
// The agora_middleware_check_permission filter fires up all the auth methods and passes the container to each one.
$auth_container = apply_filters( 'agora_middleware_check_permission', $auth_container);
// When we get the auth container back, we should know if the user can or can't see the content.
if($auth_container->is_allowed()){
// Do stuff... show the content.
}else{
//Don't do stuff...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment