factor out partials code to comicpress
This commit is contained in:
parent
7b1e8b7348
commit
90c7a23747
@ -548,6 +548,23 @@ class ComicPress {
|
|||||||
|
|
||||||
return $sorted_categories;
|
return $sorted_categories;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function _is_dir($dir) { return is_dir($dir); }
|
||||||
|
|
||||||
|
function setup_multicomic_partial_paths($post_id) {
|
||||||
|
$this->partial_paths = array();
|
||||||
|
$category_ids = wp_get_post_categories($post_id);
|
||||||
|
if (is_array($category_ids)) {
|
||||||
|
foreach ($category_ids as $id) {
|
||||||
|
$category = get_category($id);
|
||||||
|
if (!empty($category)) {
|
||||||
|
if ($this->_is_dir($target = get_template_directory() . '/subthemes/' . $category->slug)) {
|
||||||
|
$this->partial_paths[] = $target;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
@ -64,18 +64,8 @@ function comicpress_init() {
|
|||||||
global $post, $comicpress;
|
global $post, $comicpress;
|
||||||
|
|
||||||
if (!empty($post)) {
|
if (!empty($post)) {
|
||||||
if (in_comic_category() && $comicpress->is_multicomic()) {
|
if (in_comic_category() && $comicpress->is_multicomic() && !is_index()) {
|
||||||
$category_ids = wp_get_post_categories($post->ID);
|
$comicpress->setup_multicomic_partial_paths($post->ID);
|
||||||
if (is_array($category_ids)) {
|
|
||||||
foreach ($category_ids as $id) {
|
|
||||||
$category = get_category($id);
|
|
||||||
if (!empty($category)) {
|
|
||||||
if (is_dir($target = get_template_directory() . '/subthemes/' . $category->slug)) {
|
|
||||||
$comicpress->partial_paths[] = $target;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -407,6 +407,22 @@ FILE
|
|||||||
|
|
||||||
$this->assertEquals($expected_sort_order, $this->cp->get_sorted_post_categories((object)array('ID' => 1)));
|
$this->assertEquals($expected_sort_order, $this->cp->get_sorted_post_categories((object)array('ID' => 1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testSetupMulticomicPartialPaths() {
|
||||||
|
$cp = $this->getMock('ComicPress', array('_is_dir'));
|
||||||
|
|
||||||
|
wp_set_post_categories(1, array('2', '3'));
|
||||||
|
|
||||||
|
add_category('2', (object)array('slug' => 'test-one'));
|
||||||
|
add_category('3', (object)array('slug' => 'test-two'));
|
||||||
|
|
||||||
|
$cp->expects($this->at(0))->method('_is_dir')->with('/subthemes/test-one')->will($this->returnValue(true));
|
||||||
|
$cp->expects($this->at(1))->method('_is_dir')->with('/subthemes/test-two')->will($this->returnValue(false));
|
||||||
|
|
||||||
|
$cp->setup_multicomic_partial_paths(1);
|
||||||
|
|
||||||
|
$this->assertEquals(array('/subthemes/test-one'), $cp->partial_paths);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
Loading…
Reference in New Issue
Block a user