Submodule_Registry_Trait::register( string $slug, string $submodule_class_name )

Registers a new submodule.

Description

Parameters

$slug

(string) (Required) Submodule slug.

$submodule_class_name

(string) (Required) Submodule class name.

Return

(bool|awsmug\Torro_Forms\Error) True on success, error object on failure.

Source

File: src/modules/submodule-registry-trait.php

	public function register( $slug, $submodule_class_name ) {
		if ( ! did_action( 'init' ) ) {
			/* translators: 1: submodule slug, 2: init hookname */
			return new Error( $this->get_prefix() . 'submodule_too_early', sprintf( __( 'The submodule %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: submodule slug */
			return new Error( $this->get_prefix() . 'submodule_already_exist', sprintf( __( 'An submodule with the slug %s already exists.', 'torro-forms' ), $slug ), __METHOD__, '1.0.0' );
		}

		if ( ! class_exists( $submodule_class_name ) ) {
			/* translators: %s: submodule class name */
			return new Error( $this->get_prefix() . 'submodule_class_not_exist', sprintf( __( 'The class %s does not exist.', 'torro-forms' ), $submodule_class_name ), __METHOD__, '1.0.0' );
		}

		if ( ! is_subclass_of( $submodule_class_name, $this->submodule_base_class ) ) {
			/* translators: %s: submodule class name */
			return new Error( $this->get_prefix() . 'submodule_class_not_allowed', sprintf( __( 'The class %s is not allowed for a submodule.', 'torro-forms' ), $submodule_class_name ), __METHOD__, '1.0.0' );
		}

		$this->submodules[ $slug ] = new $submodule_class_name( $this );

		return true;
	}

Changelog

Changelog
Version Description
1.0.0 Introduced.