Skip to:
Content

bbPress.org

Opened 11 years ago

Closed 11 years ago

Last modified 8 months ago

#2550 closed enhancement (worksforme)

Function 'bbp_list_forums' does not allow for easy filtering

Reported by: robin-w's profile Robin W Owned by:
Milestone: Priority: normal
Severity: normal Version: 2.5.2
Component: General Keywords:
Cc:

Description

'bbp_list_forums' in /includes/forums/template starts on line 744

This function uses $r array to create a list of sub forums, which are held in $output.

The issue is that the "apply filters" is only done after $r array has been used to create $output,
so no change to $r in the filter can be used, and any filter to change the output display has to use almost all of this function.

Suggested improvement/fix :

adding a new line 766

$r = apply_filters('bbp_list_forums_args,$r)

would allow easy short filters against this array

eg

function hide_forum_counts ($r) {
$r['show_topic_count'] = false ;
$r['show_reply_count'] = false ;
$r['separator']  = ' ';
return $r ;
}
add_filter('bbp_list_forums_args','hide_forum_counts') ;

and make for neater non-repeated code

Change History (2)

#1 @netweb
11 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed

Robin,

There is a magical function called bbp_parse_args (Source: /includes/common/functions.php#L1312)

This function is used throughout bbPress to allow for either a string or array to be merged into another array. It is identical to wp_parse_args() except it allows for arguments to be passively or aggressively filtered using the optional $filter_key parameter.

If you see bbp_parse_args in a function you'll be able to filter all the things pretty easily.

Using your listed example above:

Example 1: (Source: https://gist.github.com/ntwb/3797945)

<?php
function hide_forum_counts() {
        $args['show_topic_count'] = false;
        $args['show_reply_count'] = false;
        $args['separator']        = ' '; 
        return $args;
}
add_filter('bbp_before_list_forums_parse_args', 'hide_forum_counts' );

To reverse the displayed sort order of topics (i.e use ASC instead of DESC):

<?php
function custom_display_topic_index_query () {
  $args['order'] = 'ASC';
 
  return $args;
}
add_filter('bbp_before_has_topics_parse_args', 'custom_display_topic_index_query' );

Another example for breadcrumbs via your post on bbpress.org:

<?php
//function to change name forums in breadcrumb to Blogs 
function mycustom_breadcrumb_options() {
    $args['root_text']    = 'Blogs';
        return $args;
}
add_filter('bbp_before_get_breadcrumb_parse_args', 'mycustom_breadcrumb_options') ;

#2 @Robin W
11 years ago

Stephen,

Many thanks for this - much appreciated. I'm writing some filter stuff for the codex, and will add this to it.

Regards

Robin

Note: See TracTickets for help on using tickets.