/** * Ensure that excluded posts and links behave as expected */ public function test_navigation_exclude() { $parent = $this->factory->post->create(array('post_type' => 'page')); $child = $this->factory->post->create(array('post_type' => 'page', 'post_parent' => $parent)); $hidden_child = $this->factory->post->create(array('post_type' => 'page', 'post_parent' => $parent)); $hidden_link = $this->factory->post->create(array('post_type' => 'bu_link', 'post_parent' => $parent)); // 1. Test default value (do not exclude) $posts = bu_navigation_get_posts(); $this->assertCount(4, $posts); // 2. Test explicit show for posts and nav links update_post_meta($hidden_child, BU_NAV_META_PAGE_EXCLUDE, 0); update_post_meta($hidden_link, BU_NAV_META_PAGE_EXCLUDE, 0); $posts = bu_navigation_get_posts(); $this->assertCount(4, $posts); // 3. Test explicit hide for posts and nav links update_post_meta($hidden_child, BU_NAV_META_PAGE_EXCLUDE, 1); update_post_meta($hidden_link, BU_NAV_META_PAGE_EXCLUDE, 1); $posts = bu_navigation_get_posts(); $this->assertCount(2, $posts); // 4. Test sans filter remove_filter('bu_navigation_filter_pages', 'bu_navigation_filter_pages_exclude'); $posts = bu_navigation_get_posts(); $this->assertCount(4, $posts); add_filter('bu_navigation_filter_pages', 'bu_navigation_filter_pages_exclude'); }
public function test_widget_adaptive_with_section_title() { global $wp_widget_factory, $post; /* * IA * - Page 1 * - Subpage 1.A * - Subpage 1.A.1 (widget loaded here) * - Subpage 1.A.1.A (excluded from nav) * - Subpage 1.A.2 */ $page1 = $this->factory->post->create(array('post_type' => 'page', 'post_title' => 'Page 1')); $page1_A = $this->factory->post->create(array('post_type' => 'page', 'post_title' => 'Subpage 1-A', 'post_parent' => $page1)); $page1_A_1 = $this->factory->post->create(array('post_type' => 'page', 'post_title' => 'Subpage 1-A-1 (Has Child)', 'post_parent' => $page1_A)); $page1_A_1_A = $this->factory->post->create(array('post_type' => 'page', 'post_title' => 'Subpage 1-A-1-A', 'post_parent' => $page1_A_1)); $page1_A_2 = $this->factory->post->create(array('post_type' => 'page', 'post_title' => 'Subpage 1-A-2 (No Child)', 'post_parent' => $page1_A)); // make sure we've got everyone $posts = bu_navigation_get_posts(); $this->assertCount(5, $posts); // set page1_A_1_A to hidden in nav update_post_meta($page1_A_1_A, BU_NAV_META_PAGE_EXCLUDE, 1); // make sure we're missing page1_A_1 $posts = bu_navigation_get_posts(); $this->assertCount(4, $posts); // load persepctive of page page1_A_1 $post = get_post($page1_A_1); setup_postdata($post); $instance = array('navigation_title' => 'section', 'navigation_title_text' => '', 'navigation_title_url' => '', 'navigation_style' => 'adaptive'); ob_start(); the_widget('BU_Widget_Pages', $instance); $widget = ob_get_contents(); ob_end_clean(); // echo $widget; $this->assertRegExp('/<h2.+Page 1<\\/a>/i', $widget); $this->assertRegExp('/class="level_1".+Subpage 1-A<\\/a>/is', $widget); }
/** * Legacy alias for bu_navigation_get_posts * * Translates legacy arguments that have been updated for consistency with WP_Query * * @param $args mixed Wordpress-style arguments (string or array) * @return array Array of pages keyed on page ID or FALSE on problem */ function bu_navigation_get_pages($args = '') { $defaults = array('pages' => null, 'suppress_filter_pages' => false); $r = wp_parse_args($args, $defaults); // Legacy arg translation if (!is_null($r['pages'])) { $r['post__in'] = $r['pages']; unset($r['pages']); } $r['suppress_filter_posts'] = $r['suppress_filter_pages']; unset($r['suppress_filter_pages']); return bu_navigation_get_posts($r); }
/** * Execute query set up during construction */ protected function query() { // Setup filters remove_filter('bu_navigation_filter_pages', 'bu_navigation_filter_pages_exclude'); add_filter('bu_navigation_filter_pages', array($this, 'filter_posts')); // Gather sections $section_args = array('direction' => 'down', 'depth' => $this->args['depth'], 'post_types' => $this->args['post_types']); $sections = bu_navigation_gather_sections($this->args['child_of'], $section_args); // Load pages in sections $this->posts = bu_navigation_get_posts(array('sections' => $sections, 'post_types' => $this->args['post_types'], 'post_status' => $this->args['post_status'], 'include_links' => $this->args['include_links'], 'suppress_urls' => $this->args['suppress_urls'])); $this->post_count = count($this->posts); // Restore filters remove_filter('bu_navigation_filter_pages', array($this, 'filter_posts')); add_filter('bu_navigation_filter_pages', 'bu_navigation_filter_pages_exclude'); }