User Groups Content Restriction 02

Initial commit of the User Groups based content restriction plugin.

Getting a user groups

Since I’ve decided to implement an extension of the theAverageDev Restricted Content plugin framework to handle content access on a user group level I’ve picked the User Groups plugin as my “user group server” and have dug into its code to come up with a coding plan.
In terms of functionalities I’ve laid them out in an earlier post and will not go over them again.
The plugin relates users to groups in the simplest and “wordpressiest” way: using a taxonomy.

function register_user_taxonomy() {

            'public' => false,
            'labels' => array(
            'rewrite' => false,
            'capabilities' => array(
                'manage_terms' => 'edit_users', // Using 'edit_users' cap to keep this simple.
                'edit_terms'   => 'edit_users',
                'delete_terms' => 'edit_users',
                'assign_terms' => 'read',
            'update_count_callback' => array(&$this, 'update_user_group_count') // Use a custom function to update the count. If not working, use _update_post_term_count

The codex does not list the possibility to register taxonomies for users but it is indeed supported and working to this day.

Getting access enabled groups for a post

The framework acts like a pipe connecting a “user term slugs provider” to a “post term slugs provider” and intersecting them: if at least one term comes up than the user can access the post in regards to that access restriction taxonomy.
In this case the taxonomy that will be used to restrict the posts is the one the plugin is using to add the users to a group so it’ only a matter of UI and of a little TDD to test the failure prone parts of the plugin.

Draft code

I’ve pushed an initial commit for the code to GitHub and will move into testing the “moving parts” next: the user slug provider and the post slug provider.
The plugin now activates and de-activates properly but really does little else.

I appreciate your input