'forumax_active_members_widget', 'description' => esc_html__( 'Displays members who participated in the current topic. Only visible on single topic pages.', 'forumax' ), 'customize_selective_refresh' => true, ) ); parent::__construct( 'forumax_active_members', esc_html__( '(Forumax) Active Members', 'forumax' ), $widget_ops ); } /** * Register the widget. */ public static function register_widget() { register_widget( __CLASS__ ); } /** * Displays the output — list of active members in the current topic. * * Only renders on single topic pages. On all other pages, * the widget silently returns without any output. * * @param array $args Widget display arguments. * @param array $instance Widget instance settings. */ public function widget( $args = array(), $instance = array() ) { wp_enqueue_style( 'bbpc-forum' ); // Only display on single topic pages. if ( ! function_exists( 'bbp_is_single_topic' ) || ! bbp_is_single_topic() ) { return; } $topic_id = bbp_get_topic_id(); if ( empty( $topic_id ) ) { return; } // Get widget settings. $settings = $this->parse_settings( $instance ); // Apply standard WordPress title filter. $settings['title'] = apply_filters( 'widget_title', $settings['title'], $instance, $this->id_base ); // Forumax-specific filter. $settings['title'] = apply_filters( 'forumax_active_members_widget_title', $settings['title'], $instance, $this->id_base ); // Fetch unique participant user IDs for this topic. $member_ids = $this->get_topic_participants( $topic_id, (int) $settings['max_shown'] ); // Bail if no participants found. if ( empty( $member_ids ) ) { return; } $avatar_size = absint( $settings['avatar_size'] ); echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped if ( ! empty( $settings['title'] ) ) { echo $args['before_title'] . $settings['title'] . $args['after_title']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } ?> get_col( $wpdb->prepare( "SELECT DISTINCT post_author FROM {$wpdb->posts} WHERE post_parent = %d AND post_type = %s AND post_status IN ( 'publish', 'closed' ) ORDER BY post_date DESC", $topic_id, bbp_get_reply_post_type() ) ); // Include the topic author at the beginning. $topic_author = get_post_field( 'post_author', $topic_id ); if ( ! empty( $topic_author ) ) { // Remove topic author from results if already present, then prepend. $results = array_diff( $results, array( $topic_author ) ); array_unshift( $results, $topic_author ); } // Remove invalid (0) IDs and limit. $results = array_filter( $results ); $results = array_slice( $results, 0, $max_shown ); return array_map( 'absint', $results ); } /** * Update the widget options. * * @param array $new_instance The new instance options. * @param array $old_instance The old instance options. * @return array Updated instance. */ public function update( $new_instance = array(), $old_instance = array() ) { $instance = $old_instance; $instance['title'] = strip_tags( $new_instance['title'] ); $instance['max_shown'] = (int) $new_instance['max_shown']; $instance['avatar_size'] = absint( $new_instance['avatar_size'] ); return $instance; } /** * Output the widget options form. * * @param array $instance Current widget instance settings. */ public function form( $instance = array() ) { // Get widget settings. $settings = $this->parse_settings( $instance ); ?>

esc_html__( 'Active Members', 'forumax' ), 'max_shown' => 8, 'avatar_size' => 60, ), 'forumax_active_members_widget_settings' ); } }