Content Restriction Plugin 12

Testing a scheduled job to the content restriction framework.

Unrestricted posts

The only way I find to “walk backwards” and stick as much to development object at hand as possible is to start from the end and fill the code that’s needed.
The task at hand is to spot posts of any type that the Restricted Content framework plugin should restrict and apply to each of those the default restriction terms if any.
I’ve detailed, in an earlier post, how I’m requiring the tad-reschedule plugin using Composer to handle the cron and hook scheduling part of it.
That’s a code base I’ve tested and am not willing to replicate in functions in the plugin itself; that out of the way I need to define what actions to schedule and under what conditions.
I’ve added a class to the project that the main plugin class is taking care to instantiate and init and I’ve called it “Scheduler” because imagination rules my code:

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
        tad_reschedule( 'trc/core/unrestricted_posts/check' )
            ->each( 120 )
            ->until( array( trc_Core_PostDefaults::instance(), 'has_unrestricted_posts' ) );


What I’m scheduling is a cron job that should run each 2 minutes (WordPress cron allowing) until there are posts that have no restriction applied.
If that’s the case then the trc/core/unrestricted_posts/check hook will be called.

Post Defaults first tests

I’ve laid out the first test of the has_unrestricted_posts function and pushed it to GitHub. I’ve not covered all the possibilities there but it’s a good start to make sure the class works.


On with the tests and the schedule.