Content Restriction Plugin 14

Time to apply some default restrictions to unrestricted posts.

Finding unrestricted posts

I’ve completed a satisfying development of the class methods that are supposed to help me find any post that’s not restricted according to the existing restricting taxonomies.
The code is being used in a re-scheduling loop in the Restricted Content framework plugin:

class trc_Core_Scheduler {

    /**
     * @var static
     */
    protected static $instance;

    /**
     * @return trc_Core_Scheduler
     */
    public static function instance() {
        if ( empty( self::$instance ) ) {
            self::$instance = new self();
        }

        return self::$instance;
    }

    public function schedule() {
        // each 2' apply the default restrictions to some unrestricted posts
        $post_defaults = trc_Core_PostDefaults::instance();
        tad_reschedule( 'trc/core/unrestricted_posts/check' )
            ->each( 120 )
            ->until( array( $post_defaults, 'has_unrestricted_posts' ) )
            ->with_args( $post_defaults->get_unrestricted_posts() );
    }

}

the tested code for it on GitHub.
It’s time to use that information.

Applying a default restriction

I will take the same approach that brought me the code above and start from the end.
Now that I’m scheduling an action, trc/core/unrestricted_posts/check, that’s happening each two minutes until there are unrestricted posts, I need to hook into that action to restrict the posts.
The main plugin file is, upon loading, creating and initializing an instance of the trc_Core_PostRestrictions class which is hooking to the action above to run the method in charge of applying the default restriction terms to each unrestricted post.

class trc_Core_PostRestrictions {

    /**
     * @var static
     */
    protected static $instance;

    public static function instance() {
        if ( empty( self::$instance ) ) {
            self:
            $instance = new self();
        }

        return self::$instance;
    }

    public function init() {
        add_action( 'trc/core/unrestricted_posts/check', array( $this, 'apply_default_restrictions' ) );
    }

    public function apply_default_restrictions( array $unrestricted_posts = array() ) {
        // TDD me
    }
}

I know the input or this latter method, a list of post IDs by taxonomy, and will start from that to develop its functions.

I appreciate your input