-
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.
Backport fixes to include on WordPress 5.5 beta 4 (#24218)
Co-authored-by: Noah Allen <noahtallen@gmail.com> Co-authored-by: Dominik Schilling <dominikschilling+git@gmail.com> Co-authored-by: Daniel Richards <daniel.richards@automattic.com> Co-authored-by: Dion Hulse <dion@wordpress.org> Co-authored-by: Nik Tsekouras <ntsekouras@outlook.com> Co-authored-by: Rami Yushuvaev <r_a_m_i@hotmail.com> Co-authored-by: Oskar Schöldström <m@oxy.fi> Co-authored-by: Ella van Durpe <ella@vandurpe.com>
- Loading branch information
1 parent
72984f3
commit 4efd890
Showing
45 changed files
with
693 additions
and
268 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
/** | ||
* Add support for block patterns and register default patterns. | ||
* | ||
* @package gutenberg | ||
*/ | ||
|
||
add_theme_support( 'core-block-patterns' ); | ||
|
||
/** | ||
* Extends block editor settings to include a list of default patterns. | ||
* | ||
* @param array $settings Default editor settings. | ||
* | ||
* @return array Filtered editor settings. | ||
*/ | ||
function gutenberg_extend_settings_block_patterns( $settings ) { | ||
$settings['__experimentalBlockPatterns'] = WP_Block_Patterns_Registry::get_instance()->get_all_registered(); | ||
$settings['__experimentalBlockPatternCategories'] = WP_Block_Pattern_Categories_Registry::get_instance()->get_all_registered(); | ||
|
||
return $settings; | ||
} | ||
add_filter( 'block_editor_settings', 'gutenberg_extend_settings_block_patterns', 0 ); | ||
|
||
|
||
/** | ||
* Load a block pattern by name. | ||
* | ||
* @param string $name Block Pattern File name. | ||
* | ||
* @return array Block Pattern Array. | ||
*/ | ||
function gutenberg_load_block_pattern( $name ) { | ||
return require( __DIR__ . '/patterns/' . $name . '.php' ); | ||
} | ||
|
||
/** | ||
* Register default patterns and categories, potentially overriding ones that were already registered in Core. | ||
* | ||
* This can be removed when plugin support requires WordPress 5.5.0+, and patterns have been synced back to Core. | ||
* | ||
* @see https://core.trac.wordpress.org/ticket/50550 | ||
*/ | ||
function gutenberg_register_block_patterns() { | ||
$should_register_core_patterns = get_theme_support( 'core-block-patterns' ); | ||
|
||
if ( $should_register_core_patterns ) { | ||
register_block_pattern( 'core/text-two-columns', gutenberg_load_block_pattern( 'text-two-columns' ) ); | ||
register_block_pattern( 'core/two-buttons', gutenberg_load_block_pattern( 'two-buttons' ) ); | ||
register_block_pattern( 'core/two-images', gutenberg_load_block_pattern( 'two-images' ) ); | ||
register_block_pattern( 'core/text-two-columns-with-images', gutenberg_load_block_pattern( 'text-two-columns-with-images' ) ); | ||
register_block_pattern( 'core/text-three-columns-buttons', gutenberg_load_block_pattern( 'text-three-columns-buttons' ) ); | ||
register_block_pattern( 'core/large-header', gutenberg_load_block_pattern( 'large-header' ) ); | ||
register_block_pattern( 'core/large-header-paragraph', gutenberg_load_block_pattern( 'large-header-paragraph' ) ); | ||
register_block_pattern( 'core/three-buttons', gutenberg_load_block_pattern( 'three-buttons' ) ); | ||
register_block_pattern( 'core/quote', gutenberg_load_block_pattern( 'quote' ) ); | ||
} | ||
|
||
register_block_pattern_category( 'buttons', array( 'label' => _x( 'Buttons', 'Block pattern category', 'gutenberg' ) ) ); | ||
register_block_pattern_category( 'columns', array( 'label' => _x( 'Columns', 'Block pattern category', 'gutenberg' ) ) ); | ||
register_block_pattern_category( 'gallery', array( 'label' => _x( 'Gallery', 'Block pattern category', 'gutenberg' ) ) ); | ||
register_block_pattern_category( 'header', array( 'label' => _x( 'Headers', 'Block pattern category', 'gutenberg' ) ) ); | ||
register_block_pattern_category( 'text', array( 'label' => _x( 'Text', 'Block pattern category', 'gutenberg' ) ) ); | ||
} | ||
add_action( 'init', 'gutenberg_register_block_patterns' ); |
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
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
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 |
---|---|---|
@@ -1,45 +1,21 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { loadScript, loadStyle } from '../controls'; | ||
import { loadAsset } from '../controls'; | ||
|
||
describe( 'controls', () => { | ||
const scriptAsset = 'http://www.wordpress.org/plugins/fakeasset.js'; | ||
const styleAsset = 'http://www.wordpress.org/plugins/fakeasset.css'; | ||
describe( 'loadAsset', () => { | ||
const script = document.createElement( 'script' ); | ||
const style = document.createElement( 'link' ); | ||
|
||
describe( 'loadScript', () => { | ||
it( 'should return a Promise when loading a script', () => { | ||
const result = loadScript( scriptAsset ); | ||
const result = loadAsset( script ); | ||
expect( typeof result.then ).toBe( 'function' ); | ||
} ); | ||
|
||
it( 'should reject when no script is given', async () => { | ||
expect.assertions( 1 ); | ||
const result = loadScript( '' ); | ||
await expect( result ).rejects.toThrow( Error ); | ||
} ); | ||
|
||
it( 'should reject when a non-js file is given', async () => { | ||
const result = loadScript( styleAsset ); | ||
await expect( result ).rejects.toThrow( Error ); | ||
} ); | ||
} ); | ||
|
||
describe( 'loadStyle', () => { | ||
it( 'should return a Promise when loading a style', () => { | ||
const result = loadStyle( styleAsset ); | ||
const result = loadAsset( style ); | ||
expect( typeof result.then ).toBe( 'function' ); | ||
} ); | ||
|
||
it( 'should reject when no style is given', async () => { | ||
expect.assertions( 1 ); | ||
const result = loadStyle( '' ); | ||
await expect( result ).rejects.toThrow( Error ); | ||
} ); | ||
|
||
it( 'should reject when a non-css file is given', async () => { | ||
const result = loadStyle( scriptAsset ); | ||
await expect( result ).rejects.toThrow( Error ); | ||
} ); | ||
} ); | ||
} ); |
Oops, something went wrong.