Changeset 12997
- Timestamp:
- 07/14/2021 01:50:38 AM (4 years ago)
- Location:
- trunk/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/bp-core-template.php
r12934 r12997 3857 3857 return $salutation; 3858 3858 } 3859 3860 /** 3861 * Checks if a Widget/Block is active. 3862 * 3863 * @since 9.0.0 3864 * 3865 * @param string $block_name The Block name to check (eg: 'bp/sitewide-notices'). Optional. 3866 * @param string $widget_id_base The Widget ID base to check (eg: 'bp_messages_sitewide_notices_widget' ). Optional. 3867 * @return boolean True if the Widget/Block is active. False otherwise. 3868 */ 3869 function bp_is_widget_block_active( $block_name = '', $widget_id_base = '' ) { 3870 $is_active = array( 3871 'widget' => false, 3872 'block' => false, 3873 ); 3874 3875 if ( $block_name ) { 3876 $widget_blocks = get_option( 'widget_block', array() ); 3877 $sidebars = wp_get_sidebars_widgets(); 3878 3879 if ( ! $widget_blocks || ! $sidebars ) { 3880 return false; 3881 } 3882 3883 // Neutralize inactive sidebar. 3884 unset( $sidebars['wp_inactive_widgets'] ); 3885 3886 $widgets_content = ''; 3887 foreach ( $widget_blocks as $key => $widget_block ) { 3888 $widget_block_reference = 'block-' . $key; 3889 3890 if ( ! isset( $widget_block['content'] ) || ! $widget_block['content'] ) { 3891 continue; 3892 } 3893 3894 foreach ( $sidebars as $sidebar ) { 3895 if ( is_array( $sidebar ) && in_array( $widget_block_reference, $sidebar, true ) ) { 3896 $widgets_content .= $widget_block['content'] . "\n"; 3897 } 3898 } 3899 } 3900 3901 $is_active['block'] = has_block( $block_name, $widgets_content ); 3902 } 3903 3904 if ( $widget_id_base ) { 3905 $is_active['widget'] = is_active_widget( false, false, $widget_id_base, true ); 3906 } 3907 3908 return 0 !== count( array_filter( $is_active ) ); 3909 } -
trunk/src/bp-friends/classes/class-bp-core-friends-widget.php
r12991 r12997 33 33 parent::__construct( false, $name = _x( '(BuddyPress) Friends', 'widget name', 'buddypress' ), $widget_ops ); 34 34 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 ) ) { 36 36 add_action( 'bp_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); 37 37 } -
trunk/src/bp-groups/classes/class-bp-groups-widget.php
r12976 r12997 33 33 parent::__construct( false, _x( '(BuddyPress) Groups', 'widget name', 'buddypress' ), $widget_ops ); 34 34 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 ) ) { 36 36 add_action( 'bp_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); 37 37 } -
trunk/src/bp-members/classes/class-bp-core-members-widget.php
r12976 r12997 38 38 ) ); 39 39 40 if ( is_customize_preview() || is_active_widget( false, false, $this->id_base ) ) {40 if ( is_customize_preview() || bp_is_widget_block_active( '', $this->id_base ) ) { 41 41 add_action( 'bp_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); 42 42 } -
trunk/src/bp-templates/bp-legacy/buddypress-functions.php
r12989 r12997 125 125 // Only hook the 'sitewide_notices' overlay if the Sitewide 126 126 // Notices widget is not in use (to avoid duplicate content). 127 if ( bp_is_active( 'messages' ) && ! is_active_widget( false, false, 'bp_messages_sitewide_notices_widget', true ) ) {127 if ( bp_is_active( 'messages' ) && ! bp_is_widget_block_active( 'bp/sitewide-notices', 'bp_messages_sitewide_notices_widget', true ) ) { 128 128 add_action( 'wp_footer', array( $this, 'sitewide_notices' ), 9999 ); 129 129 } -
trunk/src/bp-templates/bp-nouveau/includes/functions.php
r12947 r12997 376 376 */ 377 377 function bp_nouveau_is_object_nav_in_sidebar() { 378 return is_active_widget( false, false, 'bp_nouveau_sidebar_object_nav_widget', true);378 return bp_is_widget_block_active( 'bp/primary-nav', 'bp_nouveau_sidebar_object_nav_widget' ); 379 379 } 380 380
Note: See TracChangeset
for help on using the changeset viewer.