-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmultisite-auth.php
More file actions
executable file
·206 lines (168 loc) · 5.53 KB
/
multisite-auth.php
File metadata and controls
executable file
·206 lines (168 loc) · 5.53 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<?php namespace MUAUTH;
/*
Plugin Name: Multisite Auth
Plugin URI: https://github.com/elhardoum/multisite-auth
Description: A multisite authentication plugin for handling logins, signups, password resets, activation account auth components all in one site
Author: Samuel Elh
Version: 0.1.4
Author URI: https://samelh.com
Text Domain: muauth
*/
// prevent direct access
defined('ABSPATH') || exit('Direct access not allowed.' . PHP_EOL);
if ( !class_exists('VersionCompare') ) :
/**
* Compares PHP versions
* Making sure this blog is running enough required PHP software for
* this plugin, currently requiring 5.3 at least for namespaces
*/
Class VersionCompare
{
public $hasRequiredPHP;
protected $min;
public function __construct( $minVersion = '5.3' )
{
$this->min = $minVersion;
if ( version_compare(PHP_VERSION, $this->min, '>=') ) {
$this->hasRequiredPHP = true;
} else {
$tag = 'admin_notices';
if ( is_multisite() && is_network_admin() ) {
$tag = "network_{$tag}";
}
add_action( $tag, array( $this, "notice" ) );
}
}
public function notice()
{
printf('<div class="error notice is-dismissible"><p>Multisite Auth plugin requires at least PHP %s.</p></div>',$this->min);
}
}
$muauthVersionCompare = new VersionCompare;
if ( !isset($muauthVersionCompare->hasRequiredPHP) || !$muauthVersionCompare->hasRequiredPHP ) {
return; // no min server requirements
}
endif;
use \MUAUTH\Includes\Core\Plugin
, \MUAUTH\Includes\Admin\Admin;
class MUAUTH
{
/** Class instance **/
protected static $instance = null;
/** Constants **/
public $constants;
/** Get Class instance **/
public static function instance()
{
return null == self::$instance ? new self : self::$instance;
}
public function setup()
{
return $this
->setupConstants()
->setupGlobals()
->registerAutoload()
->loadHelpers();
}
/** define necessary constants **/
public function setupConstants()
{
$this->constants = array(
"MUAUTH_FILE" => __FILE__,
"MUAUTH_DIR" => plugin_dir_path(__FILE__),
"MUAUTH_URL" => plugin_dir_url(__FILE__),
"MUAUTH_VER" => '0.1.2',
"MUAUTH_NAME" => __('Multisite Auth', 'muauth'),
"MUAUTH_BASE" => plugin_basename(__FILE__),
"MUAUTH_DOMAIN" => 'muauth'
);
/**
* Notice the use of defined() conditional, this means you can
* pre-define a constant or more in your wp-config file
*/
foreach ( $this->constants as $constant => $def ) {
if ( !defined( $constant ) ) {
define( $constant, $def );
}
}
return $this;
}
public function setupGlobals()
{
global $muauth_raw_components
, $muauth_errors;
$muauth_raw_components = array(
'login' => _x('Account Login', 'component name', 'muauth'),
'register' => _x('Sign Up', 'muauth'),
'lost-password' => _x('Password Reset', 'component name', 'muauth'),
'activation' => _x('Account Activation', 'component name', 'muauth'),
'logout' => _x('Log out', 'component name', 'muauth'),
);
$muauth_errors = (object) array(
'default' => new \WP_Error
);
return $this;
}
public function registerAutoload()
{
spl_autoload_register(array($this, 'autoload'));
return $this;
}
public function loadHelpers()
{
// include helpers
require_once MUAUTH_DIR . sprintf (
'Includes%1$sCore%1$sfunctions.php',
DIRECTORY_SEPARATOR
);
return $this;
}
/** autoloader **/
public function autoload($class) {
$classFile = $class;
// main parent namespace
$parentNamespace = __NAMESPACE__;
if ( "\{$parentNamespace}\\" === substr( $classFile, 0, (strlen($parentNamespace)+2) ) ) {
$classFile = substr( $classFile, (strlen($parentNamespace)+2) );
}
else if ( "{$parentNamespace}\\" === substr( $classFile, 0, (strlen($parentNamespace)+1) ) ) {
$classFile = substr( $classFile, (strlen($parentNamespace)+1) );
}
$classFile = MUAUTH_DIR."{$classFile}.php";
$classFile = str_replace( '\\', DIRECTORY_SEPARATOR, $classFile );
if ( !class_exists( $class ) && file_exists($classFile) ) {
return require( $classFile );
}
}
public static function verifyNonce($param='muauth_nonce', $action='muauth_nonce')
{
if ( !isset( $_REQUEST[$param] ) ) {
return;
}
return wp_verify_nonce($_REQUEST[$param], $action);
}
public static function loadTemplate($file)
{
// pluggable
$file = apply_filters("muauth_load_template_file", MUAUTH_DIR . "templates/{$file}", $file);
// include
if ( file_exists( $file ) ) {
include( $file );
}
}
}
// init
$MUAUTH = new MUAUTH;
$MUAUTH->setup();
// init plugin
Plugin::init();
if ( is_admin() ) {
// init admin
Admin::init();
}
/*
TODO:
- widgets: login
- addons: reCaptcha, google authenticator, mailchimp
- uninstall hooks
*/