/** * Extends topic shortcode for BuddyBoss to allow filtering by author. */ class BBP_Extended_Shortcode { /** * Cached attributes for the current shortcode instance. * * @var array Attributes */ private array $atts = array(); /** * Sets up shortcode. */ public function setup() { add_shortcode( 'bbp-topic-index-extended', array( $this, 'shortcode' ) ); } /** * Extended bbPress topic index shortcode. * * @param array $atts Attributes. * @param string $content Content. * * @return string */ public function shortcode( $atts = array(), $content = null ) { $atts = shortcode_atts( array( 'author' => bp_displayed_user_id(), ), $atts ); $this->atts = $atts; if ( ! function_exists( 'bbpress' ) ) { return ''; } $bbp_shortcodes = bbpress()->shortcodes; // Bail if shortcodes are unset somehow if ( ! is_a( $bbp_shortcodes, 'BBP_Shortcodes' ) ) { return ''; } // Hook our author filter. if ( ! bbp_is_topic_archive() ) { add_filter( 'bbp_before_has_topics_parse_args', array( $this, 'update_query' ), 200 ); } if ( ! is_callable( array( $bbp_shortcodes, 'display_topic_index' ) ) ) { return ''; } return $bbp_shortcodes->display_topic_index(); } /** * Updates bbPress topic query * * @param array $args args. * * @return array */ public function update_query( $args = array() ) { if ( ! empty( $this->atts['author'] ) ) { $args['author'] = $this->atts['author']; unset( $this->atts['author'] ); } return $args; } } ( new BBP_Extended_Shortcode() )->setup(); Muzo+

Muzo+