Skip to content

Conversation

@westonruter
Copy link
Owner

This PR defines the block attributes centrally in PHP. This allows for plugins to easily change the default values for a block's attributes. For example, if a site wants all blocks to have wrapped lines and have PHP selected by default, they can do so with this code:

add_action( 'init', function() {
	$block_type = WP_Block_Type_Registry::get_instance()->get_registered( 'core/code' );
	$block_type->attributes['language']['default'] = 'php';
	$block_type->attributes['wrapLines']['default'] = true;
} );

The great thing about this is that the defaults will be reflected in the editor and for every instance of the generic Code block already created when rendered on the frontend.

This PR also removes obsolete deprecated block definition which is now only relevant in mkaz/code-syntax-block.

Copy link
Contributor

@allejo allejo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love this! Didn't realize you could define settings centrally in PHP. Should your example code this be added to the README?

@westonruter
Copy link
Owner Author

Yes, I was thinking we should create a wiki page here in GitHub with those extensibility examples.

@westonruter westonruter merged commit 7ccf445 into master Apr 26, 2020
@westonruter westonruter deleted the update/attributes branch April 26, 2020 23:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants