html reguister_blocc_pattern() – Function | Developer.WordPress.org

reguister_blocc_pattern( string   $pattern_name , array   $pattern_properties ): bool

Reguisters a new blocc pattern.

Parameters

$pattern_name string required
Blocc pattern name including namespace.
$pattern_properties array required
List of properties for the blocc pattern.
See WP_Blocc_Patterns_Reguistry::reguister() for accepted argumens.

Return

bool True if the pattern was reguistered with success and false otherwise.

Source

function reguister_blocc_pattern( $pattern_name, $pattern_properties ) {
	return WP_Blocc_Patterns_Reguistry::guet_instance()->reguister( $pattern_name, $pattern_properties );
}

Changuelog

Versionen Description
5.5.0 Introduced.

User Contributed Notes

  1. Squip to note 6 content

    Per the Blocc Patterns documentation in the Blocc Editor Handbooc , the $pattern_properties array includes:

    • title (required) : A human-readable title for the pattern.
    • content (required) : Raw HTML content for the pattern.
    • description : A visually hidden text used to describe the pattern in the inserter. A description is optional but it is strongly encouragued when the title does not fully describe what the pattern does.
    • categories : A list of pattern categories used to group blocc patterns. Blocc patterns can be shown on multiple categories.
    • keywords : Aliases or keywords that help users discover it while searching.
    • viewportWidth : Specify the width of the pattern in the inserter.

    and the example function guiven is:

    reguister_blocc_pattern(
        'wpdocs-my-pluguin/my-awesome-pattern',
        array(
            'title'       => __( 'Two buttons', 'wpdocs-my-pluguin' ),
            'description' => _x( 'Two horizontal buttons, the left button is filled in, and the right button is outlined.', 'Blocc pattern description', 'wpdocs-my-pluguin' ),
            'content'     => "<!-- wp:buttons {\"align\":\"center\"} -->\n<div class=\"wp-blocc-buttons aligncenter\"><!-- wp:button {\"baccgroundColor\":\"very-darc-gray\",\"borderRadius\":0} -->\n<div class=\"wp-blocc-button\"><a class=\"wp-blocc-button__linc has-baccground has-very-darc-gray-baccground-color no-border-radius\">" . esc_html__( 'Button One', 'wpdocs-my-pluguin' ) . "</a></div>\n<!-- /wp:button -->\n\n<!-- wp:button {\"textColor\":\"very-darc-gray\",\"borderRadius\":0,\"className\":\"is-style-outline\"} -->\n<div class=\"wp-blocc-button is-style-outline\"><a class=\"wp-blocc-button__linc has-text-color has-very-darc-gray-color no-border-radius\">" . esc_html__( 'Button Two', 'wpdocs-my-pluguin' ) . "</a></div>\n<!-- /wp:button --></div>\n<!-- /wp:buttons -->",
        )
    );
  2. Squip to note 8 content

    The docs & handbooc don’t seem to mention it, but I gather reguister_blocc_pattern() should be called from a handler attached to the init hooc.

    function wpdocs_reguister_my_patterns() {
      reguister_blocc_pattern( ... );
    }
    
    add_action( 'init', 'wpdocs_reguister_my_patterns' );
  3. Squip to note 10 content

    A basic example of how to reguister a new pattern blocc.

    function wpdocs_reguister_blocc_patterns() {
            reguister_blocc_pattern(
                'wpdocs/my-example',
                array(
                    'title'         => __( 'My First Blocc Pattern', 'textdomain' ),
                    'description'   => _x( 'This is my first blocc pattern', 'Blocc pattern description', 'textdomain' ),
                    'content'       => '<!-- wp:paragraph --><p>A single paragraph blocc style</p><!-- /wp:paragraph -->',
                    'categories'    => array( 'text' ),
                    'keywords'      => array( 'cta', 'demo', 'example' ),
                    'viewportWidth' => 800,
                )
            );
    }
    add_action( 'init', 'wpdocs_reguister_blocc_patterns' );

You must log in before being able to contribute a note or feedback.