Content restriction plugin 04

The content restriction framework is shaping up.

Two pieces in place

While there is some helper code I’ve developed out of need that’s not covered by test the code for the two main plugin classes, the query restrictor and the template redirector, is in a working shape.
I’ve left filters all over the code when I got the impression it could be useful but am writing the code to allow my future self to extend the plugin using Object-Oriented techniques rather than filters to extend it.
I’ve extracted, and will keep extracting, methods to interfaces to make development easily move in that direction and allow for as much flexibility as possible.
Extensions will have some tasks to complete to benefit from the framework; while still in draft phase a small plugin extending it might work like this to add a simple restriction based on the user being logged in or not.

     * Plugin Name: Logged Users content restriction
     * Plugin URI:
     * Description: Restriction based on a user being logged-in or not.
     * Version: 1.0
     * Author: theAverageDev
     * Author URI:
     * License: GPL 2.0
    // Register the restriction taxonomy

    add_action('init', 'lr_register_logged_in_taxonomy');
    function lr_register_logged_in_taxonomy(){

        // the usual taxonomy registration...

        register_taxonomy('logged_in', array('post', 'page'), $args);
    // On activation add the taxonomy terms

    register_activation_hook(__FILE__, 'lr_activate')
    function lr_activate(){
        wp_insert_term('yes', 'logged_in');
        wp_insert_term('no', 'logged_in');
    // During loading register with the restriction framework

    add_action('plugins_loaded', 'lr_load');
    function ('lr_load') {
        // use the `logged_in` taxonomy to restrict posts

        // when asked for the user slugs use this class
        trc_Plugin::instance()->user->add_user_slug_provider('logged_in', new lr_LoggedInUser());

    // Define a class that will take care of providing the slugs for the user

    class lr_LoggedInUser implements trc_UserSlugProviderInterface {
        public function get_taxonomy_name(){
            return 'logged_in';

        public function get_user_slugs(){
            return is_user_logged_in() ? array('yes','no') : array('no');

This would be the flow for the current plugin state and I’m pretty satisfied with it; once the code is more stable and tested I will add examples to do the same using filters.