Changeset 13481 for trunk/src/bp-groups/classes/class-bp-groups-widget.php
- Timestamp:
- 05/17/2023 11:14:06 AM (21 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-groups/classes/class-bp-groups-widget.php
r13437 r13481 6 6 * @subpackage GroupsWidgets 7 7 * @since 1.0.0 8 * @deprecated 12.0.0 8 9 */ 9 10 … … 11 12 defined( 'ABSPATH' ) || exit; 12 13 14 _deprecated_file( basename( __FILE__ ), '12.0.0', '', __( 'BuddyPress does not include Legacy Widgets anymore, you can restore it using the BP Classic plugin', 'buddypress' ) ); 15 13 16 /** 14 17 * Groups widget. 15 18 * 16 19 * @since 1.0.3 20 * @deprecated 12.0.0 17 21 */ 18 class BP_Groups_Widget extends WP_Widget{22 class BP_Groups_Widget { 19 23 20 24 /** … … 23 27 * @since 1.0.3 24 28 * @since 9.0.0 Adds the `show_instance_in_rest` property to Widget options. 29 * @deprecated 12.0.0 25 30 */ 26 31 public function __construct() { 27 $widget_ops = array( 28 'description' => __( 'A dynamic list of recently active, popular, newest, or alphabetical groups', 'buddypress' ), 29 'classname' => 'widget_bp_groups_widget buddypress widget', 30 'customize_selective_refresh' => true, 31 'show_instance_in_rest' => true, 32 ); 33 parent::__construct( false, _x( '(BuddyPress) Groups', 'widget name', 'buddypress' ), $widget_ops ); 34 35 if ( is_customize_preview() || bp_is_widget_block_active( '', $this->id_base ) ) { 36 add_action( 'bp_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); 37 } 32 _deprecated_function( __METHOD__, '12.0.0' ); 38 33 } 39 34 … … 42 37 * 43 38 * @since 2.6.0 39 * @deprecated 12.0.0 44 40 */ 45 41 public function enqueue_scripts() { 46 $min = bp_core_get_minified_asset_suffix(); 47 wp_enqueue_script( 'groups_widget_groups_list-js', buddypress()->plugin_url . "bp-groups/js/widget-groups{$min}.js", array( 'jquery' ), bp_get_version() ); 42 _deprecated_function( __METHOD__, '12.0.0' ); 48 43 } 49 44 … … 52 47 * 53 48 * @since 1.0.3 49 * @deprecated 12.0.0 54 50 * 55 51 * @param array $args Array of arguments for the widget. … … 57 53 */ 58 54 public function widget( $args, $instance ) { 59 global $groups_template; 60 61 /** 62 * Filters the user ID to use with the widget instance. 63 * 64 * @since 1.5.0 65 * 66 * @param string $value Empty user ID. 67 */ 68 $user_id = apply_filters( 'bp_group_widget_user_id', '0' ); 69 70 extract( $args ); 71 72 if ( empty( $instance['group_default'] ) ) { 73 $instance['group_default'] = 'popular'; 74 } 75 76 if ( empty( $instance['title'] ) ) { 77 $instance['title'] = __( 'Groups', 'buddypress' ); 78 } 79 80 /** 81 * Filters the title of the Groups widget. 82 * 83 * @since 1.8.0 84 * @since 2.3.0 Added 'instance' and 'id_base' to arguments passed to filter. 85 * 86 * @param string $title The widget title. 87 * @param array $instance The settings for the particular instance of the widget. 88 * @param string $id_base Root ID for all widgets of this type. 89 */ 90 $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ); 91 92 /** 93 * Filters the separator of the group widget links. 94 * 95 * @since 2.4.0 96 * 97 * @param string $separator Separator string. Default '|'. 98 */ 99 $separator = apply_filters( 'bp_groups_widget_separator', '|' ); 100 101 echo $before_widget; 102 103 $title = ! empty( $instance['link_title'] ) ? '<a href="' . esc_url( bp_get_groups_directory_url() ) . '">' . $title . '</a>' : $title; 104 105 echo $before_title . $title . $after_title; 106 107 $max_limit = bp_get_widget_max_count_limit( __CLASS__ ); 108 $max_groups = ! empty( $instance['max_groups'] ) ? (int) $instance['max_groups'] : 5; 109 110 if ( $max_groups > $max_limit ) { 111 $max_groups = $max_limit; 112 } 113 114 $group_args = array( 115 'user_id' => $user_id, 116 'type' => $instance['group_default'], 117 'per_page' => $max_groups, 118 'max' => $max_groups, 119 ); 120 121 // Back up the global. 122 $old_groups_template = $groups_template; 123 124 ?> 125 126 <?php if ( bp_has_groups( $group_args ) ) : ?> 127 <div class="item-options" id="groups-list-options"> 128 <a href="<?php bp_groups_directory_url(); ?>" id="newest-groups"<?php if ( $instance['group_default'] == 'newest' ) : ?> class="selected"<?php endif; ?>><?php _e("Newest", 'buddypress') ?></a> 129 <span class="bp-separator" role="separator"><?php echo esc_html( $separator ); ?></span> 130 <a href="<?php bp_groups_directory_url(); ?>" id="recently-active-groups"<?php if ( $instance['group_default'] == 'active' ) : ?> class="selected"<?php endif; ?>><?php _e("Active", 'buddypress') ?></a> 131 <span class="bp-separator" role="separator"><?php echo esc_html( $separator ); ?></span> 132 <a href="<?php bp_groups_directory_url(); ?>" id="popular-groups" <?php if ( $instance['group_default'] == 'popular' ) : ?> class="selected"<?php endif; ?>><?php _e("Popular", 'buddypress') ?></a> 133 <span class="bp-separator" role="separator"><?php echo esc_html( $separator ); ?></span> 134 <a href="<?php bp_groups_directory_url(); ?>" id="alphabetical-groups" <?php if ( $instance['group_default'] == 'alphabetical' ) : ?> class="selected"<?php endif; ?>><?php _e("Alphabetical", 'buddypress') ?></a> 135 </div> 136 137 <ul id="groups-list" class="item-list" aria-live="polite" aria-relevant="all" aria-atomic="true"> 138 <?php while ( bp_groups() ) : bp_the_group(); ?> 139 <li <?php bp_group_class(); ?>> 140 <div class="item-avatar"> 141 <a href="<?php bp_group_url() ?>" class="bp-tooltip" data-bp-tooltip="<?php bp_group_name() ?>"><?php bp_group_avatar_thumb() ?></a> 142 </div> 143 144 <div class="item"> 145 <div class="item-title"><?php bp_group_link(); ?></div> 146 <div class="item-meta"> 147 <span class="activity"> 148 <?php 149 if ( 'newest' == $instance['group_default'] ) { 150 printf( __( 'created %s', 'buddypress' ), bp_get_group_date_created() ); 151 } elseif ( 'popular' == $instance['group_default'] ) { 152 bp_group_member_count(); 153 } else { 154 /* translators: %s: last activity timestamp (e.g. "Active 1 hour ago") */ 155 printf( __( 'Active %s', 'buddypress' ), bp_get_group_last_active() ); 156 } 157 ?> 158 </span> 159 </div> 160 </div> 161 </li> 162 163 <?php endwhile; ?> 164 </ul> 165 <?php wp_nonce_field( 'groups_widget_groups_list', '_wpnonce-groups' ); ?> 166 <input type="hidden" name="groups_widget_max" id="groups_widget_max" value="<?php echo esc_attr( $max_groups ); ?>" /> 167 168 <?php else: ?> 169 170 <div class="widget-error"> 171 <?php _e('There are no groups to display.', 'buddypress') ?> 172 </div> 173 174 <?php endif; ?> 175 176 <?php echo $after_widget; 177 178 // Restore the global. 179 $groups_template = $old_groups_template; 55 _deprecated_function( __METHOD__, '12.0.0' ); 180 56 } 181 57 … … 184 60 * 185 61 * @since 1.0.3 62 * @deprecated 12.0.0 186 63 * 187 64 * @param array $new_instance New instance data. … … 190 67 */ 191 68 public function update( $new_instance, $old_instance ) { 192 $instance = $old_instance; 193 194 $max_limit = bp_get_widget_max_count_limit( __CLASS__ ); 195 196 $instance['title'] = strip_tags( $new_instance['title'] ); 197 $instance['max_groups'] = $new_instance['max_groups'] > $max_limit ? $max_limit : intval( $new_instance['max_groups'] ); 198 $instance['group_default'] = strip_tags( $new_instance['group_default'] ); 199 $instance['link_title'] = ! empty( $new_instance['link_title'] ); 200 201 return $instance; 69 _deprecated_function( __METHOD__, '12.0.0' ); 202 70 } 203 71 … … 206 74 * 207 75 * @since 1.0.3 76 * @deprecated 12.0.0 208 77 * 209 78 * @param array $instance Current instance. … … 211 80 */ 212 81 public function form( $instance ) { 213 $defaults = array( 214 'title' => __( 'Groups', 'buddypress' ), 215 'max_groups' => 5, 216 'group_default' => 'active', 217 'link_title' => false, 218 ); 219 220 $instance = bp_parse_args( 221 (array) $instance, 222 $defaults, 223 'groups_widget_form' 224 ); 225 226 $max_limit = bp_get_widget_max_count_limit( __CLASS__ ); 227 228 $title = strip_tags( $instance['title'] ); 229 $max_groups = $instance['max_groups'] > $max_limit ? $max_limit : intval( $instance['max_groups'] ); 230 $group_default = strip_tags( $instance['group_default'] ); 231 $link_title = (bool) $instance['link_title']; 232 ?> 233 234 <p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e('Title:', 'buddypress'); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" style="width: 100%" /></label></p> 235 236 <p><label for="<?php echo $this->get_field_id('link_title') ?>"><input type="checkbox" name="<?php echo $this->get_field_name('link_title') ?>" id="<?php echo $this->get_field_id('link_title') ?>" value="1" <?php checked( $link_title ) ?> /> <?php _e( 'Link widget title to Groups directory', 'buddypress' ) ?></label></p> 237 238 <p><label for="<?php echo $this->get_field_id( 'max_groups' ); ?>"><?php _e( 'Max groups to show:', 'buddypress' ); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_groups' ); ?>" name="<?php echo $this->get_field_name( 'max_groups' ); ?>" type="number" min="1" max="<?php echo esc_attr( $max_limit ); ?>" value="<?php echo esc_attr( $max_groups ); ?>" style="width: 30%" /></label></p> 239 240 <p> 241 <label for="<?php echo $this->get_field_id( 'group_default' ); ?>"><?php _e('Default groups to show:', 'buddypress'); ?></label> 242 <select name="<?php echo $this->get_field_name( 'group_default' ); ?>" id="<?php echo $this->get_field_id( 'group_default' ); ?>"> 243 <option value="newest" <?php selected( $group_default, 'newest' ); ?>><?php _e( 'Newest', 'buddypress' ) ?></option> 244 <option value="active" <?php selected( $group_default, 'active' ); ?>><?php _e( 'Active', 'buddypress' ) ?></option> 245 <option value="popular" <?php selected( $group_default, 'popular' ); ?>><?php _e( 'Popular', 'buddypress' ) ?></option> 246 <option value="alphabetical" <?php selected( $group_default, 'alphabetical' ); ?>><?php _e( 'Alphabetical', 'buddypress' ) ?></option> 247 </select> 248 </p> 249 <?php 82 _deprecated_function( __METHOD__, '12.0.0' ); 250 83 } 251 84 }
Note: See TracChangeset
for help on using the changeset viewer.