-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoidc-wp-roles.php
70 lines (59 loc) · 1.8 KB
/
oidc-wp-roles.php
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
<?php
/*
Plugin Name: OpenID Connect - WordPress Roles
Plugin URI: TBD
Description:
Author: daggerhart
Version: 1.0
Author URI: https://www.daggerhartlab.com
Text Domain: oidc-wp-roles
*/
define( 'OIDC_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
define( 'OIDC_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
if ( file_exists( __DIR__ . "/vendor/autoload.php" ) ) {
require_once __DIR__ . "/vendor/autoload.php";
\OidcRoles\Plugin::bootstrap();
}
/**
* Prepare database for plugin.
*/
register_activation_hook(__FILE__, 'oidc_wp_roles_install');
function oidc_wp_roles_install() {
require_once __DIR__ . "/vendor/autoload.php";
$handler = \OidcRoles\Service\LoggerFactory::getDefaultHandler();
$handler->initialize(['extra' => []]);
}
/**
* Clean up database after uninstall of plugin.
*/
register_uninstall_hook(__FILE__, 'oidc_wp_roles_uninstall');
function oidc_wp_roles_uninstall() {
require_once __DIR__ . "/vendor/autoload.php";
$handler = \OidcRoles\Service\LoggerFactory::getDefaultHandler();
$handler->uninitialize();
/**
* If "Cleanup" setting is enabled, then perform cleanup
*/
$container = \OidcRoles\Plugin::getContainer();
/** @var \OidcRoles\Service\Settings $settings */
$settings = $container->get( 'settings.general' );
if( ! $settings->get( 'cleanup', false ) ) {
return;
}
/**
* Remove roles created by this plugin
*/
/** @var \OidcRoles\Service\RoleManager $role_manager */
$role_manager = $container->get( 'role_manager' );
$oidc_roles = $role_manager->getOidcWpRoles();
foreach( $oidc_roles as $role ) {
remove_role( $role['slug'] );
}
/**
* Delete plugin settings
*/
delete_option( 'oidc_wp_roles_general_settings' );
delete_option( 'oidc_wp_roles_connections' );
delete_option( 'oidc_wp_roles_role_mapping' );
delete_option( 'oidc_wp_roles_field_mapping' );
}