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

Registers a pattern.


Parameters Parameters

$pattern_name

(string) (Required) Pattern name including namespace.

$pattern_properties

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


Top ↑

Return Return

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


Top ↑

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;
	}


Top ↑

Changelog Changelog

Changelog
Version Description
5.5.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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