Conditional Frontmatter Filtering

I am looking for a little assistance with a plugin. I have a page with a frontmatter property of ‘private_content’ and its set to true. I am trying to write a plugin that when a page is rendered, if private_content is set and if it is set to true, return the 404 page.

Code is as follows:

    <?php
      namespace Grav\Plugin;
use \Grav\Common\Plugin;
class ExamplePlugin extends Plugin
{
    public static function getSubscribedEvents()
    {
        return [
            'onPluginsInitialized' => ['onPluginsInitialized', 0]
        ];
    }
    public function onPluginsInitialized($e)
    {
      $this->enable([
          'onPageInitialized' => ['onPageInitialized', 0]
      ]);
    }
    public function onPageInitialized()
    {
        $page = $this->grav['page'];
        $header = $page->header();
        if( isset($header->private_content) && $header->private_content === true ){
          $this->grav['page']->header()->http_response_code = 404;
          $this->grav->fireEvent('onPageNotFound');          
        }
    }
}

@pickettj, Would you mind sharing what the issue is you are trying to solve?

It sounds like this should be solved with the build-in authorisation settings.

It is an authorization type of thing, but I am not planning on using the built in login plugin. I am also not looking to create 30K+ user yaml files to control access to content.