Registers a new element type.
Description
See also
Parameters
- $slug
-
(string) (Required) Element type slug.
- $element_type_class_name
-
(string) (Required) Element type class name.
Return
(bool|awsmug\Torro_Forms\Error) True on success, error object on failure.
Source
File: src/db-objects/elements/element-types/element-type-manager.php
public function register( $slug, $element_type_class_name ) { if ( ! did_action( 'init' ) ) { /* translators: 1: element type slug, 2: init hookname */ return new Error( $this->get_prefix() . 'element_type_too_early', sprintf( __( 'The element type %1$s cannot be registered before the %2$s hook.', 'torro-forms' ), $slug, '<code>init</code>' ), __METHOD__, '1.0.0' ); } if ( $this->has( $slug ) ) { /* translators: %s: element type slug */ return new Error( $this->get_prefix() . 'element_type_already_exist', sprintf( __( 'An element type with the slug %s already exists.', 'torro-forms' ), $slug ), __METHOD__, '1.0.0' ); } if ( ! class_exists( $element_type_class_name ) ) { /* translators: %s: element type class name */ return new Error( $this->get_prefix() . 'element_type_class_not_exist', sprintf( __( 'The class %s does not exist.', 'torro-forms' ), $element_type_class_name ), __METHOD__, '1.0.0' ); } if ( ! is_subclass_of( $element_type_class_name, Element_Type::class ) ) { /* translators: %s: element type class name */ return new Error( $this->get_prefix() . 'element_type_class_not_allowed', sprintf( __( 'The class %s is not allowed for a element type.', 'torro-forms' ), $element_type_class_name ), __METHOD__, '1.0.0' ); } $this->element_types[ $slug ] = new $element_type_class_name( $this ); return true; }
Changelog
Version | Description |
---|---|
1.0.0 | Introduced. |