-
Notifications
You must be signed in to change notification settings - Fork 0
/
temporary-access.php
133 lines (111 loc) · 2.4 KB
/
temporary-access.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
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
/**
* Plugin Name: Passwordless Temporary Login
* Description: Provide temporary access to users without password using direct login link.
* Version: 1.0.0
* Author: Ankit Gade
* Author URI: https://iamank.it
* License: GNU General Public License v2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Requires at least: 5.4.2
* Requires PHP: 7.3
* Text-Domain: passwordless-temporary-login
*
* @package Ankit\TemporaryAccess
* @since 1.0.0
*/
declare(strict_types=1);
namespace Ankit\TemporaryAccess;
use Pimple\Container as PimpleContainer;
// Prevent direct access.
defined( 'ABSPATH' ) || exit;
$hooks = array(
'admin_notices',
'network_admin_notices',
);
/**
* PHP 7.3+ is required in order to use the plugin.
*/
if ( version_compare( PHP_VERSION, '7.3', '<' ) ) {
foreach ( $hooks as $hook ) {
add_action(
$hook,
function () {
$message = __(
'Temporary Access Plugin requires PHP version 7.3 or higher. <br />Please ask your server administrator to update your environment to latest PHP version',
'temporary-access'
);
printf(
'<div class="notice notice-error"><span class="notice-title">%1$s</span><p>%2$s</p></div>',
esc_html__(
'The plugin Temporary Access has been deactivated',
'temporary-access'
),
wp_kses( $message, array( 'br' => true ) )
);
deactivate_plugins( plugin_basename( __FILE__ ) );
}
);
}
return;
}
/**
* Autoload the dependencies.
*
* @return bool
*/
function autoload(): bool {
static $done;
if ( is_bool( $done ) ) {
return $done;
}
if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) {
require_once __DIR__ . '/vendor/autoload.php';
$done = true;
return true;
}
$done = false;
return false;
}
/**
* Do not do anything if composer install
* is not run.
*/
if ( ! autoload() ) {
return;
}
/**
* Return the container instance.
*/
function container(): Container {
static $container;
if ( null !== $container ) {
return $container;
}
$container = new Container( new PimpleContainer() );
return $container;
}
/**
* Return the Plugin instance.
*
* @return Plugin
*/
function plugin(): Plugin {
static $plugin;
if ( null !== $plugin ) {
return $plugin;
}
$plugin = new Plugin( container() );
return $plugin;
}
/**
* Let the magic happen by
* running the plugin.
*/
add_action(
'plugins_loaded',
function () {
plugin()->run();
},
100
);