diff --git a/WP_Route.class.php b/WP_Route.class.php index 0ca28f6..b83e1b5 100644 --- a/WP_Route.class.php +++ b/WP_Route.class.php @@ -19,6 +19,7 @@ class WP_Route extends WP_Router_Utility { protected $access_arguments = array(); protected $template = array(); protected $properties = array(); + protected $body_class = ''; /** * @throws Exception @@ -116,7 +117,7 @@ public function execute( WP $query ) { $title = $this->get_title($query); - $page = new WP_Router_Page($page_contents, $title, $template); + $page = new WP_Router_Page($page_contents, $title, $template, $this->body_class); } /** diff --git a/WP_Router_Page.class.php b/WP_Router_Page.class.php index 732fb66..e7fb735 100644 --- a/WP_Router_Page.class.php +++ b/WP_Router_Page.class.php @@ -9,6 +9,7 @@ class WP_Router_Page extends WP_Router_Utility { protected $contents = ''; protected $title = ''; protected $template = ''; + protected $body_class = ''; protected $meta = array(); public static function init() { @@ -82,10 +83,11 @@ private static function make_post() { return $id; } - public function __construct( $contents, $title, $template = '' ) { + public function __construct( $contents, $title, $template = '', $body_class = '' ) { $this->contents = $contents; $this->title = $title; $this->template = $template; + $this->body_class = $body_class; $this->add_hooks(); } @@ -97,6 +99,7 @@ protected function add_hooks() { add_filter('redirect_canonical', array($this, 'override_redirect'), 10, 2); add_filter('get_post_metadata', array($this, 'set_post_meta'), 10, 4); add_filter('post_type_link', array($this, 'override_permalink'), 10, 4); + add_filter('body_class', array($this, 'set_body_class'), 10, 1); if ( $this->template ) { add_filter('template_include', array($this, 'override_template'), 10, 1); } @@ -235,4 +238,9 @@ public function override_permalink( $post_link, $post, $leavename, $sample ) { } return $post_link; } + + public function set_body_class( $classes ) { + $classes[] = $this->body_class; + return $classes; + } }