GC_Block_Patterns_Registry::register()

最后更新于:2021-11-26 10:16:22

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

Registers a pattern.

参数

$pattern_name

(string) (Required) Pattern name including namespace.

$pattern_properties

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

响应

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

源文件

文件: gc-includes/class-gc-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;
	}