be_subpages_widget_args filter
Closed this issue · 6 comments
The be_subpages_widget_args
filter appears twice, once for the original fetch of get_pages() and another for the deeper pages. So if this is filtered (since $post->ID or $subpage->ID), then it ruins the entire widget. I recommend that the second filter name be changed to something like be_subpages_widget_deeper_args
.
Can you give me an example where you'd need different arguments for the top level args and the lower level args?
By default, they are different args. Look at the code:
if ( $deep_subpages && in_array( $subpage->ID, $parents ) ) {
$args = array(
'child_of' => $subpage->ID,
'parent' => $subpage->ID,
);
$deeper_pages = get_pages( apply_filters( 'be_subpages_widget_args', $args ) );
$this->build_subpages( $deeper_pages, $parents );
}
$args = array(
'child_of' => $parents[0],
'parent' => $parents[0],
'sort_column' => 'menu_order'
);
$subpages = get_pages( apply_filters( 'be_subpages_widget_args', $args ) );
So, how is one to differentiate between the two?
You could pass a second optional parameter instead of a second filter name.
But my question is, what would you be doing with a filter that requires differentiation, as a use case?
(as an aside, I see one bug that needs fixing: we need the sort_column on the deeper pages)
Yes, that was one which I added as well. The second for me is that I do not want to filter deeper subpages because I wanted to include the parent page as well as the contact page in the listing as the first item per my client's request.
add_filter( 'be_subpages_widget_args', 'flashcove_subpages_widget_args' );
/**
* Add Parent to the Subpages Widget.
*
* @param array $args Array of arguments.
* @param array Modified array of arguments for get_pages().
*/
function flashcove_subpages_widget_args( $args ) {
// Build a menu listing top level parent's children
$args['include'] = $args['child_of'] . ',10';
$args['sort_column'] = 'menu_order';
return $args;
}
I would be nice if the parent page ID was passed as an argument, so I wouldn't have to re
Just updated it ( b82306e ) . Let me know if this works for you.