This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
{ | |
// ... | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
{ | |
// ... | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$plugin = new My_Plugin(); | |
$plugin->boot(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment