public static function for_id($id, $action = 'register') { return new static(sprintf('Cannot %2$s "%1$s". There already is a module with this ID.', $id, $action)); }
/** * Registers the given module. * * @since 3.0.0 * * @param Module $module Module object. * * @return bool Whether or not the module is active. * * @throws ModuleAlreadyRegisteredException if a module with the ID of the given module already has been registered. */ public function register_module(Module $module) { $id = $module->id(); if ($this->has_module($id)) { throw ModuleAlreadyRegisteredException::for_id($id, 'register'); } if (isset($this->states[$id])) { if ($this->states[$id]) { $module->activate(); } else { $module->deactivate(); } } else { $this->states[$id] = $module->is_active(); $this->save_modules(); } $this->modules[$id] = $module; return $this->states[$id]; }