Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
07/14/2021 08:52:00 AM (5 years ago)
Author:
imath
Message:

Introduce a new BP_Component property for block globals

This new property will help us to manage Widget Block occurrences globals and use a single filter on 'widget_block_dynamic_classname' to make sure Widget Blocks will include Legacy Widget classnames and inherit their styles.

This commit also makes sure WordPress is >= 5.0 before using the has_block function.

See #8515
Fixes #8516

File:
1 edited

Legend:

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

    r12994 r12998  
    140140     */
    141141    public $search_query_arg = 's';
     142
     143    /**
     144     * An array of globalized data for BP Blocks.
     145     *
     146     * @since 9.0.0
     147     *
     148     * @var array
     149     */
     150    public $block_globals = array();
    142151
    143152    /** Methods ***************************************************************/
     
    206215     *
    207216     * @since 1.5.0
    208      *
     217     * @since 9.0.0 Adds the `$block_globals` argument to the `$args` parameter.
    209218     *
    210219     * @param array $args {
     
    222231     *     @type array    $global_tables         Optional. An array of database table names.
    223232     *     @type array    $meta_tables           Optional. An array of metadata table names.
     233     *     @type array    $block_globals         Optional. An array of globalized data for BP Blocks.
    224234     * }
    225235     */
     
    242252            'global_tables'         => '',
    243253            'meta_tables'           => '',
     254            'block_globals'         => array(),
    244255        ) );
    245256
     
    306317        if ( ! empty( $r['meta_tables'] ) ) {
    307318            $this->register_meta_tables( $r['meta_tables'] );
     319        }
     320
     321        /**
     322         * Filters the $blocks global value.
     323         *
     324         * @since 9.0.0
     325         *
     326         * @param array $blocks a list of global properties for blocks keyed
     327         *                      by their corresponding block name.
     328         */
     329        $block_globals = apply_filters( 'bp_' . $this->id . '_block_globals', $r['block_globals'] );
     330        if ( is_array( $block_globals ) && array_filter( $block_globals ) ) {
     331            foreach ( $block_globals as $block_name => $block_props ) {
     332                $this->block_globals[ $block_name ] = new stdClass();
     333
     334                // Initialize an `items` property for Widget Block occurrences.
     335                $this->block_globals[ $block_name ]->items = array();
     336
     337                // Set the global properties for the Block.
     338                $this->block_globals[ $block_name ]->props = (array) $block_props;
     339            }
    308340        }
    309341
Note: See TracChangeset for help on using the changeset viewer.