Ticket #8594: 8594.patch
File 8594.patch, 29.6 KB (added by , 4 years ago) |
---|
-
src/bp-blogs/bp-blogs-widgets.php
diff --git src/bp-blogs/bp-blogs-widgets.php src/bp-blogs/bp-blogs-widgets.php index b0edfea71..1b7e1bed3 100644
10 10 // Exit if accessed directly. 11 11 defined( 'ABSPATH' ) || exit; 12 12 13 /** 14 * Registers the Recent Posts Legacy Widget. 15 * 16 * @since 10.0.0 17 */ 18 function bp_blogs_register_recent_posts_widget() { 19 register_widget( 'BP_Blogs_Recent_Posts_Widget' ); 20 } 21 13 22 /** 14 23 * Register the widgets for the Blogs component. 15 24 */ … … function bp_blogs_register_widgets() { 17 26 global $wpdb; 18 27 19 28 if ( bp_is_active( 'activity' ) && bp_is_root_blog( $wpdb->blogid ) ) { 20 add_action( 'widgets_init', function() { register_widget( 'BP_Blogs_Recent_Posts_Widget' ); });29 add_action( 'widgets_init', 'bp_blogs_register_recent_posts_widget' ); 21 30 } 22 31 } 23 32 add_action( 'bp_register_widgets', 'bp_blogs_register_widgets' ); -
src/bp-core/bp-core-widgets.php
diff --git src/bp-core/bp-core-widgets.php src/bp-core/bp-core-widgets.php index 17be2801a..53ae6d981 100644
10 10 // Exit if accessed directly. 11 11 defined( 'ABSPATH' ) || exit; 12 12 13 /** 14 * Should BuddyPress load Legacy Widgets? 15 * 16 * @since 10.0.0 17 * 18 * @return bool False if BuddyPress shouldn't load Legacy Widgets. True otherwise. 19 */ 20 function bp_core_retain_legacy_widgets() { 21 $theme_supports = current_theme_supports( 'widgets-block-editor' ); 22 $wp_supports = bp_is_running_wp( '5.8.0' ); 23 24 /** This filter is documented in wp-includes/widgets.php */ 25 $block_widgets_enabled = $theme_supports && apply_filters( 'use_widgets_block_editor', $wp_supports ); 26 27 $retain_legacy_widgets = true; 28 if ( $block_widgets_enabled ) { 29 $retain_legacy_widgets = false; 30 } 31 32 /** 33 * Filter here to force Legacy Widgets to be retained or not. 34 * 35 * @since 10.0.0 36 * 37 * @param bool $retain_legacy_widgets False if BuddyPress shouldn't load Legacy Widgets. True otherwise. 38 */ 39 return apply_filters( 'bp_core_retain_legacy_widgets', $retain_legacy_widgets ); 40 } 41 42 /** 43 * Registers the Login widget. 44 * 45 * @since 10.0.0 46 */ 47 function bp_core_register_login_widget() { 48 register_widget( 'BP_Core_Login_Widget' ); 49 } 50 13 51 /** 14 52 * Register bp-core widgets. 15 53 * 16 54 * @since 1.0.0 17 55 */ 18 56 function bp_core_register_widgets() { 19 add_action( 'widgets_init', function() { register_widget( 'BP_Core_Login_Widget' ); });57 add_action( 'widgets_init', 'bp_core_register_login_widget' ); 20 58 } 21 59 add_action( 'bp_register_widgets', 'bp_core_register_widgets' ); 60 61 /** 62 * Checks whether BuddyPress should unhook Legacy Widget registrations. 63 * 64 * @since 10.0.0 65 */ 66 function bp_core_maybe_unhook_legacy_widgets() { 67 if ( bp_core_retain_legacy_widgets() ) { 68 return; 69 } 70 71 $callbacks = array( 72 'bp_core_register_login_widget', 73 'bp_members_register_members_widget', 74 'bp_members_register_whos_online_widget', 75 'bp_members_register_recently_active_widget', 76 ); 77 78 if ( bp_is_active( 'friends' ) ) { 79 $callbacks[] = 'bp_friends_register_friends_widget'; 80 } 81 82 if ( bp_is_active( 'groups' ) ) { 83 $callbacks[] = 'bp_groups_register_groups_widget'; 84 } 85 86 if ( bp_is_active( 'messages' ) ) { 87 $callbacks[] = 'bp_messages_register_sitewide_notices_widget'; 88 } 89 90 if ( bp_is_active( 'blogs' ) && bp_is_active( 'activity' ) && bp_is_root_blog() ) { 91 $callbacks[] = 'bp_blogs_register_recent_posts_widget'; 92 } 93 94 foreach ( $callbacks as $callback ) { 95 remove_action( 'widgets_init', $callback ); 96 } 97 } 98 add_action( 'widgets_init', 'bp_core_maybe_unhook_legacy_widgets', 0 ); -
src/bp-friends/bp-friends-widgets.php
diff --git src/bp-friends/bp-friends-widgets.php src/bp-friends/bp-friends-widgets.php index 9858b7c78..732f48de8 100644
10 10 // Exit if accessed directly. 11 11 defined( 'ABSPATH' ) || exit; 12 12 13 /** 14 * Registers the Friends Legacy Widget. 15 * 16 * @since 10.0.0 17 */ 18 function bp_friends_register_friends_widget() { 19 register_widget( 'BP_Core_Friends_Widget' ); 20 } 21 13 22 /** 14 23 * Register the friends widget. 15 24 * … … function bp_friends_register_widgets() { 27 36 return; 28 37 } 29 38 30 add_action( 31 'widgets_init', 32 function() { 33 register_widget( 'BP_Core_Friends_Widget' ); 34 } 35 ); 39 add_action( 'widgets_init', 'bp_friends_register_friends_widget' ); 36 40 } 37 41 add_action( 'bp_register_widgets', 'bp_friends_register_widgets' ); 38 42 -
src/bp-groups/bp-groups-widgets.php
diff --git src/bp-groups/bp-groups-widgets.php src/bp-groups/bp-groups-widgets.php index 937bb14cb..50516eb49 100644
10 10 // Exit if accessed directly. 11 11 defined( 'ABSPATH' ) || exit; 12 12 13 /** 14 * Registers the Groups Legacy Widget. 15 * 16 * @since 10.0.0 17 */ 18 function bp_groups_register_groups_widget() { 19 register_widget( 'BP_Groups_Widget' ); 20 } 21 13 22 /** 14 23 * Register widgets for groups component. 15 24 * 16 25 * @since 1.0.0 17 26 */ 18 27 function groups_register_widgets() { 19 add_action( 'widgets_init', function() { register_widget( 'BP_Groups_Widget' ); });28 add_action( 'widgets_init', 'bp_groups_register_groups_widget' ); 20 29 } 21 30 add_action( 'bp_register_widgets', 'groups_register_widgets' ); 22 31 -
src/bp-members/bp-members-widgets.php
diff --git src/bp-members/bp-members-widgets.php src/bp-members/bp-members-widgets.php index 924980fb3..3d760f22f 100644
10 10 // Exit if accessed directly. 11 11 defined( 'ABSPATH' ) || exit; 12 12 13 /** 14 * Registers the Members Legacy Widget. 15 * 16 * @since 10.0.0 17 */ 18 function bp_members_register_members_widget() { 19 register_widget( 'BP_Core_Members_Widget' ); 20 } 21 22 /** 23 * Registers the "Who's online?" Legacy Widget. 24 * 25 * @since 10.0.0 26 */ 27 function bp_members_register_whos_online_widget() { 28 register_widget( 'BP_Core_Whos_Online_Widget' ); 29 } 30 31 /** 32 * Registers the "Recently Active" Legacy Widget. 33 * 34 * @since 10.0.0 35 */ 36 function bp_members_register_recently_active_widget() { 37 register_widget( 'BP_Core_Recently_Active_Widget' ); 38 } 39 13 40 /** 14 41 * Register bp-members widgets. 15 42 * … … defined( 'ABSPATH' ) || exit; 18 45 * @since 2.2.0 19 46 */ 20 47 function bp_members_register_widgets() { 21 add_action( 22 'widgets_init', 23 function() { 24 return register_widget( 'BP_Core_Members_Widget' ); 25 } 26 ); 27 28 add_action( 29 'widgets_init', 30 function() { 31 return register_widget( 'BP_Core_Whos_Online_Widget' ); 32 } 33 ); 34 35 add_action( 36 'widgets_init', 37 function() { 38 return register_widget( 'BP_Core_Recently_Active_Widget' ); 39 } 40 ); 48 add_action( 'widgets_init', 'bp_members_register_members_widget' ); 49 add_action( 'widgets_init', 'bp_members_register_whos_online_widget' ); 50 add_action( 'widgets_init', 'bp_members_register_recently_active_widget' ); 41 51 } 42 52 add_action( 'bp_register_widgets', 'bp_members_register_widgets' ); 43 53 -
src/bp-messages/bp-messages-widgets.php
diff --git src/bp-messages/bp-messages-widgets.php src/bp-messages/bp-messages-widgets.php index cd8ffd4a0..d9bf3d1e6 100644
10 10 // Exit if accessed directly. 11 11 defined( 'ABSPATH' ) || exit; 12 12 13 /** 14 * Registers the Sitewide Notices Legacy Widget. 15 * 16 * @since 10.0.0 17 */ 18 function bp_messages_register_sitewide_notices_widget() { 19 register_widget( 'BP_Messages_Sitewide_Notices_Widget' ); 20 } 21 13 22 /** 14 23 * Register widgets for the Messages component. 15 24 * 16 25 * @since 1.9.0 17 26 */ 18 27 function bp_messages_register_widgets() { 19 add_action( 20 'widgets_init', 21 function() { 22 register_widget( 'BP_Messages_Sitewide_Notices_Widget' ); 23 } 24 ); 28 add_action( 'widgets_init', 'bp_messages_register_sitewide_notices_widget' ); 25 29 } 26 30 add_action( 'bp_register_widgets', 'bp_messages_register_widgets' ); -
src/bp-templates/bp-nouveau/buddypress-functions.php
diff --git src/bp-templates/bp-nouveau/buddypress-functions.php src/bp-templates/bp-nouveau/buddypress-functions.php index bffb1ce40..a9ccaee8a 100644
class BP_Nouveau extends BP_Theme_Compat { 196 196 add_action( 'widgets_init', 'bp_nouveau_register_sidebars', 11 ); 197 197 198 198 // Register the Primary Object nav widget. 199 add_action( 'bp_widgets_init', array( 'BP_Nouveau_Object_Nav_Widget', 'register_widget' ) ); 199 if ( bp_core_retain_legacy_widgets() ) { 200 add_action( 'bp_widgets_init', array( 'BP_Nouveau_Object_Nav_Widget', 'register_widget' ) ); 201 } 200 202 201 203 // Set the BP Uri for the Ajax customizer preview. 202 204 add_filter( 'bp_uri', array( $this, 'customizer_set_uri' ), 10, 1 ); -
src/bp-templates/bp-nouveau/includes/activity/loader.php
diff --git src/bp-templates/bp-nouveau/includes/activity/loader.php src/bp-templates/bp-nouveau/includes/activity/loader.php index 9f74fc3ba..73ed8791b 100644
class BP_Nouveau_Activity { 60 60 protected function includes() { 61 61 require $this->dir . 'functions.php'; 62 62 require $this->dir . 'template-tags.php'; 63 require $this->dir . 'widgets.php'; 63 64 if ( bp_core_retain_legacy_widgets() ) { 65 require $this->dir . 'widgets.php'; 66 } 64 67 65 68 // Test suite requires the AJAX functions early. 66 69 if ( function_exists( 'tests_add_filter' ) ) { … … class BP_Nouveau_Activity { 87 90 */ 88 91 protected function setup_actions() { 89 92 add_action( 'bp_nouveau_enqueue_scripts', 'bp_nouveau_activity_enqueue_scripts' ); 90 add_action( 'bp_widgets_init', array( 'BP_Latest_Activities', 'register_widget' ) );91 93 add_action( 'bp_nouveau_notifications_init_filters', 'bp_nouveau_activity_notification_filters' ); 92 94 95 if ( bp_core_retain_legacy_widgets() ) { 96 add_action( 'bp_widgets_init', array( 'BP_Latest_Activities', 'register_widget' ) ); 97 } 98 93 99 $bp = buddypress(); 94 100 95 101 if ( bp_is_akismet_active() && isset( $bp->activity->akismet ) ) { -
src/bp-templates/bp-nouveau/includes/classes.php
diff --git src/bp-templates/bp-nouveau/includes/classes.php src/bp-templates/bp-nouveau/includes/classes.php index 52f52612d..3e01aa79e 100644
3 3 * Common Classes 4 4 * 5 5 * @since 3.0.0 6 * @version 9.0.06 * @version 10.0.0 7 7 */ 8 8 9 9 // Exit if accessed directly. 10 10 defined( 'ABSPATH' ) || exit; 11 11 12 /** 13 * Builds a group of BP_Button 14 * 15 * @since 3.0.0 16 */ 17 class BP_Buttons_Group { 18 19 /** 20 * The parameters of the Group of buttons 21 * 22 * @var array 23 */ 24 protected $group = array(); 25 26 /** 27 * Constructor 28 * 29 * @since 3.0.0 30 * 31 * @param array $args Optional array having the following parameters { 32 * @type string $id A string to use as the unique ID for the button. Required. 33 * @type int $position Where to insert the Button. Defaults to 99. 34 * @type string $component The Component's the button is build for (eg: Activity, Groups..). Required. 35 * @type bool $must_be_logged_in Whether the button should only be displayed to logged in users. Defaults to True. 36 * @type bool $block_self Optional. True if the button should be hidden when a user is viewing his own profile. 37 * Defaults to False. 38 * @type string $parent_element Whether to use a wrapper. Defaults to false. 39 * @type string $parent_attr set an array of attributes for the parent element. 40 * @type string $button_element Set this to 'button', 'img', or 'a', defaults to anchor. 41 * @type string $button_attr Any attributes required for the button_element 42 * @type string $link_text The text of the link. Required. 43 * } 44 */ 45 public function __construct( $args = array() ) { 46 foreach ( $args as $arg ) { 47 $this->add( $arg ); 48 } 49 } 50 51 52 /** 53 * Sort the Buttons of the group according to their position attribute 54 * 55 * @since 3.0.0 56 * 57 * @param array the list of buttons to sort. 58 * 59 * @return array the list of buttons sorted. 60 */ 61 public function sort( $buttons ) { 62 $sorted = array(); 63 64 foreach ( $buttons as $button ) { 65 $position = 99; 66 67 if ( isset( $button['position'] ) ) { 68 $position = (int) $button['position']; 69 } 70 71 // If position is already taken, move to the first next available 72 if ( isset( $sorted[ $position ] ) ) { 73 $sorted_keys = array_keys( $sorted ); 74 75 do { 76 $position += 1; 77 } while ( in_array( $position, $sorted_keys, true ) ); 78 } 79 80 $sorted[ $position ] = $button; 81 } 82 83 ksort( $sorted ); 84 return $sorted; 85 } 86 87 /** 88 * Get the BuddyPress buttons for the group 89 * 90 * @since 3.0.0 91 * 92 * @param bool $sort whether to sort the buttons or not. 93 * 94 * @return array An array of HTML links. 95 */ 96 public function get( $sort = true ) { 97 $buttons = array(); 98 99 if ( empty( $this->group ) ) { 100 return $buttons; 101 } 102 103 if ( true === $sort ) { 104 $this->group = $this->sort( $this->group ); 105 } 106 107 foreach ( $this->group as $key_button => $button ) { 108 // Reindex with ids. 109 if ( true === $sort ) { 110 $this->group[ $button['id'] ] = $button; 111 unset( $this->group[ $key_button ] ); 112 } 113 114 $buttons[ $button['id'] ] = bp_get_button( $button ); 115 } 116 117 return $buttons; 118 } 119 120 /** 121 * Update the group of buttons 122 * 123 * @since 3.0.0 124 * 125 * @param array $args Optional. See the __constructor for a description of this argument. 126 */ 127 public function update( $args = array() ) { 128 foreach ( $args as $id => $params ) { 129 if ( isset( $this->group[ $id ] ) ) { 130 $this->group[ $id ] = bp_parse_args( 131 $params, 132 $this->group[ $id ], 133 'buttons_group_update' 134 ); 135 } else { 136 $this->add( $params ); 137 } 138 } 139 } 140 141 /** 142 * Adds a button. 143 * 144 * @since 9.0.0 145 * 146 * @param array $args Required. See the __constructor for a description of this argument. 147 * @return bool true on success, false on failure to add. 148 */ 149 private function add( $args ) { 150 $r = bp_parse_args( 151 (array) $args, 152 array( 153 'id' => '', 154 'position' => 99, 155 'component' => '', 156 'must_be_logged_in' => true, 157 'block_self' => false, 158 'parent_element' => false, 159 'parent_attr' => array(), 160 'button_element' => 'a', 161 'button_attr' => array(), 162 'link_text' => '', 163 ), 164 'buttons_group_constructor' 165 ); 166 167 // Just don't set the button if a param is missing 168 if ( empty( $r['id'] ) || empty( $r['component'] ) || empty( $r['link_text'] ) ) { 169 return false; 170 } 171 172 $r['id'] = sanitize_key( $r['id'] ); 173 174 // If the button already exist don't add it 175 if ( isset( $this->group[ $r['id'] ] ) ) { 176 return false; 177 } 178 179 /* 180 * If, in bp_nouveau_get_*_buttons(), we pass through a false value for 'parent_element' 181 * but we have attributtes for it in the array, let's default to setting a div. 182 * 183 * Otherwise, the original false value will be passed through to BP buttons. 184 * @todo: this needs review, probably trying to be too clever 185 */ 186 if ( ( ! empty( $r['parent_attr'] ) ) && false === $r['parent_element'] ) { 187 $r['parent_element'] = 'div'; 188 } 189 190 $this->group[ $r['id'] ] = $r; 191 return true; 192 } 193 } 194 195 /** 196 * BP Sidebar Item Nav_Widget 197 * 198 * Adds a widget to move avatar/item nav into the sidebar 199 * 200 * @since 3.0.0 201 * 202 * @uses WP_Widget 203 */ 204 class BP_Nouveau_Object_Nav_Widget extends WP_Widget { 205 /** 206 * Constructor 207 * 208 * @since 3.0.0 209 * @since 9.0.0 Adds the `show_instance_in_rest` property to Widget options. 210 */ 211 public function __construct() { 212 $widget_ops = array( 213 'description' => __( 'Displays BuddyPress primary nav in the sidebar of your site. Make sure to use it as the first widget of the sidebar and only once.', 'buddypress' ), 214 'classname' => 'widget_nav_menu buddypress_object_nav', 215 'show_instance_in_rest' => true, 216 ); 217 218 parent::__construct( 219 'bp_nouveau_sidebar_object_nav_widget', 220 __( '(BuddyPress) Primary navigation', 'buddypress' ), 221 $widget_ops 222 ); 223 } 224 225 /** 226 * Register the widget 227 * 228 * @since 3.0.0 229 */ 230 public static function register_widget() { 231 register_widget( 'BP_Nouveau_Object_Nav_Widget' ); 232 } 233 234 /** 235 * Displays the output, the button to post new support topics 236 * 237 * @since 3.0.0 238 * 239 * @param mixed $args Arguments 240 * @param unknown $instance 241 */ 242 public function widget( $args, $instance ) { 243 if ( ! is_buddypress() || bp_is_group_create() ) { 244 return; 245 } 246 247 /** 248 * Filters the nav widget args for the BP_Nouveau_Object_Nav_Widget widget. 249 * 250 * @since 3.0.0 251 * 252 * @param array $value Array of arguments { 253 * @param bool $bp_nouveau_widget_title Whether or not to assign a title for the widget. 254 * } 255 */ 256 $item_nav_args = bp_parse_args( 257 $instance, 258 apply_filters( 259 'bp_nouveau_object_nav_widget_args', 260 array( 'bp_nouveau_widget_title' => true ) 261 ), 262 'widget_object_nav' 263 ); 264 265 $title = ''; 266 267 if ( ! empty( $item_nav_args['bp_nouveau_widget_title'] ) ) { 268 if ( bp_is_group() ) { 269 $title = bp_get_current_group_name(); 270 } elseif ( bp_is_user() ) { 271 $title = bp_get_displayed_user_fullname(); 272 } elseif ( bp_get_directory_title( bp_current_component() ) ) { 273 $title = bp_get_directory_title( bp_current_component() ); 274 } 275 } 276 277 /** 278 * Filters the BP_Nouveau_Object_Nav_Widget widget title. 279 * 280 * @since 3.0.0 281 * 282 * @param string $title The widget title. 283 * @param array $instance The settings for the particular instance of the widget. 284 * @param string $id_base Root ID for all widgets of this type. 285 */ 286 $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); 287 288 echo $args['before_widget']; 289 290 if ( ! empty( $title ) ) { 291 echo $args['before_title'] . $title . $args['after_title']; 292 } 293 294 if ( bp_is_user() ) { 295 bp_get_template_part( 'members/single/parts/item-nav' ); 296 } elseif ( bp_is_group() ) { 297 bp_get_template_part( 'groups/single/parts/item-nav' ); 298 } elseif ( bp_is_directory() ) { 299 bp_get_template_part( 'common/nav/directory-nav' ); 300 } 301 302 echo $args['after_widget']; 303 } 304 305 /** 306 * Update the new support topic widget options (title) 307 * 308 * @since 3.0.0 309 * 310 * @param array $new_instance The new instance options 311 * @param array $old_instance The old instance options 312 * 313 * @return array the instance 314 */ 315 public function update( $new_instance, $old_instance ) { 316 $instance = $old_instance; 317 $instance['bp_nouveau_widget_title'] = (bool) $new_instance['bp_nouveau_widget_title']; 318 319 return $instance; 320 } 321 322 /** 323 * Output the new support topic widget options form 324 * 325 * @since 3.0.0 326 * 327 * @param $instance Instance 328 * 329 * @return string HTML Output 330 */ 331 public function form( $instance ) { 332 $defaults = array( 333 'bp_nouveau_widget_title' => true, 334 ); 335 336 $instance = bp_parse_args( 337 (array) $instance, 338 $defaults, 339 'widget_object_nav_form' 340 ); 341 342 $bp_nouveau_widget_title = (bool) $instance['bp_nouveau_widget_title']; 343 ?> 344 345 <p> 346 <input class="checkbox" type="checkbox" <?php checked( $bp_nouveau_widget_title, true ); ?> id="<?php echo $this->get_field_id( 'bp_nouveau_widget_title' ); ?>" name="<?php echo $this->get_field_name( 'bp_nouveau_widget_title' ); ?>" /> 347 <label for="<?php echo $this->get_field_id( 'bp_nouveau_widget_title' ); ?>"><?php esc_html_e( 'Include navigation title', 'buddypress' ); ?></label> 348 </p> 12 require plugin_dir_path( __FILE__ ) . 'classes/class-bp-buttons-group.php'; 349 13 350 <?php 351 }14 if ( bp_core_retain_legacy_widgets() ) { 15 require plugin_dir_path( __FILE__ ) . 'classes/class-bp-nouveau-object-nav-widget.php'; 352 16 } -
src/bp-templates/bp-nouveau/includes/classes/class-bp-buttons-group.php
diff --git src/bp-templates/bp-nouveau/includes/classes/class-bp-buttons-group.php src/bp-templates/bp-nouveau/includes/classes/class-bp-buttons-group.php index e69de29bb..be429fdaa 100644
1 <?php 2 /** 3 * BP Buttons Group class. 4 * 5 * @since 3.0.0 6 * @version 10.0.0 7 */ 8 9 // Exit if accessed directly. 10 defined( 'ABSPATH' ) || exit; 11 12 /** 13 * Builds a group of BP_Button 14 * 15 * @since 3.0.0 16 */ 17 class BP_Buttons_Group { 18 19 /** 20 * The parameters of the Group of buttons 21 * 22 * @var array 23 */ 24 protected $group = array(); 25 26 /** 27 * Constructor 28 * 29 * @since 3.0.0 30 * 31 * @param array $args Optional array having the following parameters { 32 * @type string $id A string to use as the unique ID for the button. Required. 33 * @type int $position Where to insert the Button. Defaults to 99. 34 * @type string $component The Component's the button is build for (eg: Activity, Groups..). Required. 35 * @type bool $must_be_logged_in Whether the button should only be displayed to logged in users. Defaults to True. 36 * @type bool $block_self Optional. True if the button should be hidden when a user is viewing his own profile. 37 * Defaults to False. 38 * @type string $parent_element Whether to use a wrapper. Defaults to false. 39 * @type string $parent_attr set an array of attributes for the parent element. 40 * @type string $button_element Set this to 'button', 'img', or 'a', defaults to anchor. 41 * @type string $button_attr Any attributes required for the button_element 42 * @type string $link_text The text of the link. Required. 43 * } 44 */ 45 public function __construct( $args = array() ) { 46 foreach ( $args as $arg ) { 47 $this->add( $arg ); 48 } 49 } 50 51 52 /** 53 * Sort the Buttons of the group according to their position attribute 54 * 55 * @since 3.0.0 56 * 57 * @param array the list of buttons to sort. 58 * 59 * @return array the list of buttons sorted. 60 */ 61 public function sort( $buttons ) { 62 $sorted = array(); 63 64 foreach ( $buttons as $button ) { 65 $position = 99; 66 67 if ( isset( $button['position'] ) ) { 68 $position = (int) $button['position']; 69 } 70 71 // If position is already taken, move to the first next available 72 if ( isset( $sorted[ $position ] ) ) { 73 $sorted_keys = array_keys( $sorted ); 74 75 do { 76 $position += 1; 77 } while ( in_array( $position, $sorted_keys, true ) ); 78 } 79 80 $sorted[ $position ] = $button; 81 } 82 83 ksort( $sorted ); 84 return $sorted; 85 } 86 87 /** 88 * Get the BuddyPress buttons for the group 89 * 90 * @since 3.0.0 91 * 92 * @param bool $sort whether to sort the buttons or not. 93 * 94 * @return array An array of HTML links. 95 */ 96 public function get( $sort = true ) { 97 $buttons = array(); 98 99 if ( empty( $this->group ) ) { 100 return $buttons; 101 } 102 103 if ( true === $sort ) { 104 $this->group = $this->sort( $this->group ); 105 } 106 107 foreach ( $this->group as $key_button => $button ) { 108 // Reindex with ids. 109 if ( true === $sort ) { 110 $this->group[ $button['id'] ] = $button; 111 unset( $this->group[ $key_button ] ); 112 } 113 114 $buttons[ $button['id'] ] = bp_get_button( $button ); 115 } 116 117 return $buttons; 118 } 119 120 /** 121 * Update the group of buttons 122 * 123 * @since 3.0.0 124 * 125 * @param array $args Optional. See the __constructor for a description of this argument. 126 */ 127 public function update( $args = array() ) { 128 foreach ( $args as $id => $params ) { 129 if ( isset( $this->group[ $id ] ) ) { 130 $this->group[ $id ] = bp_parse_args( 131 $params, 132 $this->group[ $id ], 133 'buttons_group_update' 134 ); 135 } else { 136 $this->add( $params ); 137 } 138 } 139 } 140 141 /** 142 * Adds a button. 143 * 144 * @since 9.0.0 145 * 146 * @param array $args Required. See the __constructor for a description of this argument. 147 * @return bool true on success, false on failure to add. 148 */ 149 private function add( $args ) { 150 $r = bp_parse_args( 151 (array) $args, 152 array( 153 'id' => '', 154 'position' => 99, 155 'component' => '', 156 'must_be_logged_in' => true, 157 'block_self' => false, 158 'parent_element' => false, 159 'parent_attr' => array(), 160 'button_element' => 'a', 161 'button_attr' => array(), 162 'link_text' => '', 163 ), 164 'buttons_group_constructor' 165 ); 166 167 // Just don't set the button if a param is missing 168 if ( empty( $r['id'] ) || empty( $r['component'] ) || empty( $r['link_text'] ) ) { 169 return false; 170 } 171 172 $r['id'] = sanitize_key( $r['id'] ); 173 174 // If the button already exist don't add it 175 if ( isset( $this->group[ $r['id'] ] ) ) { 176 return false; 177 } 178 179 /* 180 * If, in bp_nouveau_get_*_buttons(), we pass through a false value for 'parent_element' 181 * but we have attributtes for it in the array, let's default to setting a div. 182 * 183 * Otherwise, the original false value will be passed through to BP buttons. 184 * @todo: this needs review, probably trying to be too clever 185 */ 186 if ( ( ! empty( $r['parent_attr'] ) ) && false === $r['parent_element'] ) { 187 $r['parent_element'] = 'div'; 188 } 189 190 $this->group[ $r['id'] ] = $r; 191 return true; 192 } 193 } -
src/bp-templates/bp-nouveau/includes/classes/class-bp-nouveau-object-nav-widget.php
diff --git src/bp-templates/bp-nouveau/includes/classes/class-bp-nouveau-object-nav-widget.php src/bp-templates/bp-nouveau/includes/classes/class-bp-nouveau-object-nav-widget.php index e69de29bb..a5c5d4a0a 100644
1 <?php 2 /** 3 * BP Sidebar Item Nav_Widget class. 4 * 5 * @since 3.0.0 6 * @version 10.0.0 7 */ 8 9 // Exit if accessed directly. 10 defined( 'ABSPATH' ) || exit; 11 12 /** 13 * BP Sidebar Item Nav_Widget. 14 * 15 * Adds a widget to move avatar/item nav into the sidebar. 16 * 17 * @since 3.0.0 18 */ 19 class BP_Nouveau_Object_Nav_Widget extends WP_Widget { 20 /** 21 * Constructor 22 * 23 * @since 3.0.0 24 * @since 9.0.0 Adds the `show_instance_in_rest` property to Widget options. 25 */ 26 public function __construct() { 27 $widget_ops = array( 28 'description' => __( 'Displays BuddyPress primary nav in the sidebar of your site. Make sure to use it as the first widget of the sidebar and only once.', 'buddypress' ), 29 'classname' => 'widget_nav_menu buddypress_object_nav', 30 'show_instance_in_rest' => true, 31 ); 32 33 parent::__construct( 34 'bp_nouveau_sidebar_object_nav_widget', 35 __( '(BuddyPress) Primary navigation', 'buddypress' ), 36 $widget_ops 37 ); 38 } 39 40 /** 41 * Register the widget 42 * 43 * @since 3.0.0 44 */ 45 public static function register_widget() { 46 register_widget( 'BP_Nouveau_Object_Nav_Widget' ); 47 } 48 49 /** 50 * Displays the output, the button to post new support topics 51 * 52 * @since 3.0.0 53 * 54 * @param mixed $args Arguments 55 * @param unknown $instance 56 */ 57 public function widget( $args, $instance ) { 58 if ( ! is_buddypress() || bp_is_group_create() ) { 59 return; 60 } 61 62 /** 63 * Filters the nav widget args for the BP_Nouveau_Object_Nav_Widget widget. 64 * 65 * @since 3.0.0 66 * 67 * @param array $value Array of arguments { 68 * @param bool $bp_nouveau_widget_title Whether or not to assign a title for the widget. 69 * } 70 */ 71 $item_nav_args = bp_parse_args( 72 $instance, 73 apply_filters( 74 'bp_nouveau_object_nav_widget_args', 75 array( 'bp_nouveau_widget_title' => true ) 76 ), 77 'widget_object_nav' 78 ); 79 80 $title = ''; 81 82 if ( ! empty( $item_nav_args['bp_nouveau_widget_title'] ) ) { 83 if ( bp_is_group() ) { 84 $title = bp_get_current_group_name(); 85 } elseif ( bp_is_user() ) { 86 $title = bp_get_displayed_user_fullname(); 87 } elseif ( bp_get_directory_title( bp_current_component() ) ) { 88 $title = bp_get_directory_title( bp_current_component() ); 89 } 90 } 91 92 /** 93 * Filters the BP_Nouveau_Object_Nav_Widget widget title. 94 * 95 * @since 3.0.0 96 * 97 * @param string $title The widget title. 98 * @param array $instance The settings for the particular instance of the widget. 99 * @param string $id_base Root ID for all widgets of this type. 100 */ 101 $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); 102 103 echo $args['before_widget']; 104 105 if ( ! empty( $title ) ) { 106 echo $args['before_title'] . $title . $args['after_title']; 107 } 108 109 if ( bp_is_user() ) { 110 bp_get_template_part( 'members/single/parts/item-nav' ); 111 } elseif ( bp_is_group() ) { 112 bp_get_template_part( 'groups/single/parts/item-nav' ); 113 } elseif ( bp_is_directory() ) { 114 bp_get_template_part( 'common/nav/directory-nav' ); 115 } 116 117 echo $args['after_widget']; 118 } 119 120 /** 121 * Update the new support topic widget options (title) 122 * 123 * @since 3.0.0 124 * 125 * @param array $new_instance The new instance options 126 * @param array $old_instance The old instance options 127 * 128 * @return array the instance 129 */ 130 public function update( $new_instance, $old_instance ) { 131 $instance = $old_instance; 132 $instance['bp_nouveau_widget_title'] = (bool) $new_instance['bp_nouveau_widget_title']; 133 134 return $instance; 135 } 136 137 /** 138 * Output the new support topic widget options form 139 * 140 * @since 3.0.0 141 * 142 * @param $instance Instance 143 * 144 * @return string HTML Output 145 */ 146 public function form( $instance ) { 147 $defaults = array( 148 'bp_nouveau_widget_title' => true, 149 ); 150 151 $instance = bp_parse_args( 152 (array) $instance, 153 $defaults, 154 'widget_object_nav_form' 155 ); 156 157 $bp_nouveau_widget_title = (bool) $instance['bp_nouveau_widget_title']; 158 ?> 159 160 <p> 161 <input class="checkbox" type="checkbox" <?php checked( $bp_nouveau_widget_title, true ); ?> id="<?php echo $this->get_field_id( 'bp_nouveau_widget_title' ); ?>" name="<?php echo $this->get_field_name( 'bp_nouveau_widget_title' ); ?>" /> 162 <label for="<?php echo $this->get_field_id( 'bp_nouveau_widget_title' ); ?>"><?php esc_html_e( 'Include navigation title', 'buddypress' ); ?></label> 163 </p> 164 165 <?php 166 } 167 }