Changeset 13153 for trunk/src/bp-core/bp-core-widgets.php
- Timestamp:
- 11/19/2021 05:03:56 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/bp-core-widgets.php
r11366 r13153 12 12 13 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 51 /** 14 52 * Register bp-core widgets. 15 53 * … … 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 );
Note: See TracChangeset
for help on using the changeset viewer.