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

Reusable Blocks: Preload user permissions #15061

Merged
merged 2 commits into from
Apr 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions lib/client-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -560,3 +560,32 @@ function gutenberg_extend_block_editor_styles( $settings ) {
return $settings;
}
add_filter( 'block_editor_settings', 'gutenberg_extend_block_editor_styles' );

/**
* Extends block editor preload paths to preload additional data. Note that any
* additions here should be complemented with a corresponding core ticket to
* reconcile the change upstream for future removal from Gutenberg.
*
* @since 5.6.0
*
* @param array $preload_paths $preload_paths Array of paths to preload.
*
* @return array Filtered array of paths to preload.
*/
function gutenberg_extend_block_editor_preload_paths( $preload_paths ) {
/*
* Used in considering user permissions for creating and updating blocks,
* as condition for displaying relevant actions in the interface.
*
* Trac ticket: https://core.trac.wordpress.org/ticket/46429
*
* This is present in WordPress 5.2 and should be removed from Gutenberg
* once WordPress 5.2 is the minimum supported version.
*/
if ( ! in_array( array( '/wp/v2/blocks', 'OPTIONS' ), $preload_paths ) ) {
$preload_paths[] = array( '/wp/v2/blocks', 'OPTIONS' );
}

return $preload_paths;
}
add_filter( 'block_editor_preload_paths', 'gutenberg_extend_block_editor_preload_paths' );
2 changes: 1 addition & 1 deletion packages/e2e-tests/specs/block-deletion.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe( 'block deletion -', () => {
beforeEach( addThreeParagraphsToNewPost );

describe( 'deleting the third block using the Remove Block menu item', () => {
it.skip( 'results in two remaining blocks and positions the caret at the end of the second block', async () => {
it( 'results in two remaining blocks and positions the caret at the end of the second block', async () => {
// The blocks can't be empty to trigger the toolbar
await page.keyboard.type( 'Paragraph to remove' );

Expand Down
26 changes: 26 additions & 0 deletions phpunit/class-extend-preload-paths-test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/**
* Test `gutenberg_extend_block_editor_preload_paths`.
*
* @package Gutenberg
*/

class Extend_Preload_Paths_Test extends WP_UnitTestCase {
/**
* Tests '/wp/v2/blocks' added if missing.
*/
function test_localizes_script() {
$preload_paths = gutenberg_extend_block_editor_preload_paths( array() );

$this->assertEquals( array( array( '/wp/v2/blocks', 'OPTIONS' ) ), $preload_paths );
}

/**
* Tests '/wp/v2/blocks' not added if present.
*/
function test_replaces_registered_properties() {
$preload_paths = gutenberg_extend_block_editor_preload_paths( array( array( '/wp/v2/blocks', 'OPTIONS' ) ) );

$this->assertEquals( array( array( '/wp/v2/blocks', 'OPTIONS' ) ), $preload_paths );
}
}