wpo365-login.php
3.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
/**
* Plugin Name: WPO365 | LOGIN
* Plugin URI: https://wordpress.org/plugins/wpo365-login
* Description: With WPO365 | LOGIN users can sign in with their corporate or school (Azure AD / Microsoft Office 365) account to access your WordPress website: No username or password required (OIDC or SAML 2.0 based SSO). Plus you can send email using Microsoft Graph instead of SMTP from your WordPress website.
* Version: 23.1
* Author: marco@wpo365.com
* Author URI: https://www.wpo365.com
* License: GPL2+
*/
namespace Wpo;
require __DIR__ . '/vendor/autoload.php';
use \Wpo\Core\Globals;
use \Wpo\Core\Wp_Hooks;
use \Wpo\Services\Dependency_Service;
use \Wpo\Services\Files_Service;
use \Wpo\Services\Request_Service;
use \Wpo\Services\Router_Service;
use Wpo\Services\Options_Service;
// Prevent public access to this script
defined('ABSPATH') or die();
if (!class_exists('\Wpo\Login')) {
class Login
{
private $dependencies;
public function __construct()
{
$this->deactivation_hooks();
add_action('plugins_loaded', array($this, 'init'), 1);
}
public function init()
{
$skip_init = defined('WPO_AUTH_SCENARIO') && constant('WPO_AUTH_SCENARIO') == 'internet' && !\is_admin();
if ($skip_init) {
add_action('login_init', array($this, 'load'), 1);
return;
}
$this->load();
}
public function load()
{
Globals::set_global_vars(__FILE__, __DIR__);
load_plugin_textdomain('wpo365-login', false, dirname(plugin_basename(__FILE__)) . '/languages');
$this->cache_dependencies();
Wp_Hooks::add_wp_hooks();
$this->load_gutenberg_blocks();
$has_route = Router_Service::has_route();
if (!Options_Service::get_global_boolean_var('no_sso', false) && !$has_route) {
add_action('init', '\Wpo\Services\Authentication_Service::authenticate_request', 1);
}
}
/**
* @since 13.0
*
* To load the Gutenberg M365 blocks.
*/
private function load_gutenberg_blocks()
{
$apps = array(
'docs' => array(
'edition' => 'basic',
'load_front_end_assets' => true,
)
);
$plugins_dir = __DIR__;
$plugins_url = \plugins_url() . '/' . basename(__DIR__);
foreach ($apps as $app => $settings) {
new \Wpo\Blocks\Loader($app, $settings['edition'], $plugins_dir, $plugins_url, $settings['load_front_end_assets']);
}
}
private function cache_dependencies()
{
$this->dependencies = Dependency_Service::get_instance();
$this->dependencies->add('Request_Service', Request_Service::get_instance(true));
$this->dependencies->add('Files_Service', Files_Service::get_instance());
}
private function deactivation_hooks()
{
if (\class_exists('\Wpo\Sync\Sync_Manager')) {
// Delete possible cron jobs
register_deactivation_hook(__FILE__, function () {
\Wpo\Sync\Sync_Manager::get_scheduled_events(true);
});
}
if (\class_exists('\Wpo\Sync\SyncV2_Service')) {
// Delete possible cron jobs
register_deactivation_hook(__FILE__, function () {
\Wpo\Sync\SyncV2_Service::get_scheduled_events(null, true);
});
}
}
}
}
$wpo365_login = new Login();