WP_Block_Patterns_Registry::register() public WP 5.5.0
Registers a pattern.
{} It's a method of the class: WP_Block_Patterns_Registry{}
No Hooks.
Return
true/false. True if the pattern was registered with success and false otherwise.
Usage
$WP_Block_Patterns_Registry = new WP_Block_Patterns_Registry(); $WP_Block_Patterns_Registry->register( $pattern_name, $pattern_properties );
- $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.
Changelog
Since 5.5.0 | Introduced. |
Code of WP_Block_Patterns_Registry::register() WP Block Patterns Registry::register WP 5.6
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;
}