Skip to main content

Extensibility

PropertyValue
descriptionSupported hooks and add-on patterns for extending MAC Core.
tagsdoc, mac-core, hook, extensibility
rating
urlsGitHub

Overview

MAC Core exposes a small extension surface on purpose. The supported way to extend the plugin is through documented filters and public wrapper functions, not by patching private methods or vendored code.

Use these hooks when you need to:

  • add runtime services
  • add settings modules
  • add admin tabs
  • override the SureCart public token
  • extend FormatDatetime

Public Hooks

HookPurposeExpected shape
mac_core_servicesAppend runtime services during kernel bootstrap.array<int, Service>
mac_core_settings_sectionsAdd settings modules and fields.array<string,array<string,mixed>>
mac_core_admin_tabsAdd admin tabs to the MAC Core screen.array<string,array{label:string,callback:callable}>
mac_core_surecart_public_tokenOverride the SureCart licensing public token.string
mac_core_format_datetime_configOverride the default preset and view.array{default_preset:string,default_view:string}
mac_core_format_datetime_presetsAdd or override datetime presets.array<string,array<string,mixed>>
mac_core_format_datetime_viewsAdd or override datetime views.array<string,array<string,mixed>>

Add Runtime Services

Use mac_core_services to append instantiated services that implement the shared Service contract.

<?php

use MacCore\Contracts\Service;

final class MyMacCoreAddon implements Service {
public function register(): void {
add_action( 'init', function (): void {
// Custom runtime behavior.
} );
}
}

add_filter(
'mac_core_services',
function ( array $services ): array {
$services[] = new MyMacCoreAddon();
return $services;
}
);

Recommended use:

  • self-contained add-on behavior
  • site-level modules that belong beside MAC Core

Do not use this hook to replace the plugin kernel or remove built-in services.

Add Settings Modules

Use mac_core_settings_sections to add new modules that follow the same schema shape as the built-in sections.

Each module should define:

  • title
  • description
  • fields

Each field should define at minimum:

  • type
  • label
  • description
  • default

Example:

<?php

add_filter(
'mac_core_settings_sections',
function ( array $sections ): array {
$sections['example'] = [
'title' => 'Example Module',
'description' => 'Additional MAC Core settings.',
'fields' => [
'enabled' => [
'type' => 'checkbox',
'group' => 'General',
'label' => 'Enable example behavior',
'description' => 'Turns the example feature on.',
'default' => false,
],
],
];

return $sections;
}
);

Add Admin Tabs

Use mac_core_admin_tabs to append tabs to the existing MAC Core admin page.

Each tab entry must provide:

  • label
  • callback

Example:

<?php

add_filter(
'mac_core_admin_tabs',
function ( array $tabs ): array {
$tabs['example'] = [
'label' => 'Example',
'callback' => static function (): void {
echo '<p>Example admin content.</p>';
},
];

return $tabs;
}
);

Override the Licensing Token

MAC Core ships with a default constant, but the supported override point is the mac_core_surecart_public_token filter.

<?php

add_filter(
'mac_core_surecart_public_token',
function (): string {
return 'pt_your_public_token_here';
}
);

Use this instead of editing the plugin or modifying the vendored SureCart runtime.

Extend FormatDatetime

FormatDatetime exposes three dedicated hooks:

  • mac_core_format_datetime_config
  • mac_core_format_datetime_presets
  • mac_core_format_datetime_views

The common pattern is:

  • add a preset that maps your field names
  • add one or more output views
  • optionally change the default preset or view for the site

See Utils / Format Datetime for working examples.

Public vs Internal Surface

Treat these as public:

  • the documented hooks above
  • mac_format_datetime()
  • the documented global mac_* utility wrappers

Treat these as internal:

  • private methods on services and utilities
  • the exact internal service registration order
  • vendored SureCart SDK internals
  • implementation details not exposed through a documented hook or wrapper