Skip to:
Content

bbPress.org

Opened 6 years ago

Last modified 6 years ago

#3247 new enhancement

Improvement of bbp-topic-index shortcode

Reported by: satollo's profile satollo Owned by:
Milestone: 2.8 Priority: low
Severity: normal Version:
Component: API - Shortcodes Keywords: 2nd-opinion needs-patch
Cc:

Description

The bbp-topic-index shortcode just displays the list of the latest active topics. On many forum there is even the list of the last inserted topic (overall the whole forums) for who want to check new topics to reply to.

The shortcode could accept the attribute orderby and the modify the query to order by date instead of order by the last activity meta key.

Since the shortcode filters the query (shortcodes.php:293 inside the function display_topic_index) it should be easy to add that option.

PHP since version 5.3 should support this syntax:

if (isset($attrs['orderby'])) {
  add_filter('bbp_before_has_topics_parse_args', function ($args) {
    $args['orderby'] = $attrs['orderby'];
    return $args;
  });
}

which simplifies a lot the filter coding. In the code above $attrs is the default attributes array the shortcode function receive from WP.

Stefano.

Change History (2)

#1 @johnjamesjacoby
6 years ago

  • Component changed from Component - Topics to API - Shortcodes
  • Keywords 2nd-opinion needs-patch added
  • Milestone changed from Awaiting Review to 2.8

Hi @satollo. Thanks for creating this ticket here.

You're correct to identify that these shortcodes don't come with very many attributes available to them. You're also one of the first to recommend adding some new ones, and in thinking about it more, there is a lot we can do here.

I'd love a way to expose most (probably all?) of the attributes used by the queries inside of these shortcodes. There's really no reason not to, so long as they're all properly sanitized on the way in.

I imagine needing to break apart the BBP_Shortcodes class a bit, into unique individual shortcode (or block) objects, each with their own array of attributes, as right now they aren't really exposed anywhere; they're all trapped inside their respective $attr variables and methods.

If done correctly, this also ends up a neat (albeit scope-creeped) way to bring in some Gutenberg support.

If you're able to work up a patch, we could try to get something started in 2.7 or later. In general, we still support PHP 5.2 (as does WordPress) and try to stay away from anonymous functions and hooks together, because it's impossible to unhook them. This muddies the approach, but I hope you'll think about it a bit more.

Moving to 2.8 for now.

#2 @satollo
6 years ago

Hi, of course the code was a custom one for a specific site, not meant to be distributed. I can look at a better patch: not using the anonymous functions means to register the parameters in a class scoped variable, since we cannot pass them to the filtering function. But I'll look at that asap.

I think the main three lists of topics needed in a forum are:

  • the last updated
  • the ones without an answer (time limited - very old unanswered topics are not meaningful)
  • the recently created

They could be generated by a single shortcode or a set of shortcodes (like [bbp-topics-unanswered since-days="60"] and like).

Thank you, Stefano.

Note: See TracTickets for help on using tickets.