Traits

HasSettings

v1.0.0

Adds getSetting, setSetting, deleteSetting, and getAllSettings helpers backed by SettingsServiceInterface.

Use Trait

use Meteorack\Sdk\RuntimeWp\Traits\HasSettings;

How To Use It

  • You usually get this automatically through AbstractModule, so import the trait manually only when you build your own base module class.
  • Use the helpers for everyday module configuration work and drop to SettingsServiceInterface only when you need raw defaults or service-level composition.

Helpers

public function getSetting(string $key, mixed $default = null): mixed

Reads a module setting with an optional fallback.

public function setSetting(string $key, mixed $value): void

Persists a module setting value.

public function deleteSetting(string $key): void

Deletes a stored setting for the current module.

public function getAllSettings(): array

Returns all stored settings for the module.

Example

bootstrap.php
class ReportsModule extends AbstractModule
{
    public function onSdkReady(SdkContext $ctx): void
    {
        parent::onSdkReady($ctx);

        $this->setSetting('theme', 'dark');
        $theme = $this->getSetting('theme', 'light');

        $ctx->logger()->info('reports.theme_loaded', ['theme' => $theme]);
    }
}