Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Class CustomPage_Frontend
- */
- class CustomPage_Frontend {
- private static $instance = null;
- public $path = 'custompage';
- /**
- * Just to be able to call it statically.
- */
- public static function init()
- {
- if (null == self::$instance) {
- self::$instance = new self;
- }
- return self::$instance;
- }
- /**
- * Boot this thing up
- */
- public function __construct()
- {
- add_action('init', array($this, 'rewrite_rules'));
- add_action('template_redirect', array($this, 'template_redirect'));
- add_filter( 'query_vars', array($this, 'query_vars'));
- }
- /**
- * Rewrites
- * @return Void
- */
- public function rewrite_rules()
- {
- add_rewrite_rule(
- '^'.$this->path.'/?$',
- 'index.php?'.$this->path.'=yes',
- 'top'
- );
- }
- /**
- * Query vars
- * @param Array $vars
- * @return Void
- */
- public function query_vars( $vars )
- {
- $vars[] = $this->path;
- return $vars;
- }
- /**
- * Templates redirects
- * @return Void
- */
- public function template_redirect()
- {
- if (get_query_var($this->path) == 'yes') {
- add_filter( 'template_include', function() {
- get_template_part('templates/custom-page');
- });
- }
- }
- }
- CustomPage_Frontend::init();
Add Comment
Please, Sign In to add comment