PluginProbe
Advanced Access Manager – Access Governance for WordPress / 7.1.2
Advanced Access Manager – Access Governance for WordPress v7.1.2
7.1.4 7.1.2 7.1.3 6.8.4 6.8.5 6.9.0 6.9.1 6.9.10 6.9.11 6.9.12 6.9.13 6.9.14 6.9.15 6.9.16 6.9.17 6.9.18 6.9.19 6.9.2 6.9.20 6.9.21 6.9.22 6.9.23 6.9.24 6.9.25 6.9.26 All 210 releases
advanced-access-manager / aam.php
aam.php
311 lines 8.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Plugin Name: Advanced Access Manager – Access Governance for WordPress
5 * Description: Powerfully robust WordPress plugin designed to help you control every aspect of your website, your way.
6 * Version: 7.1.2
7 * Author: VasylTech LLC <support@aamplugin.com>
8 * Author URI: https://aamportal.com
9 * Text Domain: advanced-access-manager
10 * Domain Path: /lang/
11 * License: GPLv3
12 * License URI: http://www.gnu.org/licenses/gpl.html
13 *
14 **/
15
16 /**
17 * Main plugin's class
18 *
19 * @package AAM
20 * @author AAM <support@aamplugin.com>
21 *
22 * @version 7.0.0
23 */
24 class AAM
25 {
26
27 /**
28 * Collection of AAM services
29 *
30 * @version 7.0.0
31 */
32 const SERVICES = [
33 AAM_Service_Core::class => '__return_true',
34 AAM_Service_Urls::class => 'service.urls.enabled',
35 AAM_Service_LoginRedirect::class => 'service.login_redirect.enabled',
36 AAM_Service_LogoutRedirect::class => 'service.logout_redirect.enabled',
37 AAM_Service_AccessDeniedRedirect::class => 'service.access_denied_redirect.enabled',
38 AAM_Service_NotFoundRedirect::class => 'service.not_found_redirect.enabled',
39 AAM_Service_BackendMenu::class => 'service.backend_menu.enabled',
40 AAM_Service_Metaboxes::class => 'service.metaboxes.enabled',
41 AAM_Service_Widgets::class => 'service.widgets.enabled',
42 AAM_Service_AdminToolbar::class => 'service.admin_toolbar.enabled',
43 AAM_Service_ApiRoute::class => 'service.api_route.enabled',
44 AAM_Service_Identity::class => 'service.identity.enabled',
45 AAM_Service_Content::class => 'service.content.enabled',
46 AAM_Service_SecureLogin::class => 'service.secure_login.enabled',
47 AAM_Service_Jwt::class => 'service.jwt.enabled',
48 AAM_Service_Capability::class => 'service.capability.enabled',
49 AAM_Service_SecurityAudit::class => 'service.security_audit.enabled',
50 AAM_Service_Welcome::class => 'service.welcome.enabled',
51 AAM_Service_Hooks::class => 'service.hooks.enabled',
52 AAM_Service_Shortcodes::class => 'service.shortcodes.enabled',
53 AAM_Service_Policies::class => 'service.policies.enabled'
54 ];
55
56 /**
57 * Single instance of itself
58 *
59 * @var AAM
60 * @access private
61 *
62 * @version 7.0.0
63 */
64 private static $_instance = null;
65
66 /**
67 * Current user
68 *
69 * @var AAM_Framework_AccessLevel_Interface
70 * @access private
71 *
72 * @version 7.0.0
73 */
74 private $_current_user = null;
75
76 /**
77 * Initialize the AAM Object
78 *
79 * @return void
80 * @access protected
81 *
82 * @version 7.0.0
83 */
84 protected function __construct() { }
85
86 /**
87 * Get AAM API manager
88 *
89 * @return AAM_Core_Gateway
90 * @access public
91 *
92 * @version 7.0.0
93 */
94 public static function api()
95 {
96 return AAM_Core_Gateway::get_instance();
97 }
98
99 /**
100 * Get current user
101 *
102 * @return AAM_Framework_AccessLevel_Interface|null
103 * @access public
104 *
105 * @version 7.0.0
106 */
107 public static function current_user()
108 {
109 return self::get_instance()->_current_user;
110 }
111
112 /**
113 * Initialize current user
114 *
115 * @return void
116 * @access private
117 *
118 * @version 7.0.0
119 */
120 private function _init_current_user($user = null)
121 {
122 global $current_user;
123
124 // Important! Do not use WP core function to avoid loop
125 if (is_a($user, 'WP_User')) {
126 $id = $user->ID;
127 } else {
128 $id = (is_a($current_user, 'WP_User') ? $current_user->ID : null);
129 }
130
131 // Set current user
132 if (is_numeric($id) && $id > 0) {
133 $this->_current_user = self::api()->user($id);
134 } else {
135 $this->_current_user = self::api()->visitor();
136 }
137
138 // Updating AAM Framework default context. This way we do not have to write
139 // code like AAM::api()->user()->...
140 AAM::api()->setup($this->_current_user);
141 }
142
143 /**
144 * Bootstrap AAM when all plugins are loaded
145 *
146 * @return void
147 * @access public
148 *
149 * @version 7.0.5
150 */
151 public static function on_plugins_loaded()
152 {
153 // Load all the defined AAM services
154 foreach(self::SERVICES as $service_class => $flag) {
155 if ($flag === '__return_true' || AAM::api()->config->get($flag, true)) {
156 call_user_func("{$service_class}::bootstrap");
157 }
158 }
159 }
160
161 /**
162 * Hook on WP core init
163 *
164 * @return void
165 * @access public
166 *
167 * @version 7.0.0
168 */
169 public static function on_init()
170 {
171 if (is_admin()) {
172 AAM_Backend_Manager::bootstrap();
173 }
174
175 // Load AAM internationalization
176 load_plugin_textdomain(
177 'advanced-access-manager',
178 false,
179 'advanced-access-manager/lang'
180 );
181 }
182
183 /**
184 * Initialize the AAM plugin
185 *
186 * @return AAM
187 * @access public
188 *
189 * @version 7.0.0
190 */
191 public static function get_instance()
192 {
193 if (is_null(self::$_instance)) {
194 self::$_instance = new self;
195
196 // Make sure if user is changed dynamically, AAM adjusts accordingly
197 add_action('set_current_user', function() {
198 self::$_instance->_current_user = null;
199
200 // Reinitialize current user
201 self::$_instance->_init_current_user();
202 }, 1);
203
204 // The same with with after user login. WordPress core has bug with this
205 add_action('wp_login', function($_, $user) {
206 self::$_instance->_init_current_user($user);
207 }, 10, 2);
208
209 // Initialize current user
210 self::$_instance->_init_current_user();
211 }
212
213 return self::$_instance;
214 }
215
216 /**
217 * Activation hook
218 *
219 * @return void
220 * @access public
221 *
222 * @version 7.0.0
223 */
224 public static function activate()
225 {
226 global $wp_version;
227
228 // Check PHP Version
229 if (version_compare(PHP_VERSION, '5.6.40') === -1) {
230 exit(__('PHP 5.6.40 or higher is required.', 'advanced-access-manager'));
231 } elseif (version_compare($wp_version, '5.8.0') === -1) {
232 exit(__('WP 5.8.0 or higher is required.', 'advanced-access-manager'));
233 }
234 }
235
236 /**
237 * Redirect user to AAM page after plugin activation
238 *
239 * @param string $plugin
240 *
241 * @return void
242 *
243 * @access public
244 * @static
245 *
246 * @version 7.0.0
247 */
248 public static function activated_plugin($plugin)
249 {
250 $misc = AAM::api()->misc;
251
252 if (
253 $plugin === "advanced-access-manager/aam.php"
254 && !is_network_admin()
255 && $misc->get($_SERVER, 'REQUEST_METHOD') === 'GET'
256 && filter_input(INPUT_GET, 'action') === 'activate'
257 && $misc->get($_SERVER, 'SCRIPT_NAME') === '/wp-admin/plugins.php'
258 ) {
259 wp_redirect(admin_url('admin.php?page=aam')); exit;
260 }
261 }
262
263 /**
264 * Deactivate hook
265 *
266 * Remove all leftovers from AAM execution
267 *
268 * @return void
269 * @access public
270 *
271 * @version 7.0.0
272 */
273 public static function uninstall()
274 {
275 AAM_Service_Core::get_instance()->reset();
276
277 // Trigger any uninstall hook that is registered by any extension
278 do_action('aam_uninstall_action');
279 }
280
281 }
282
283 if (defined('ABSPATH')) {
284 // Define few common constants
285 define('AAM_MEDIA', plugins_url('/media', __FILE__));
286 define('AAM_KEY', 'advanced-access-manager');
287 define('AAM_VERSION', '7.1.2');
288 define('AAM_BASEDIR', __DIR__);
289
290 // Load vendor
291 require __DIR__ . '/vendor/autoload.php';
292
293 // Register autoloader
294 require(__DIR__ . '/autoloader.php');
295 AAM_Autoloader::register();
296
297 // Initialize AAM
298 AAM::get_instance();
299
300 // Load AAM service and register all the necessary initializations
301 add_action('plugins_loaded', 'AAM::on_plugins_loaded', -9999);
302 add_action('init', 'AAM::on_init');
303
304 // Activation & deactivation hooks
305 register_activation_hook(__FILE__, array('AAM', 'activate'));
306 register_uninstall_hook(__FILE__, array('AAM', 'uninstall'));
307
308 // Improve user experience by redirecting user to the AAM page after it is
309 // activated
310 add_action('activated_plugin', array('AAM', 'activated_plugin'));
311 }