Front end content access functions

written by: Jeff McNear

this is a follow up to this article

Besides the simple check for validation (login) status discussed before

<?php
if ( is_user_logged_in() ) { ?>
   you are logged in
<?php } else { ?>
   get out you don't belong
<?php }?>

More specific filters can be applied by what the user capabilities are attached to the login, so this block of code would filter for an admin level user

<?php
if ( current_user_can( 'activate_plugins' ) ): // check for a capability that only admins have ?>

          <p>Howdy, Administrator!</p>

<?php endif; // end of user capability check ?>

where the parameter within the parenthesis can be any of these parameters.

The user level also can be inserted as a parameter – as tin these examples:

if( current_user_can( 'administrator' ) )
if( current_user_can( 'editor' ) )
if( current_user_can( 'author' ) )
if( current_user_can( 'contributor' ) )
if( current_user_can( 'subscriber' ) )

IMPORTANT SIDE NOTE: If custom capabilities are desired for a custom post type then they must be specified when the post type is created – otherwise the CPT will use the “post” capabilities in a generic way. Like this:

	$capabilities = array(
		'edit_post'             => 'edit_post_special',
		'read_post'             => 'read_post_special',
		'delete_post'           => 'delete_post_special',
		'edit_posts'            => 'edit_posts_special',
		'edit_others_posts'     => 'edit_others_posts_special',
		'publish_posts'         => 'publish_posts_special',
		'read_private_posts'    => 'read_private_posts_special',
	);