Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
05/17/2023 11:14:06 AM (22 months ago)
Author:
imath
Message:

Deprecate BP Legacy widgets

Deprecate all classes, functions, JavaScripts and files related to Legacy Widgets. Legacy Widgets are now available from the BP Classic plugin.

See #8869
Closes https://github.com/buddypress/buddypress/pull/99

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/bp-core-widgets.php

    r13417 r13481  
    66 * @subpackage Core
    77 * @since 1.0.0
     8 * @deprecated 12.0.0
    89 */
    910
     
    1112defined( 'ABSPATH' ) || exit;
    1213
    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 
    23     /** This filter is documented in wp-includes/widgets.php */
    24     $block_widgets_enabled = $theme_supports && apply_filters( 'use_widgets_block_editor', true );
    25 
    26     $retain_legacy_widgets = true;
    27     if ( $block_widgets_enabled ) {
    28         $retain_legacy_widgets = false;
    29     }
    30 
    31     /**
    32      * Filter here to force Legacy Widgets to be retained or not.
    33      *
    34      * @since 10.0.0
    35      *
    36      * @param bool $retain_legacy_widgets False if BuddyPress shouldn't load Legacy Widgets. True otherwise.
    37      */
    38     return apply_filters( 'bp_core_retain_legacy_widgets', $retain_legacy_widgets );
    39 }
    40 
    41 /**
    42  * Registers the Login widget.
    43  *
    44  * @since 10.0.0
    45  */
    46 function bp_core_register_login_widget() {
    47     register_widget( 'BP_Core_Login_Widget' );
    48 }
    49 
    50 /**
    51  * Register bp-core widgets.
    52  *
    53  * @since 1.0.0
    54  */
    55 function bp_core_register_widgets() {
    56     add_action( 'widgets_init', 'bp_core_register_login_widget' );
    57 }
    58 add_action( 'bp_register_widgets', 'bp_core_register_widgets' );
    59 
    60 /**
    61  * Checks whether BuddyPress should unhook Legacy Widget registrations.
    62  *
    63  * @since 10.0.0
    64  */
    65 function bp_core_maybe_unhook_legacy_widgets() {
    66     if ( bp_core_retain_legacy_widgets() ) {
    67         return;
    68     }
    69 
    70     $callbacks = array(
    71         'BP_Core_Login_Widget'           => 'bp_core_register_login_widget',
    72         'BP_Core_Members_Widget'         => 'bp_members_register_members_widget',
    73         'BP_Core_Whos_Online_Widget'     => 'bp_members_register_whos_online_widget',
    74         'BP_Core_Recently_Active_Widget' => 'bp_members_register_recently_active_widget',
    75     );
    76 
    77     if ( bp_is_active( 'friends' ) ) {
    78         $callbacks['BP_Core_Friends_Widget'] = 'bp_friends_register_friends_widget';
    79     }
    80 
    81     if ( bp_is_active( 'groups' ) ) {
    82         $callbacks['BP_Groups_Widget'] = 'bp_groups_register_groups_widget';
    83     }
    84 
    85     if ( bp_is_active( 'messages' ) ) {
    86         $callbacks['BP_Messages_Sitewide_Notices_Widget'] = 'bp_messages_register_sitewide_notices_widget';
    87     }
    88 
    89     if ( bp_is_active( 'blogs' ) && bp_is_active( 'activity' ) && bp_is_root_blog() ) {
    90         $callbacks['BP_Blogs_Recent_Posts_Widget'] = 'bp_blogs_register_recent_posts_widget';
    91     }
    92 
    93     foreach ( $callbacks as $widget_id => $callback ) {
    94         $widget_base = strtolower( $widget_id );
    95 
    96         // If there's an active widget, we need to carry on loading it.
    97         if ( is_active_widget( false, false, $widget_base ) ) {
    98             continue;
    99         }
    100 
    101         remove_action( 'widgets_init', $callback );
    102     }
    103 }
    104 add_action( 'widgets_init', 'bp_core_maybe_unhook_legacy_widgets', 0 );
     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' ) );
Note: See TracChangeset for help on using the changeset viewer.