WP_Block_Patterns_Registry::register

Advertisement

Summery Summery

Registers a pattern.

Syntax Syntax

WP_Block_Patterns_Registry::register( string $pattern_name, array $pattern_properties )

Parameters Parameters

$pattern_name

(Required) Pattern name including namespace.

$pattern_properties

(Required) Array containing the properties of the pattern: title, content, description, viewportWidth, categories, keywords.

Return Return

(bool) True if the pattern was registered with success and false otherwise.

Source Source

File: wp-includes/class-wp-block-patterns-registry.php

	public function register( $pattern_name, $pattern_properties ) {
		if ( ! isset( $pattern_name ) || ! is_string( $pattern_name ) ) {
			_doing_it_wrong( __METHOD__, __( 'Pattern name must be a string.' ), '5.5.0' );
			return false;
		}

		if ( ! isset( $pattern_properties['title'] ) || ! is_string( $pattern_properties['title'] ) ) {
			_doing_it_wrong( __METHOD__, __( 'Pattern title must be a string.' ), '5.5.0' );
			return false;
		}

		if ( ! isset( $pattern_properties['content'] ) || ! is_string( $pattern_properties['content'] ) ) {
			_doing_it_wrong( __METHOD__, __( 'Pattern content must be a string.' ), '5.5.0' );
			return false;
		}

		$this->registered_patterns[ $pattern_name ] = array_merge(
			$pattern_properties,
			array( 'name' => $pattern_name )
		);

		return true;
	}

Advertisement

Changelog Changelog

Changelog
Version Description
5.5.0 Introduced.

Advertisement

Leave a Reply