Skip to:
Content

BuddyPress.org

Ticket #8515: 8515.patch

File 8515.patch, 5.1 KB (added by imath, 5 years ago)
  • src/bp-core/bp-core-template.php

    diff --git src/bp-core/bp-core-template.php src/bp-core/bp-core-template.php
    index d3ffae013..f5655279e 100644
    function bp_email_the_salutation( $settings = array() ) {  
    38563856
    38573857                return $salutation;
    38583858        }
     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 */
     3869function 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}
  • src/bp-friends/classes/class-bp-core-friends-widget.php

    diff --git src/bp-friends/classes/class-bp-core-friends-widget.php src/bp-friends/classes/class-bp-core-friends-widget.php
    index b264b9f80..bb945714e 100644
    class BP_Core_Friends_Widget extends WP_Widget {  
    3232                );
    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                }
    3838        }
  • src/bp-groups/classes/class-bp-groups-widget.php

    diff --git src/bp-groups/classes/class-bp-groups-widget.php src/bp-groups/classes/class-bp-groups-widget.php
    index d539355d7..ed615e89b 100644
    class BP_Groups_Widget extends WP_Widget {  
    3232                );
    3333                parent::__construct( false, _x( '(BuddyPress) Groups', '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                }
    3838        }
  • src/bp-members/classes/class-bp-core-members-widget.php

    diff --git src/bp-members/classes/class-bp-core-members-widget.php src/bp-members/classes/class-bp-core-members-widget.php
    index 63d8b2072..8cbae5b20 100644
    class BP_Core_Members_Widget extends WP_Widget {  
    3737                        'show_instance_in_rest'       => true,
    3838                ) );
    3939
    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 ) ) {
    4141                        add_action( 'bp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
    4242                }
    4343        }
  • src/bp-templates/bp-legacy/buddypress-functions.php

    diff --git src/bp-templates/bp-legacy/buddypress-functions.php src/bp-templates/bp-legacy/buddypress-functions.php
    index 2316ab487..3a1a43556 100644
    class BP_Legacy extends BP_Theme_Compat {  
    124124
    125125                // Only hook the 'sitewide_notices' overlay if the Sitewide
    126126                // 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 ) ) {
    128128                        add_action( 'wp_footer', array( $this, 'sitewide_notices' ), 9999 );
    129129                }
    130130
  • src/bp-templates/bp-nouveau/includes/functions.php

    diff --git src/bp-templates/bp-nouveau/includes/functions.php src/bp-templates/bp-nouveau/includes/functions.php
    index abbca46ca..77c1f93ef 100644
    function bp_nouveau_register_sidebars() {  
    375375 * @return bool
    376376 */
    377377function 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' );
    379379}
    380380
    381381/**