Make WordPress Core


Ignore:
Timestamp:
07/01/2020 01:08:11 PM (5 years ago)
Author:
gziolo
Message:

Editor: Support filtering arguments in block type registration

Adds possibility to filter the settings of a block type during its registration.

Props aduth, azaozz.
Fixes #49615.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/blocks/register.php

    r48141 r48263  
    381381        $this->assertFalse( has_blocks( $content ) );
    382382    }
     383
     384    /**
     385     * @ticket 49615
     386     */
     387    public function test_filter_block_registration() {
     388        $filter_registration = function( $args, $name ) {
     389            $args['attributes'] = array( $name => array( 'type' => 'boolean' ) );
     390            return $args;
     391        };
     392
     393        add_filter( 'register_block_type_args', $filter_registration, 10, 2 );
     394        register_block_type( 'core/test-filtered', array() );
     395        remove_filter( 'register_block_type_args', $filter_registration );
     396
     397        $registry   = WP_Block_Type_Registry::get_instance();
     398        $block_type = $registry->get_registered( 'core/test-filtered' );
     399        $this->assertEquals( 'boolean', $block_type->attributes['core/test-filtered']['type'] );
     400    }
    383401}
Note: See TracChangeset for help on using the changeset viewer.