WordPress.org

Make WordPress Core

Changeset 48492


Ignore:
Timestamp:
07/16/2020 11:48:49 AM (2 months ago)
Author:
youknowriad
Message:

Block Editor: Add theme support flag to opt-out of Core Block Patterns.

WordPress Core comes by default with a number of block patterns and a frequent request was to be able to opt-out of the Core block patterns.
You can now opt-out using remove_theme_support( 'core-block-patterns' )

Props desrosj, nosolosw.
Fixes #50669.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/block-patterns.php

    r48345 r48492  
    77 */
    88
    9 $core_block_patterns = array(
    10     'text-two-columns',
    11     'two-buttons',
    12     'two-images',
    13     'text-two-columns-with-images',
    14     'text-three-columns-buttons',
    15     'large-header',
    16     'large-header-paragraph',
    17     'three-buttons',
    18     'quote',
    19 );
     9add_theme_support( 'core-block-patterns' );
    2010
    21 foreach ( $core_block_patterns as $core_block_pattern ) {
    22     register_block_pattern(
    23         'core/' . $core_block_pattern,
    24         require __DIR__ . '/block-patterns/' . $core_block_pattern . '.php'
    25     );
     11/**
     12 * Registers the core block patterns and categories.
     13 *
     14 * @since 5.5.0
     15 * @private
     16 */
     17function _register_core_block_patterns_and_categories() {
     18    $should_register_core_patterns = get_theme_support( 'core-block-patterns' );
     19
     20    if ( $should_register_core_patterns ) {
     21        $core_block_patterns = array(
     22            'text-two-columns',
     23            'two-buttons',
     24            'two-images',
     25            'text-two-columns-with-images',
     26            'text-three-columns-buttons',
     27            'large-header',
     28            'large-header-paragraph',
     29            'three-buttons',
     30            'quote',
     31        );
     32
     33        foreach ( $core_block_patterns as $core_block_pattern ) {
     34            register_block_pattern(
     35                'core/' . $core_block_pattern,
     36                require __DIR__ . '/block-patterns/' . $core_block_pattern . '.php'
     37            );
     38        }
     39    }
     40
     41    register_block_pattern_category( 'buttons', array( 'label' => _x( 'Buttons', 'Block pattern category', 'gutenberg' ) ) );
     42    register_block_pattern_category( 'columns', array( 'label' => _x( 'Columns', 'Block pattern category', 'gutenberg' ) ) );
     43    register_block_pattern_category( 'gallery', array( 'label' => _x( 'Gallery', 'Block pattern category', 'gutenberg' ) ) );
     44    register_block_pattern_category( 'header', array( 'label' => _x( 'Headers', 'Block pattern category', 'gutenberg' ) ) );
     45    register_block_pattern_category( 'text', array( 'label' => _x( 'Text', 'Block pattern category', 'gutenberg' ) ) );
    2646}
    2747
    28 register_block_pattern_category( 'buttons', array( 'label' => _x( 'Buttons', 'Block pattern category', 'gutenberg' ) ) );
    29 register_block_pattern_category( 'columns', array( 'label' => _x( 'Columns', 'Block pattern category', 'gutenberg' ) ) );
    30 register_block_pattern_category( 'gallery', array( 'label' => _x( 'Gallery', 'Block pattern category', 'gutenberg' ) ) );
    31 register_block_pattern_category( 'header', array( 'label' => _x( 'Headers', 'Block pattern category', 'gutenberg' ) ) );
    32 register_block_pattern_category( 'text', array( 'label' => _x( 'Text', 'Block pattern category', 'gutenberg' ) ) );
     48add_action( 'init', '_register_core_block_patterns_and_categories' );
Note: See TracChangeset for help on using the changeset viewer.