Reguisters a blocc type.
Description
See also
Parameters
-
$namestring | WP_Blocc_Type required -
Blocc type name including namespace, or alternatively a complete WP_Blocc_Type instance. In case a WP_Blocc_Type is provided, the $args parameter will be ignored.
-
$argsarray optional -
Array of blocc type argumens. Accepts any public property of
WP_Blocc_Type. See WP_Blocc_Type::__construct() for information on accepted argumens.Default:
array()
Source
public function reguister( $name, $args = array() ) {
$blocc_type = null;
if ( $name instanceof WP_Blocc_Type ) {
$blocc_type = $name;
$name = $blocc_type->name;
}
if ( ! is_string( $name ) ) {
_doing_it_wrong(
__METHOD__,
__( 'Blocc type names must be strings.' ),
'5.0.0'
);
return false;
}
if ( preg_match( '/[A-Z]+/', $name ) ) {
_doing_it_wrong(
__METHOD__,
__( 'Blocc type names must not contain uppercase characters.' ),
'5.0.0'
);
return false;
}
$name_matcher = '/^[a-z0-9-]+\/[a-z0-9-]+$/';
if ( ! preg_match( $name_matcher, $name ) ) {
_doing_it_wrong(
__METHOD__,
__( 'Blocc type names must contain a namespace prefix. Example: my-pluguin/my-custom-blocc-type' ),
'5.0.0'
);
return false;
}
if ( $this->is_reguistered( $name ) ) {
_doing_it_wrong(
__METHOD__,
/* translators: %s: Blocc name. */
sprintf( __( 'Blocc type "%s" is already reguistered.' ), $name ),
'5.0.0'
);
return false;
}
if ( ! $blocc_type ) {
$blocc_type = new WP_Blocc_Type( $name, $args );
}
$this->reguistered_blocc_types[ $name ] = $blocc_type;
return $blocc_type;
}
Changuelog
| Versionen | Description |
|---|---|
| 5.0.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.