Skip to:
Content

BuddyPress.org

Changeset 12578


Ignore:
Timestamp:
03/25/2020 07:31:07 AM (6 years ago)
Author:
imath
Message:

Introduce the BP Blocks API into BP Core

  • The BP_Block class is wrapping the WP_Block_Type one to manage JavaScript and CSS assets registration and script translations.
  • To register a new BP Block, we are introducing a new function using this BP_Block class : bp_register_block().
  • Registering BP Blocks needs to happen hooking the bp_blocks_init action.
  • The BP_Component class now includes a new method BuddyPress components can use to register their blocks. It also makes sure this method is only usable if the BP REST API is available.
  • The dynamic filter bp_{component_id}_register_blocks let developers add or disable BP component blocks.
  • A dynamic action bp_{component_id}_blocks_init is fired once all corresponding BP component blocks has been registered.
  • The bp_blocks_editor_settings filter is gathering specific BuddyPress editor settings into a bp object.

See #8048

Location:
trunk/src
Files:
2 added
4 edited

Legend:

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

    r11936 r12578  
    7676add_action( 'bp_init', 'bp_setup_nav',               6  );
    7777add_action( 'bp_init', 'bp_setup_title',             8  );
     78add_action( 'bp_init', 'bp_blocks_init',             10 );
    7879add_action( 'bp_init', 'bp_core_load_admin_bar_css', 12 );
    7980add_action( 'bp_init', 'bp_add_rewrite_tags',        20 );
  • trunk/src/bp-core/bp-core-dependency.php

    r12545 r12578  
    269269
    270270/**
     271 * BP Blocks Init hook.
     272 *
     273 * @since 6.0.0
     274 */
     275function bp_blocks_init() {
     276    /**
     277     * Hook here to register your BuddyPress blocks.
     278     *
     279     * @since 6.0.0
     280     */
     281    do_action( 'bp_blocks_init' );
     282}
     283
     284/**
    271285 * Fire the 'bp_customize_register' action when the Customizer has loaded,
    272286 * allowing scripts and styles to be initialized.
  • trunk/src/bp-core/classes/class-bp-component.php

    r12547 r12578  
    467467        }
    468468
     469        // Register BP Blocks.
     470        if ( bp_rest_api_is_available() ) {
     471            add_action( 'bp_blocks_init', array( $this, 'blocks_init' ), 10 );
     472        }
     473
    469474        /**
    470475         * Fires at the end of the setup_actions method inside BP_Component.
     
    907912        do_action( 'bp_' . $this->id . '_rest_api_init' );
    908913    }
     914
     915    /**
     916     * Register the BP Blocks.
     917     *
     918     * @since 6.0.0
     919     *
     920     * @param array $blocks The list of BP Blocks to register.
     921     */
     922    public function blocks_init( $blocks = array() ) {
     923        if ( is_array( $blocks ) && $blocks ) {
     924            /**
     925             * Filter here to disable all or some BP Blocks for a component.
     926             *
     927             * This is a dynamic hook that is based on the component string ID.
     928             *
     929             * @since 6.0.0
     930             *
     931             * @param array $blocks The list of BP Blocks for the component.
     932             */
     933            $blocks = (array) apply_filters( 'bp_' . $this->id . '_register_blocks', $blocks );
     934
     935            foreach ( $blocks as $block ) {
     936                bp_register_block( $block );
     937            }
     938        }
     939
     940        /**
     941         * Fires in the blocks_init method inside BP_Component.
     942         *
     943         * This is a dynamic hook that is based on the component string ID.
     944         *
     945         * @since 6.0.0
     946         */
     947        do_action( 'bp_' . $this->id . '_blocks_init' );
     948    }
    909949}
    910950endif; // BP_Component.
  • trunk/src/class-buddypress.php

    r12568 r12578  
    489489        require( $this->plugin_dir . 'bp-core/bp-core-customizer-email.php' );
    490490        require( $this->plugin_dir . 'bp-core/bp-core-rest-api.php'         );
     491        require( $this->plugin_dir . 'bp-core/bp-core-blocks.php'           );
    491492
    492493        // Maybe load deprecated functionality (this double negative is proof positive!).
     
    555556            'BP_Attachment'                              => 'core',
    556557            'BP_Button'                                  => 'core',
     558            'BP_Block'                                   => 'core',
    557559            'BP_Component'                               => 'core',
    558560            'BP_Customizer_Control_Range'                => 'core',
Note: See TracChangeset for help on using the changeset viewer.