-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix allowed_block_types regression (#14229)
- Loading branch information
1 parent
44c58b8
commit 357175f
Showing
4 changed files
with
62 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
/** | ||
* Plugin Name: Gutenberg Test Allowed Blocks | ||
* Plugin URI: https://github.com/WordPress/gutenberg | ||
* Author: Gutenberg Team | ||
* | ||
* @package gutenberg-test-allowed-blocks | ||
*/ | ||
|
||
/** | ||
* Restrict the allowed blocks in the editor. | ||
* | ||
* @param Array $allowed_block_types An array of strings containing the previously allowed blocks. | ||
* @param WP_Post $post The current post object. | ||
* @return Array An array of strings containing the new allowed blocks after the filter is applied. | ||
*/ | ||
function my_plugin_allowed_block_types( $allowed_block_types, $post ) { | ||
if ( 'post' !== $post->post_type ) { | ||
return $allowed_block_types; | ||
} | ||
return array( 'core/paragraph', 'core/image' ); | ||
} | ||
|
||
add_filter( 'allowed_block_types', 'my_plugin_allowed_block_types', 10, 2 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
activatePlugin, | ||
createNewPost, | ||
deactivatePlugin, | ||
searchForBlock, | ||
} from '@wordpress/e2e-test-utils'; | ||
|
||
describe( 'Allowed Blocks Filter', () => { | ||
beforeAll( async () => { | ||
await activatePlugin( 'gutenberg-test-allowed-blocks' ); | ||
} ); | ||
|
||
beforeEach( async () => { | ||
await createNewPost(); | ||
} ); | ||
|
||
afterAll( async () => { | ||
await deactivatePlugin( 'gutenberg-test-allowed-blocks' ); | ||
} ); | ||
|
||
it( 'should restrict the allowed blocks in the inserter', async () => { | ||
// The paragraph block is available. | ||
await searchForBlock( 'Paragraph' ); | ||
const paragraphBlock = await page.$( `button[aria-label="Paragraph"]` ); | ||
expect( paragraphBlock ).not.toBeNull(); | ||
await paragraphBlock.click(); | ||
|
||
// The gallery block is not available. | ||
await searchForBlock( 'Gallery' ); | ||
const galleryBlock = await page.$( `button[aria-label="Gallery"]` ); | ||
expect( galleryBlock ).toBeNull(); | ||
} ); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters