Skip to content

Commit

Permalink
♻️ remove pages_by_parent filter
Browse files Browse the repository at this point in the history
as the whole setup is an unnecessary exercise in filtering.  Calling the function directly is much simpler and easier to understand.
  • Loading branch information
jdub233 committed Oct 27, 2020
1 parent 7e1f66a commit b432d9b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 19 deletions.
8 changes: 0 additions & 8 deletions class-bu-widget-pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,6 @@ public function widget( $args, $instance ) {
// Set list arguments based on post type and navigation style.
$list_args = $this->get_list_args( $post, $instance );

do_action( 'bu_navigation_widget_before_list' );

// Alter args for adaptive mode.
if ( 'adaptive' === $instance['navigation_style'] ) {
$list_args = widget_bu_pages_args_adaptive( $list_args );
Expand Down Expand Up @@ -284,12 +282,6 @@ protected function get_list_args( $post, $instance ) {
return ( is_404() ) ? '' : $list_args;
}

// 'adaptive' style needs an action from included/library.php to be loaded.
if ( 'adaptive' === $instance['navigation_style'] ) {
add_action( 'bu_navigation_widget_before_list', 'bu_navigation_widget_adaptive_before_list' );
return $list_args;
}

// 'site' navigation_style doesn't require additional handling.
return $list_args;
}
Expand Down
9 changes: 0 additions & 9 deletions extras/bu-navigation-adaptive-contentnav.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@
* @todo bu_navigation_list_pages has a lot of adaptive mode logic -- refactor to consolidate
*/

/**
* Attach adaptive-mode specific hooks
*/
function bu_navigation_widget_adaptive_before_list() {
add_filter( 'bu_navigation_filter_pages_by_parent', 'bu_navigation_filter_pages_adaptive' );
}

/**
* Filters arguments passed to bu_navigation_list_pages from widget display
*
Expand All @@ -39,8 +32,6 @@ function widget_bu_pages_args_adaptive( $args ) {
function bu_navigation_filter_pages_adaptive( $pages_by_parent ) {
global $post;

remove_filter( 'bu_navigation_filter_pages_by_parent', 'bu_navigation_filter_pages_adaptive' );

$filtered = array();
$has_children = false;

Expand Down
6 changes: 4 additions & 2 deletions includes/library.php
Original file line number Diff line number Diff line change
Expand Up @@ -714,8 +714,6 @@ function bu_navigation_pages_by_parent( $pages ) {
}
}

$pages_by_parent = apply_filters( 'bu_navigation_filter_pages_by_parent', $pages_by_parent );

return $pages_by_parent;
}

Expand Down Expand Up @@ -1022,6 +1020,10 @@ function bu_navigation_list_pages( $args = '' ) {
$pages = bu_navigation_get_pages( $page_args );
$pages_by_parent = bu_navigation_pages_by_parent( $pages );

if ( 'adaptive' === $parsed_args['style'] ) {
$pages_by_parent = bu_navigation_filter_pages_adaptive( $pages_by_parent );
}

$sections = ! empty( $parsed_args['sections'] ) ? $parsed_args['sections'] : array_keys( $pages_by_parent );

if ( 'adaptive' === $parsed_args['style'] ) {
Expand Down

0 comments on commit b432d9b

Please sign in to comment.