Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion WP_Route.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}

/**
Expand Down
10 changes: 9 additions & 1 deletion WP_Router_Page.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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();
}

Expand All @@ -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);
}
Expand Down Expand Up @@ -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;
}
}