connector-wordpress/source/connector-mobilizon.php

91 lines
2.9 KiB
PHP
Raw Normal View History

2021-01-08 14:08:40 +01:00
<?php
/**
2021-01-16 15:21:46 +01:00
* Plugin Name: <wordpress-nice-name>
* Author: <wordpress-author-name>
* Author URI: <wordpress-author-url>
* Description: <wordpress-description>
* Version: <wordpress-version>
2021-01-08 14:08:40 +01:00
* Requires at least: <wordpress-minimum-version>
* Requires PHP: <wordpress-php-minimum-version>
* License: <wordpress-license>
*/
2024-04-05 23:26:11 +02:00
require_once __DIR__ . '/includes/exceptions/GeneralException.php';
require_once __DIR__ . '/includes/exceptions/GroupNotFoundException.php';
require_once __DIR__ . '/includes/Constants.php';
require_once __DIR__ . '/includes/Api.php';
require_once __DIR__ . '/includes/EventsCache.php';
require_once __DIR__ . '/includes/Settings.php';
require_once __DIR__ . '/includes/DateTimeWrapper.php';
require_once __DIR__ . '/includes/Formatter.php';
require_once __DIR__ . '/includes/GraphQlClient.php';
require_once __DIR__ . '/includes/EventsListBlock.php';
require_once __DIR__ . '/includes/EventsListShortcut.php';
require_once __DIR__ . '/includes/EventsListWidget.php';
2021-01-08 14:08:40 +01:00
// Exit if this file is called directly.
if (!defined('ABSPATH')) {
exit;
}
2021-11-01 21:17:10 +01:00
final class Mobilizon_Connector {
2021-01-08 14:08:40 +01:00
2021-11-01 21:17:10 +01:00
private function __construct() {
2024-04-05 23:26:11 +02:00
add_action('init', [$this, 'register_api']);
2021-12-14 15:33:07 +01:00
add_action('init', [$this, 'register_blocks']);
2022-06-03 23:48:19 +02:00
add_action('init', [$this, 'register_settings'], 1); // required for register_blocks
2021-11-01 21:17:10 +01:00
add_action('init', [$this, 'register_shortcut']);
add_action('widgets_init', [$this, 'register_widget']);
register_activation_hook(__FILE__, [$this, 'enable_activation']);
}
2021-01-08 14:08:40 +01:00
2021-11-01 21:17:10 +01:00
public static function init() {
// Create singleton instance.
static $instance = false;
if(!$instance) {
$instance = new self();
}
return $instance;
}
2021-01-08 14:08:40 +01:00
2021-11-01 21:17:10 +01:00
public function enable_activation() {
MobilizonConnector\Settings::setDefaultOptions();
}
2021-01-08 14:08:40 +01:00
2022-06-03 23:48:19 +02:00
private function load_settings_globally_before_script($scriptName) {
$settings = array(
'isShortOffsetNameShown' => MobilizonConnector\Settings::isShortOffsetNameShown(),
'locale' => str_replace('_', '-', get_locale()),
2024-04-05 23:26:11 +02:00
'timeZone' => wp_timezone_string()
2022-06-03 23:48:19 +02:00
);
wp_add_inline_script($scriptName, 'var MOBILIZON_CONNECTOR = ' . json_encode($settings), 'before');
}
2024-04-05 23:26:11 +02:00
public function register_api() {
MobilizonConnector\Api::init();
}
2021-12-14 15:33:07 +01:00
public function register_blocks() {
2022-06-03 23:48:19 +02:00
$scriptName = MobilizonConnector\EventsListBlock::initAndReturnScriptName();
$this->load_settings_globally_before_script($scriptName);
2021-12-14 15:33:07 +01:00
}
2021-11-01 21:17:10 +01:00
public function register_settings() {
MobilizonConnector\Settings::init();
}
public function register_shortcut() {
MobilizonConnector\EventsListShortcut::init();
}
public function register_widget() {
register_widget('MobilizonConnector\EventsListWidget');
}
2021-11-01 20:55:37 +01:00
}
2021-01-08 14:08:40 +01:00
2021-11-01 21:17:10 +01:00
function mobilizon_connector_run_plugin() {
return Mobilizon_Connector::init();
2021-01-08 14:08:40 +01:00
}
2021-11-01 21:17:10 +01:00
mobilizon_connector_run_plugin();