Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to set up a wordpress site using active directory authentication. One question that has come up is the ability to limit category/post/blog reading to specific AD groups.

I've never seen this done and I haven't been able to find any plugins that seem to promise this functionality. It would seem that the best option is to just give a bunch of users a role with the read_private_posts capability, but I'm not sure this will do the trick.

share|improve this question
1  
Interesting: is it possible to restrict certain categories to specific groups of users? Regardless of the AD issue: can you do more than just password-protect a post? –  Jan Fabry Dec 29 '10 at 7:58
add comment

migrated from superuser.com Dec 28 '10 at 22:57

This question came from our site for computer enthusiasts and power users.

2 Answers

I think this should definitely be doable. I think I would first try to get one of the LDAP authentication plugins -- like Simple LDAP Login or LDAP Login Password and Role Manager -- working, and then write a small custom plugin to handle the content authorization.

Here's a rough outline of the custom plugin's main logic:

function checkContentAuthorization( $content )
{
    $authorization = array(
        'ldap group 1' => array(
            'authorizesCategories'  = array( 1, 14, 83 ),
            'authorizedPosts'       = array( 53, 48, 23, 432 )
        ),
        'ldap group 2' => array(
            'authorizesCategories'  = array( 54, 9, 34 ),
            'authorizedPosts'       = array( 48, 13, 29, 93 )
        ),
    )

    if( is_category() )
    {
        if( !in_array( $currentCategoryID, $authorization[ currentLDAPUser->groupName ][ 'authorizedCategories' ] )
            $content = 'Access denied';
    }
    elseif( is_single() )
    {
        if( !in_array( $currentPostID, $authorization[ currentLDAPUser->groupName ][ 'authorizedPosts' ] )
            $content = 'Access denied';
    }

    return $content;
}
add_filter( 'the_content', 'checkContentAuthorization' );

Obviously that's a stripped down version and there's a lot of details to fill in, but actually writing the plugin itself would take at least half a day. That should get you pointed in the right direction, though.

share|improve this answer
add comment

The Role System in Wordpress is somehow limited, so don't expect it to do the job. Especially not while you're combining it with some other structure of account information that might be organized orthogonally against core WP data-structures.

I would start with the authentication part first and when sign-on is working to see what and where to limit content access (as long as this is for reading only as you asked for it).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.