WP_Block_Patterns_Registry::register( string $pattern_name, array $pattern_properties )
Registers a pattern.
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.
Return
(bool) True if the pattern was registered with success and false otherwise.
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;
} Changelog
| Version | Description |
|---|---|
| 5.5.0 | Introduced. |
© 2003–2021 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_block_patterns_registry/register