TS\WonderfulRelations\System\ChildPlugin\ChildPluginContext is the
configuration carrier returned by your provider’s make_context().
Every with_*() call returns a new instance — the context is
immutable from the outside.
Required fields
ChildPluginContext::create(
string $slug, // 'your-plugin'
string $version, // '1.0.0'
string $textdomain, // 'your-plugin'
string $title, // 'Your WR Child Plugin'
string $main_file // __FILE__ from the plugin's main file
);$main_file must be the absolute path to the plugin’s bootstrap file
(the one with the Plugin Name: header). Wonderful Relations derives
plugin_basename, base_dir, root_dir and base_url from it.
Optional with_*() setters
| Setter | Purpose |
|---|---|
with_modules_bootstrap( string $init_class ) | FQCN of your Modules\Init bootstrap. Will be newed once after WR loads. Skip if your plugin has no PHP modules. |
with_dashboard_shortcode( string $identifier ) | Wonderful Relations template shortcode rendered as the main admin page. Without this the page is a placeholder. |
with_menu_icon( string $icon ) | Dashicon name (dashicons-database), data URL or path under the plugin folder. Defaults to dashicons-admin-generic. |
with_required_plugins( array $plugins ) | 'folder/file.php' => 'Human name' map. Activation refuses if any are missing. |
without_admin_menu() | Disable the auto-registered admin menu (headless providers). |
with_external_data_dir( string $sub_path ) | Sub-folder under wp-content/ that the plugin owns for runtime files. Returned as an absolute path with trailing slash. |
with_cron_schedules( callable $registrar ) | Closure invoked on init to register cron hooks. |
with_custom_submenus( callable $registrar ) | Closure invoked inside Menu::admin_menu(). Signature: fn(string $parent_slug, ChildPluginContext $ctx): void. |
with_preflight_warnings( callable $provider ) | Closure that returns extra warnings shown on the Update Center preflight step. Signature: fn(ChildPluginContext $ctx): array<string>. |
as_mother() | Marks the context as the WR mother plugin. Do not use in child plugins — it changes boot hook and deactivation cascade. |
with_kernel_class( string $fqcn ) | Replace the default Kernel. Escape hatch for plugins that boot a license updater or extra services. |
with_menu_class( string $fqcn ) | Replace the default Menu. Escape hatch for plugins with custom admin pages. |
Worked example
return ChildPluginContext::create(
'your-plugin',
'1.0.0',
'your-plugin',
'Your WR Child Plugin',
__FILE__
)
->with_modules_bootstrap( \TS\YourPlugin\Modules\Init::class )
->with_dashboard_shortcode( 'your_plugin_dashboard' )
->with_menu_icon( 'dashicons-database' )
->with_required_plugins( array(
'woocommerce/woocommerce.php' => 'WooCommerce',
) )
->with_cron_schedules( function () {
add_action( 'your_plugin_hourly_sync', [ Sync::class, 'run' ] );
if ( ! wp_next_scheduled( 'your_plugin_hourly_sync' ) ) {
wp_schedule_event( time(), 'hourly', 'your_plugin_hourly_sync' );
}
} )
->with_preflight_warnings( function () {
return is_multisite()
? array( 'This plugin does not support multisite.' )
: array();
} );Read-back accessors
The context exposes getters for every field plus a few derived paths:
slug(),version(),textdomain(),title(),main_file()plugin_name()—folder/file.phpbase_dir()—folderonlyroot_dir()—…/folder/src/(with trailing slash)base_url()— URL to plugin folderexternal_data_dir()— absolute path ornullcron_registrar(),custom_submenus_registrar(),preflight_warnings_provider()kernel_class(),menu_class()has_database_config_file()—trueifsrc/Database/Config/config.jsonexists
