Skip to content

Modules

Feature modules are self-contained classes that use the Module trait for singleton lifecycle management. Each module calls init() once on first instantiation, where it registers WordPress hooks and boots sub-components.

Module pattern

use Barberklingen\BasePlugin\Traits\Module;

class MyFeature {
    use Module;

    public function init(): void {
        add_action('init', [$this, 'register_hooks']);
    }
}

// Boot it — safe to call multiple times, init() runs only once
MyFeature::get_instance();

The Module trait composes Singleton, so get_instance() always returns the same object.

Loader pattern

Larger features bundle sub-modules behind a Loader class. The loader's init() instantiates each sub-module:

class MyFeatureLoader {
    use Module;

    public function init(): void {
        SubModuleA::get_instance();
        SubModuleB::get_instance();
    }
}

Feature loaders are typically guarded by a feature flag before being booted:

if (get_option('my_feature_enabled')) {
    MyFeatureLoader::get_instance();
}

Available modules

Module Description
Subscription Renewals Custom renewal status and renewal order creation
Subscription Addons Add-on products attached to subscriptions
Replacement Orders Create a free replacement copy of an existing order
Referral Coupons Generate and validate referral discount coupons
Security Role/capability management and area lockdown

Core modules (always active)

These are booted unconditionally by BasePluginSetup:

Module Purpose
BaseMigrator Runs versioned DB migrations
RecurringTasksMigrator Runs deployment-time tasks
Admin\Subscription Custom subscription meta box in WP admin
Admin\Order Order admin enhancements
Modules\Subscription Subscription payment/cancellation hooks
Cart Disables persistent cart
CronEndpoint Handles cron.org external triggers
SEO Adds robots.txt disallow rules
I18n Loads barberklingen-base textdomain
OrderReceived Order completion hooks
CommandsProvider (Staging) Registers wp staging pull CLI command