Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
07/14/2021 01:50:38 AM (3 years ago)
Author:
imath
Message:

Add a new function to check if a Widget/Block is active into a sidebar

Some of our Legacy Widgets are being displayed only if active they have been included into a Sidebar Widget. We are using the is_active_widget() WordPress function to check whether it is the case or not. This function doesn't fit in the Widget Blocks case as all Blocks are being inserted into the specific WP_Widget_Block widget.

As WordPress 5.8 doesn't provide any equivalent (so far?), we are introducing a new function to do this check: bp_is_widget_block_active(). It takes 2 optional arguments.

  • $block_name: the name of the block you need to check (eg: 'bp/members').
  • $widget_id_base: the Base ID of the widget (eg: 'bp_messages_sitewide_notices_widget').

You can use it to check a block, a widget or both.

Fixes #8515

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-friends/classes/class-bp-core-friends-widget.php

    r12991 r12997  
    3333        parent::__construct( false, $name = _x( '(BuddyPress) Friends', 'widget name', 'buddypress' ), $widget_ops );
    3434
    35         if ( is_customize_preview() || is_active_widget( false, false, $this->id_base ) ) {
     35        if ( is_customize_preview() || bp_is_widget_block_active( '', $this->id_base ) ) {
    3636            add_action( 'bp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
    3737        }
Note: See TracChangeset for help on using the changeset viewer.