Registers a new module.
Description
See also
Parameters
- $slug
-
(string) (Required) Module slug.
- $module_class_name
-
(string) (Required) Module class name.
Return
(bool|awsmug\Torro_Forms\Error) True on success, error object on failure.
Source
File: src/modules/module-manager.php
public function register( $slug, $module_class_name ) { if ( isset( $this->modules[ $slug ] ) ) { /* translators: %s: module slug */ return new Error( $this->get_prefix() . 'module_already_exist', sprintf( __( 'A module with the slug %s already exists.', 'torro-forms' ), $slug ), __METHOD__, '1.0.0' ); } if ( ! class_exists( $module_class_name ) ) { /* translators: %s: module class name */ return new Error( $this->get_prefix() . 'module_class_not_exist', sprintf( __( 'The class %s does not exist.', 'torro-forms' ), $module_class_name ), __METHOD__, '1.0.0' ); } if ( ! is_subclass_of( $module_class_name, Module::class ) ) { /* translators: %s: module class name */ return new Error( $this->get_prefix() . 'module_class_not_allowed', sprintf( __( 'The class %s is not allowed for a module.', 'torro-forms' ), $module_class_name ), __METHOD__, '1.0.0' ); } $this->modules[ $slug ] = new $module_class_name( $this->get_prefix(), array( 'manager' => $this, 'error_handler' => $this->error_handler(), ) ); return true; }
Changelog
Version | Description |
---|---|
1.0.0 | Introduced. |