__( 'A dynamic list of recently active, popular, newest, or alphabetical groups', 'buddypress' ), 'classname' => 'widget_bp_groups_widget buddypress widget', 'customize_selective_refresh' => true, 'show_instance_in_rest' => true, ); parent::__construct( false, _x( '(BuddyPress) Groups', 'widget name', 'buddypress' ), $widget_ops ); if ( is_customize_preview() || bp_is_widget_block_active( '', $this->id_base ) ) { add_action( 'bp_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); } } /** * Enqueue scripts. * * @since 2.6.0 */ public function enqueue_scripts() { $min = bp_core_get_minified_asset_suffix(); wp_enqueue_script( 'groups_widget_groups_list-js', buddypress()->plugin_url . "bp-groups/js/widget-groups{$min}.js", array( 'jquery' ), bp_get_version() ); } /** * Extends our front-end output method. * * @since 1.0.3 * * @param array $args Array of arguments for the widget. * @param array $instance Widget instance data. */ public function widget( $args, $instance ) { global $groups_template; /** * Filters the user ID to use with the widget instance. * * @since 1.5.0 * * @param string $value Empty user ID. */ $user_id = apply_filters( 'bp_group_widget_user_id', '0' ); extract( $args ); if ( empty( $instance['group_default'] ) ) { $instance['group_default'] = 'popular'; } if ( empty( $instance['title'] ) ) { $instance['title'] = __( 'Groups', 'buddypress' ); } /** * Filters the title of the Groups widget. * * @since 1.8.0 * @since 2.3.0 Added 'instance' and 'id_base' to arguments passed to filter. * * @param string $title The widget title. * @param array $instance The settings for the particular instance of the widget. * @param string $id_base Root ID for all widgets of this type. */ $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ); /** * Filters the separator of the group widget links. * * @since 2.4.0 * * @param string $separator Separator string. Default '|'. */ $separator = apply_filters( 'bp_groups_widget_separator', '|' ); echo $before_widget; $title = ! empty( $instance['link_title'] ) ? '' . $title . '' : $title; echo $before_title . $title . $after_title; $max_limit = bp_get_widget_max_count_limit( __CLASS__ ); $max_groups = ! empty( $instance['max_groups'] ) ? (int) $instance['max_groups'] : 5; if ( $max_groups > $max_limit ) { $max_groups = $max_limit; } $group_args = array( 'user_id' => $user_id, 'type' => $instance['group_default'], 'per_page' => $max_groups, 'max' => $max_groups, ); // Back up the global. $old_groups_template = $groups_template; ?>
class="selected"> class="selected"> class="selected"> class="selected">
$max_limit ? $max_limit : intval( $new_instance['max_groups'] ); $instance['group_default'] = strip_tags( $new_instance['group_default'] ); $instance['link_title'] = ! empty( $new_instance['link_title'] ); return $instance; } /** * Extends our form method. * * @since 1.0.3 * * @param array $instance Current instance. * @return mixed */ public function form( $instance ) { $defaults = array( 'title' => __( 'Groups', 'buddypress' ), 'max_groups' => 5, 'group_default' => 'active', 'link_title' => false, ); $instance = bp_parse_args( (array) $instance, $defaults, 'groups_widget_form' ); $max_limit = bp_get_widget_max_count_limit( __CLASS__ ); $title = strip_tags( $instance['title'] ); $max_groups = $instance['max_groups'] > $max_limit ? $max_limit : intval( $instance['max_groups'] ); $group_default = strip_tags( $instance['group_default'] ); $link_title = (bool) $instance['link_title']; ?>