Hierarchies
<?php
namespace DeepWebSolutions\Plugins\MyTestPlugin;
use DeepWebSolutions\Framework\Foundations\Actions\InitializableInterface;
use DeepWebSolutions\Framework\Foundations\Actions\SetupableInterface;
use DeepWebSolutions\Framework\Foundations\Hierarchy\Plugin\AbstractPluginRoot;
use DeepWebSolutions\Framework\Foundations\Hierarchy\Plugin\AbstractPluginNode;
use DeepWebSolutions\Framework\Foundations\Hierarchy\Actions\InitializeChildrenTrait;
use DeepWebSolutions\Framework\Foundations\Hierarchy\Actions\MaybeSetupChildrenTrait;
use DeepWebSolutions\Framework\Foundations\Hierarchy\States\ActiveParentTrait;
use DeepWebSolutions\Framework\Foundations\Hierarchy\States\DisabledParentTrait;
use DeepWebSolutions\Framework\Foundations\States\ActiveableInterface;
use DeepWebSolutions\Framework\Foundations\States\DisableableInterface;
// Exceptions import and Local traits import ommitted for brevity
class MyPlugin extends AbstractPluginRoot implements InitializableInterface, SetupableInterface {
use InitializeChildrenTrait;
use MaybeSetupChildrenTrait;
use SetupLocalTrait;
use SetupOnInitializationTrait;
public function get_plugin_file_path(): string {
return $path_to_file_with_plugin_header_comment;
}
protected function setup_local(): ?SetupFailureException {
// do some local setup ... like registering some actions and filters
return null;
}
}
class GenericComponents extends AbstractPluginNode implements InitializableInterface, SetupableInterface, ActiveableInterface, DisableableInterface {
use InitializeChildrenTrait;
use InitializeLocalTrait;
use MaybeSetupChildrenTrait;
use SetupLocalTrait;
use ActiveLocalTrait;
use ActiveParentTrait;
use DisabledLocalTrait;
use DisabledParentTrait;
protected function is_active_local(): bool {
// add your own logic for this node (and all of its descendants) to be active
// for example, a setting in the WP admin area
return true;
}
protected function is_disabled_local(): bool {
// add your own logic for this node (and all of its descendants) to be disabled
// for example, this plugin branch could be for compatibility with another plugin
// and thus, if that plugin is not active, nothing here should run
return false;
}
protected function initialize_local(): ?InitializationFailureException {
// do some local initialization, basically just making sure that
// everything is in order for the 'setup_local' call
return null;
}
protected function setup_local(): ?SetupFailureException {
// do some local setup, like registering actions and filters,
// registering shortcodes, setting up REST routes,
// adding admin notices, whatever
return null;
}
}
$plugin = new MyPlugin();
$component1 = new GenericComponent();
$component2 = new GenericComponent();
$component3 = new GenericComponent();
$plugin->add_child( $component1 );
$component1->add_child( $component2 );
$component1->add_child( $component3 );
// automagically run everything!
$plugin->initialize();

Last updated