Skip to:
Content

BuddyPress.org

Ticket #8625: 8625.01.patch

File 8625.01.patch, 2.0 KB (added by r-a-y, 3 years ago)
  • src/bp-core/bp-core-widgets.php

     
    1414 * Should BuddyPress load Legacy Widgets?
    1515 *
    1616 * @since 10.0.0
     17 * @deprecated
    1718 *
    1819 * @return bool False if BuddyPress shouldn't load Legacy Widgets. True otherwise.
    1920 */
     
    6465 * @since 10.0.0
    6566 */
    6667function bp_core_maybe_unhook_legacy_widgets() {
    67         if ( bp_core_retain_legacy_widgets() ) {
    68                 return;
    69         }
    70 
    7168        $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',
     69                'BP_Core_Login_Widget',
     70                'BP_Core_Members_Widget',
     71                'BP_Core_Whos_Online_Widget',
     72                'BP_Core_Recently_Active_Widget',
    7673        );
    7774
    7875        if ( bp_is_active( 'friends' ) ) {
    79                 $callbacks[] = 'bp_friends_register_friends_widget';
     76                $callbacks[] = 'BP_Core_Friends_Widget';
    8077        }
    8178
    8279        if ( bp_is_active( 'groups' ) ) {
    83                 $callbacks[] = 'bp_groups_register_groups_widget';
     80                $callbacks[] = 'BP_Groups_Widget';
    8481        }
    8582
    8683        if ( bp_is_active( 'messages' ) ) {
    87                 $callbacks[] = 'bp_messages_register_sitewide_notices_widget';
     84                $callbacks[] = 'BP_Messages_Sitewide_Notices_Widget';
    8885        }
    8986
    9087        if ( bp_is_active( 'blogs' ) && bp_is_active( 'activity' ) && bp_is_root_blog() ) {
    91                 $callbacks[] = 'bp_blogs_register_recent_posts_widget';
     88                $callbacks[] = 'BP_Blogs_Recent_Posts_Widget';
    9289        }
    9390
    94         foreach ( $callbacks as $callback ) {
    95                 remove_action( 'widgets_init', $callback );
     91        // Widget base is the callback in lowercase letters. Sigh.
     92        $legacy_widgets_base = array_map( 'strtolower', $callbacks );
     93
     94        foreach ( $legacy_widgets_base as $key => $widget_base ) {
     95                if ( ! is_active_widget( false, false, $widget_base ) ) {
     96                        unregister_widget( $callbacks[ $key ] );
     97                }
    9698        }
    9799}
    98 add_action( 'widgets_init', 'bp_core_maybe_unhook_legacy_widgets', 0 );
     100add_action( 'widgets_init', 'bp_core_maybe_unhook_legacy_widgets', 20 );