Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extensibility: Pass the post object to allowed_block_types filter #6208

Merged
merged 1 commit into from
Apr 17, 2018

Conversation

gziolo
Copy link
Member

@gziolo gziolo commented Apr 16, 2018

Description

Closes #2685.

This PR open an access to the current post to the allowed_block_types filter to make it possible to provide a different set of allowed block types per post type or based on other properties.

How has this been tested?

Manually added the following filter:

function my_test_allowed_block_types( $allowed_block_types, $post ) {
	if ( $post->post_type === 'post' ) {
		return $allowed_block_types;
	}
	return [ 'core/paragraph' ];
}
	
add_filter( 'allowed_block_types', 'my_test_allowed_block_types', 10, 2 );

Types of changes

Improvement.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.

@gziolo gziolo added [Feature] Blocks Overall functionality of blocks [Feature] Extensibility The ability to extend blocks or the editing experience labels Apr 16, 2018
@gziolo gziolo self-assigned this Apr 16, 2018
@gziolo gziolo force-pushed the update/extensibility-allowed-block-types branch from 1aa6a05 to f92b60f Compare April 16, 2018 13:36
@gziolo
Copy link
Member Author

gziolo commented Apr 16, 2018

@zgordon - can you give it a try?

@gziolo gziolo requested a review from a team April 16, 2018 13:43
@zgordon
Copy link

zgordon commented Apr 16, 2018

@gziolo do I just pill down latest Master to try this?

@gziolo
Copy link
Member Author

gziolo commented Apr 16, 2018

Rather this branch: update/extensibility-allowed-block-types.

@@ -937,8 +937,9 @@ function gutenberg_editor_scripts_and_styles( $hook ) {
*
* @param bool|array $allowed_block_types Array of block type slugs, or
* boolean to enable/disable all.
* @param object The post resource data.
Copy link
Member

@noisysocks noisysocks Apr 17, 2018

Choose a reason for hiding this comment

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

This @param comment is missing the name of the argument.

(It's weird that the linter didn't yell about this.)

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not a function, so it's tricky for both human and computer. I updated :)

Copy link
Member

@noisysocks noisysocks left a comment

Choose a reason for hiding this comment

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

👍 nice. This looks good to me once that @param is fixed up.

@zgordon
Copy link

zgordon commented Apr 17, 2018

Sweet! @gziolo can confirm it's working for me as expected :)

@gziolo gziolo force-pushed the update/extensibility-allowed-block-types branch from f92b60f to 5b4000e Compare April 17, 2018 05:48
@gziolo gziolo merged commit 1ba33b2 into master Apr 17, 2018
@gziolo gziolo deleted the update/extensibility-allowed-block-types branch April 17, 2018 05:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Blocks Overall functionality of blocks [Feature] Extensibility The ability to extend blocks or the editing experience
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants