Skip to content

Instantly share code, notes, and snippets.

@carlalexander
Last active February 11, 2018 19:58
Embed
What would you like to do?
class My_Plugin_Admin_Page implements Action_Hook_SubscriberInterface
{
public static function get_actions()
{
return array(
'init' => 'configure',
'admin_menu' => 'add_admin_page'
);
}
public function add_admin_page()
{
// ...
}
public function configure()
{
// ...
}
}
class My_Plugin_Ajax implements Action_Hook_SubscriberInterface
{
const ACTION = 'my_plugin_ajax';
public static function get_actions()
{
return array(
'wp_ajax_' . self::ACTION => 'do_ajax'
);
}
public function do_ajax()
{
// ...
}
}
class My_plugin
{
private $api_manager;
private $booted = false;
public function __construct()
{
$this->api_manager = new WP_Plugin_API_Manager();
}
public function get_subscribers()
{
return array(
new My_Plugin_Admin_Page(),
new My_Plugin_Ajax()
);
}
public function boot()
{
if ($this->booted) {
return;
}
foreach ($this->get_subscribers() as $subscriber) {
$this->api_manager->register($subscriber);
}
$this->booted = true;
}
}
$plugin = new My_Plugin();
$plugin->boot();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment