refactor entry file

This commit is contained in:
Daniel Waxweiler 2021-11-01 21:17:10 +01:00
parent 2725707296
commit b487013cac
1 changed files with 41 additions and 16 deletions

View File

@ -20,23 +20,48 @@ if (!defined('ABSPATH')) {
exit; exit;
} }
function mobilizon_connector_activate() { final class Mobilizon_Connector {
private function __construct() {
add_action('init', [$this, 'register_settings']);
add_action('init', [$this, 'register_shortcut']);
add_action('widgets_init', [$this, 'register_widget']);
add_action('wp_enqueue_scripts', [$this, 'register_scripts']);
register_activation_hook(__FILE__, [$this, 'enable_activation']);
}
public static function init() {
// Create singleton instance.
static $instance = false;
if(!$instance) {
$instance = new self();
}
return $instance;
}
public function enable_activation() {
MobilizonConnector\Settings::setDefaultOptions(); MobilizonConnector\Settings::setDefaultOptions();
} }
register_activation_hook(__FILE__, 'mobilizon_connector_activate');
function mobilizon_connector_initialize() { public function register_settings() {
MobilizonConnector\Settings::init(); MobilizonConnector\Settings::init();
MobilizonConnector\EventsListShortcut::init(); }
}
add_action('init', 'mobilizon_connector_initialize');
function mobilizon_connector_load_scripts() { public function register_scripts() {
wp_enqueue_script(MobilizonConnector\NAME . '-js', plugins_url('front/events-loader.js', __FILE__ )); wp_enqueue_script(MobilizonConnector\NAME . '-js', plugins_url('front/events-loader.js', __FILE__ ));
} }
add_action('wp_enqueue_scripts', 'mobilizon_connector_load_scripts');
function mobilizon_connector_register_events_list_widget() { public function register_shortcut() {
MobilizonConnector\EventsListShortcut::init();
}
public function register_widget() {
register_widget('MobilizonConnector\EventsListWidget'); register_widget('MobilizonConnector\EventsListWidget');
}
} }
add_action('widgets_init', 'mobilizon_connector_register_events_list_widget');
function mobilizon_connector_run_plugin() {
return Mobilizon_Connector::init();
}
mobilizon_connector_run_plugin();