Skip to:
Content

BuddyPress.org

Changeset 12994


Ignore:
Timestamp:
07/12/2021 07:48:13 PM (4 years ago)
Author:
imath
Message:

Make sure all BP components init their BP Blocks

Even if some components don't have native BP Blocks, it makes it easier for developers to add their custom blocks or override existing BP Blocks or disable BP Blocks. Working on the BP Blocks feature as a plugin made us realize this.

This commit also improves the BP_Block constructor inline documentation, adds a new method to the Core component to register REST controllers and moves the BP_REST_Components_Endpoint one from the Members component to the Core component.

Fixes #8511

Location:
trunk
Files:
10 edited

Legend:

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

    r12670 r12994  
    380380        parent::rest_api_init( $controllers );
    381381    }
     382
     383    /**
     384     * Register the BP Blogs Blocks.
     385     *
     386     * @since 9.0.0
     387     *
     388     * @param array $blocks Optional. See BP_Component::blocks_init() for
     389     *                      description.
     390     */
     391    public function blocks_init( $blocks = array() ) {
     392        parent::blocks_init( array() );
     393    }
    382394}
  • trunk/src/bp-core/classes/class-bp-block.php

    r12661 r12994  
    4848     * @since 6.0.0
    4949     *
    50      * @param array $args The registration arguments for the BP Block.
     50     * @param array $args {
     51     *     The registration arguments for the BP Block. Part of the arguments are the ones
     52     *     used by `WP_Block_Type`. Below are BP specific arguments.
     53     *
     54     *     @type string $name               The name of the block (eg: `bp/member`).
     55     *     @type string $editor_script_url  URL to the JavaScript main file of the BP Block
     56     *                                      to load into the Block Editor.
     57     *     @type array  $editor_script_deps The list of JavaScript dependency handles for the
     58     *                                      BP Block main file.
     59     *     @type string $script_url         URL to the JavaScript file to load into the Block
     60     *                                      Editor and on front-end.
     61     *     @type array  $script_deps        The list of JavaScript dependency handles for the
     62     *                                      JavaScript file to load into the Block Editor and
     63     *                                      on front-end.
     64     *     @type string $editor_style_url   URL to the CSS main file of the BP Block to load
     65     *                                      into the Block Editor.
     66     *     @type array  $editor_style_deps  The list of CSS dependency handles for the
     67     *                                      CSS main file.
     68     *     @type string $style_url          URL to the CSS file to load into the Block Editor
     69     *                                      and on front-end.
     70     *     @type array  $style_deps         The list of CSS dependency handles for the CSS file
     71     *                                      to load into the Block Editor and on front-end.
     72     * }
    5173     */
    5274    public function __construct( $args ) {
  • trunk/src/bp-core/classes/class-bp-component.php

    r12581 r12994  
    918918     * @since 6.0.0
    919919     *
     920     * @see `BP_Block->construct()` for a full description of a BP Block arguments.
     921     *
    920922     * @param array $blocks The list of BP Blocks to register.
    921923     */
    922924    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 
     925        /**
     926         * Filter here to add new BP Blocks, disable some or all BP Blocks for a component.
     927         *
     928         * This is a dynamic hook that is based on the component string ID.
     929         *
     930         * @since 6.0.0
     931         *
     932         * @param array $blocks The list of BP Blocks for the component.
     933         */
     934        $blocks = (array) apply_filters( 'bp_' . $this->id . '_register_blocks', $blocks );
     935        $blocks = array_filter( $blocks );
     936
     937        if ( $blocks ) {
    935938            foreach ( $blocks as $block ) {
    936939                bp_register_block( $block );
  • trunk/src/bp-core/classes/class-bp-core.php

    r12753 r12994  
    352352        parent::register_post_types();
    353353    }
     354
     355    /**
     356     * Init the Core controllers of the BP REST API.
     357     *
     358     * @since 9.0.0
     359     *
     360     * @param array $controllers Optional. See BP_Component::rest_api_init() for
     361     *                           description.
     362     */
     363    public function rest_api_init( $controllers = array() ) {
     364        $controllers = array(
     365            'BP_REST_Components_Endpoint',
     366        );
     367
     368        parent::rest_api_init( $controllers );
     369    }
     370
     371    /**
     372     * Register the BP Core Blocks.
     373     *
     374     * @since 9.0.0
     375     *
     376     * @param array $blocks Optional. See BP_Component::blocks_init() for
     377     *                      description.
     378     */
     379    public function blocks_init( $blocks = array() ) {
     380        parent::blocks_init( array() );
     381    }
    354382}
  • trunk/src/bp-friends/classes/class-bp-friends-component.php

    r12670 r12994  
    338338        parent::rest_api_init( array( 'BP_REST_Friends_Endpoint' ) );
    339339    }
     340
     341    /**
     342     * Register the BP Friends Blocks.
     343     *
     344     * @since 9.0.0
     345     *
     346     * @param array $blocks Optional. See BP_Component::blocks_init() for
     347     *                      description.
     348     */
     349    public function blocks_init( $blocks = array() ) {
     350        parent::blocks_init( array() );
     351    }
    340352}
  • trunk/src/bp-members/classes/class-bp-members-component.php

    r12951 r12994  
    696696     * @since 5.0.0
    697697     * @since 6.0.0 Adds the Member Cover and Signup REST endpoints.
     698     * @since 9.0.0 Moves the `BP_REST_Components_Endpoint` controller in `BP_Core` component.
    698699     *
    699700     * @param array $controllers Optional. See BP_Component::rest_api_init() for
     
    702703    public function rest_api_init( $controllers = array() ) {
    703704        $controllers = array(
    704             /**
    705              * As the Members component is always loaded,
    706              * let's register the Components endpoint here.
    707              */
    708             'BP_REST_Components_Endpoint',
    709705            'BP_REST_Members_Endpoint',
    710706            'BP_REST_Attachments_Member_Avatar_Endpoint',
  • trunk/src/bp-messages/classes/class-bp-messages-component.php

    r12463 r12994  
    446446        parent::rest_api_init( array( 'BP_REST_Messages_Endpoint' ) );
    447447    }
     448
     449    /**
     450     * Register the BP Messages Blocks.
     451     *
     452     * @since 9.0.0
     453     *
     454     * @param array $blocks Optional. See BP_Component::blocks_init() for
     455     *                      description.
     456     */
     457    public function blocks_init( $blocks = array() ) {
     458        parent::blocks_init( array() );
     459    }
    448460}
  • trunk/src/bp-settings/classes/class-bp-settings-component.php

    r12745 r12994  
    293293        parent::setup_admin_bar( $wp_admin_nav );
    294294    }
     295
     296    /**
     297     * Register the BP Settings Blocks.
     298     *
     299     * @since 9.0.0
     300     *
     301     * @param array $blocks Optional. See BP_Component::blocks_init() for
     302     *                      description.
     303     */
     304    public function blocks_init( $blocks = array() ) {
     305        parent::blocks_init( array() );
     306    }
    295307}
  • trunk/src/bp-xprofile/classes/class-bp-xprofile-component.php

    r12869 r12994  
    457457        ) );
    458458    }
     459
     460    /**
     461     * Register the BP xProfile Blocks.
     462     *
     463     * @since 9.0.0
     464     *
     465     * @param array $blocks Optional. See BP_Component::blocks_init() for
     466     *                      description.
     467     */
     468    public function blocks_init( $blocks = array() ) {
     469        parent::blocks_init( array() );
     470    }
    459471}
  • trunk/tests/phpunit/testcases/core/class-bp-component.php

    r12607 r12994  
    3131
    3232        $this->assertSame( $bp->unit_test_rest->controllers, array(
    33             'BP_REST_Components_Endpoint',
    3433            'BP_REST_Members_Endpoint',
    3534            'BP_REST_Attachments_Member_Avatar_Endpoint',
     
    4948
    5049        $this->assertSame( $bp->unit_test_rest->controllers, array(
    51             'BP_REST_Components_Endpoint',
    5250            'BP_REST_Attachments_Member_Avatar_Endpoint',
    5351            'BP_REST_Attachments_Member_Cover_Endpoint',
     
    6664
    6765        $this->assertSame( $bp->unit_test_rest->controllers, array(
    68             'BP_REST_Components_Endpoint',
    6966            'BP_REST_Members_Endpoint',
    7067            'BP_REST_Attachments_Member_Avatar_Endpoint',
Note: See TracChangeset for help on using the changeset viewer.