diff --git a/functions.php b/functions.php index d6a2f95..e4eb916 100644 --- a/functions.php +++ b/functions.php @@ -2,6 +2,7 @@ // load all of the comic & non-comic category information add_action('init', '__comicpress_init'); +add_action('template_redirect', '__comicpress_template_redirect', 100); function __comicpress_init() { global $comicpress, $wp_query; @@ -34,6 +35,10 @@ function __comicpress_init() { $comicpress_filters->init(); } +function __comicpress_template_redirect() { + ob_start(); +} + function F($name, $path, $override_post = null) { global $post; @@ -146,12 +151,13 @@ function RT($which, $restrictions = null, $override_post = null) { } function M($override_post = null) { - global $post, $__attachments, $__ordering; + global $post, $__attachments; $post_to_use = !is_null($override_post) ? $override_post : $post; $comic_post = new ComicPressComicPost($post_to_use); - $__attachments = $comic_post->get_attachments(); - $__ordering = $comic_post->normalize_ordering(); + $__attachments = $comic_post->get_attachments_with_children(true); + + return $__attachments; } /** @@ -196,6 +202,3 @@ function comicpress_list_storyline_categories($args = "") { if ($style == "list") { $output .= ""; } echo $output; } - -ob_start(); -?> diff --git a/test/FunctionsTest.php b/test/FunctionsTest.php new file mode 100644 index 0000000..358746a --- /dev/null +++ b/test/FunctionsTest.php @@ -0,0 +1,43 @@ + 2)) + ); + } + + /** + * @dataProvider providerTestM + */ + function testM($post_to_use) { + global $post, $__attachments; + + $post = (object)array('ID' => 1); + + $backend = $this->getMock('ComicPressFakeBackend', array('generate_from_post')); + + $post_to_test = (!is_null($post_to_use)) ? $post_to_use : $post; + + $backend->expects($this->once())->method('generate_from_post')->with($post_to_test)->will($this->returnValue(array('test-1', 'test-2', 'test-3'))); + $comicpress = ComicPress::get_instance(); + $comicpress->backends = array($backend); + + update_post_meta($post_to_test->ID, 'image-ordering', array( + 'test-1' => array('enabled' => true, 'children' => array('rss' => 'test-2')) + )); + + $result = M($post_to_use); + + $this->assertEquals(array('test-1' => array('rss' => 'test-2')), $result); + $this->assertEquals($result, $__attachments); + $this->assertEquals(array( + 'test-1' => array('enabled' => true, 'children' => array('rss' => 'test-2')) + ), get_post_meta($post_to_test->ID, 'image-ordering', true)); + } +}