Version Description
Download this release
Release Info
Developer | vasyltech |
Plugin | ![]() |
Version | 6.0.0-alpha.1 |
Comparing to | |
See all releases |
Code changes from version 5.10 to 6.0.0-alpha.1
- aam.php +90 -107
- application/Addon/Repository.php +262 -0
- application/Api/Manager.php +0 -157
- application/Api/Rest/Resource/Post.php +0 -432
- application/Api/Rest/Resource/Revision.php +0 -66
- application/Api/Rest/Resource/User.php +38 -60
- application/Backend/Authorization.php +0 -104
- application/Backend/Feature.php +59 -59
- application/Backend/Feature/Abstract.php +100 -36
- application/Backend/Feature/Extension/Manager.php +0 -217
- application/Backend/Feature/ISubjectAware.php +19 -0
- application/Backend/Feature/Main/404Redirect.php +53 -48
- application/Backend/Feature/Main/Capability.php +177 -218
- application/Backend/Feature/Main/Jwt.php +125 -94
- application/Backend/Feature/Main/LoginRedirect.php +46 -80
- application/Backend/Feature/Main/LogoutRedirect.php +47 -81
- application/Backend/Feature/Main/Menu.php +142 -140
- application/Backend/Feature/Main/Metabox.php +150 -133
- application/Backend/Feature/Main/Policy.php +63 -57
- application/Backend/Feature/Main/Post.php +755 -410
- application/Backend/Feature/Main/Redirect.php +45 -90
- application/Backend/Feature/Main/Route.php +68 -93
- application/Backend/Feature/Main/Toolbar.php +88 -92
- application/Backend/Feature/Main/Uri.php +91 -103
- application/Backend/Feature/Main/{GetStarted.php → Welcome.php} +21 -17
- application/Backend/Feature/Settings/ConfigPress.php +38 -40
- application/Backend/Feature/Settings/Content.php +35 -42
- application/Backend/Feature/Settings/Core.php +46 -95
- application/Backend/Feature/Settings/Manager.php +32 -27
- application/Backend/Feature/Settings/Security.php +43 -47
- application/Backend/Feature/Settings/Service.php +75 -0
- application/Backend/Feature/Subject/Role.php +179 -143
- application/Backend/Feature/Subject/User.php +206 -338
- application/Backend/Filter.php +0 -274
- application/Backend/Manager.php +148 -913
- application/Backend/Subject.php +158 -125
- application/Backend/View.php +244 -158
- application/Backend/View/Helper.php +27 -49
- application/Backend/View/Localization.php +91 -19
- application/Backend/View/PostOptionList.php +69 -145
- application/Backend/Widget/Login.php +71 -32
- application/Backend/phtml/extensions.phtml +0 -165
- application/Backend/phtml/index.phtml +13 -341
- application/Backend/phtml/main-panel.phtml +0 -30
- application/Backend/phtml/main/404redirect.phtml +0 -65
- application/Backend/phtml/main/get-started.phtml +0 -21
- application/Backend/phtml/main/logout-redirect.phtml +0 -69
- application/Backend/phtml/main/metabox.phtml +0 -113
- application/Backend/phtml/main/post.phtml +0 -91
- application/Backend/phtml/main/toolbar.phtml +0 -94
- application/Backend/phtml/metabox/iframe-footer.phtml +8 -0
- application/Backend/phtml/metabox/iframe-header.phtml +22 -0
- application/Backend/phtml/metabox/metabox-content.phtml +0 -178
- application/Backend/phtml/metabox/policy-metabox.phtml +9 -9
- application/Backend/phtml/metabox/post-iframe.phtml +19 -0
- application/Backend/phtml/metabox/post-metabox.phtml +3 -1
- application/Backend/phtml/metabox/term-metabox.phtml +8 -12
- application/Backend/phtml/page/addon-panel.phtml +110 -0
- application/Backend/phtml/page/current-subject.phtml +9 -0
- application/Backend/phtml/page/main-panel.phtml +36 -0
- application/Backend/phtml/page/subject-panel-advanced.phtml +117 -0
- application/Backend/phtml/page/subject-panel.phtml +90 -0
- application/Backend/phtml/partial/jwt-login-url.phtml +18 -0
- application/Backend/phtml/partial/login-redirect.phtml +0 -5
- application/Backend/phtml/partial/post-access-form.phtml +189 -112
- application/Backend/phtml/partial/post-advanced-settings.phtml +0 -181
- application/Backend/phtml/partial/post-type.phtml +0 -7
- application/Backend/phtml/partial/posts-terms-help-tips.phtml +11 -0
- application/Backend/phtml/partial/redirect.phtml +0 -5
- application/Backend/phtml/partial/role-inheritance.phtml +4 -2
- application/Backend/phtml/partial/taxonomy-access-form.phtml +16 -0
- application/Backend/phtml/partial/term-access-form.phtml +19 -0
- application/Backend/phtml/partial/term-type.phtml +0 -7
- application/Backend/phtml/partial/type-access-form.phtml +16 -0
- application/Backend/phtml/service/404redirect.phtml +67 -0
- application/Backend/phtml/{main → service}/capability.phtml +15 -19
- application/Backend/phtml/{main → service}/jwt.phtml +13 -12
- application/Backend/phtml/{main → service}/login-redirect.phtml +18 -16
- application/Backend/phtml/service/logout-redirect.phtml +71 -0
- application/Backend/phtml/{main → service}/menu.phtml +75 -34
- application/Backend/phtml/service/metabox.phtml +149 -0
- application/Backend/phtml/{main → service}/policy.phtml +1 -1
- application/Backend/phtml/service/post.phtml +39 -0
- application/Backend/phtml/{main → service}/redirect.phtml +35 -31
- application/Backend/phtml/{main → service}/route.phtml +8 -6
- application/Backend/phtml/service/toolbar.phtml +126 -0
- application/Backend/phtml/{main → service}/uri.phtml +30 -33
- application/Backend/phtml/service/welcome.phtml +23 -0
- application/Backend/phtml/settings/configpress.phtml +4 -2
- application/Backend/phtml/settings/content.phtml +20 -12
- application/Backend/phtml/settings/core.phtml +4 -2
- application/Backend/phtml/settings/security.phtml +5 -3
- application/Backend/phtml/settings/service.phtml +18 -0
- application/Backend/phtml/system/export.phtml +0 -67
- application/Backend/phtml/user/multiple-roles.phtml +21 -12
- application/Backend/phtml/widget/login-backend.phtml +2 -0
- application/Backend/phtml/widget/login-frontend.phtml +63 -27
- application/Core/API.php +199 -277
- application/Core/AccessSettings.php +163 -0
- application/Core/Api/Area.php +0 -79
- application/Core/Cache.php +0 -65
- application/Core/Compatibility.php +0 -398
- application/Core/Config.php +82 -77
- application/Core/ConfigPress.php +61 -52
- application/Core/ConfigPress/Evaluator.php +87 -57
- application/Core/ConfigPress/Reader.php +73 -34
- application/Core/Console.php +40 -41
- application/Core/Contract/MigrationInterface.php +30 -0
- application/Core/Contract/RequestTrait.php +113 -0
- application/Core/Contract/ServiceTrait.php +63 -0
- application/{Shortcode/Strategy/Interface.php → Core/Contract/ShortcodeInterface.php} +23 -10
- application/Core/Contract/SingletonTrait.php +73 -0
- application/Core/Exporter.php +0 -328
- application/Core/Gateway.php +167 -212
- application/Core/Importer.php +0 -301
- application/Core/Jwt/Auth.php +0 -64
- application/Core/Jwt/Issuer.php +85 -79
- application/Core/Jwt/Manager.php +0 -463
- application/Core/Login.php +0 -355
- application/Core/Media.php +0 -218
- application/Core/Migration.php +59 -0
- application/Core/Migration/2019_06_30-migrate-settings-to-6.0.0.php +381 -0
- application/Core/Object.php +229 -97
- application/Core/Object/Cache.php +0 -101
- application/Core/Object/Capability.php +0 -74
- application/Core/Object/LoginRedirect.php +22 -93
- application/Core/Object/LogoutRedirect.php +21 -89
- application/Core/Object/Menu.php +62 -242
- application/Core/Object/Metabox.php +41 -203
- application/Core/Object/Policy.php +21 -62
- application/Core/Object/Post.php +166 -256
- application/Core/Object/Redirect.php +30 -102
- application/Core/Object/Route.php +36 -79
- application/Core/Object/Toolbar.php +35 -96
- application/Core/Object/Uri.php +94 -151
- application/Core/Object/Visibility.php +67 -117
- application/Core/Policy/Condition.php +107 -104
- application/Core/Policy/Factory.php +1 -1
- application/Core/Policy/Manager.php +17 -27
- application/Core/Policy/Token.php +50 -68
- application/Core/Redirect.php +156 -0
- application/Core/Request.php +26 -15
- application/Core/Server.php +0 -116
- application/Core/Subject.php +266 -199
- application/Core/Subject/Default.php +27 -75
- application/Core/Subject/Role.php +105 -107
- application/Core/Subject/User.php +224 -484
- application/Core/Subject/Visitor.php +17 -70
- application/Extension/List.php +0 -99
- application/Extension/Repository.php +0 -493
- application/Frontend/Authorization.php +0 -205
- application/Frontend/Filter.php +0 -192
- application/Frontend/Manager.php +0 -187
- application/Frontend/phtml/login.phtml +0 -15
aam.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
/**
|
4 |
* Plugin Name: Advanced Access Manager
|
5 |
* Description: Collection of features to manage your WordPress website authentication, authorization and monitoring
|
6 |
-
* Version:
|
7 |
* Author: Vasyl Martyniuk <vasyl@vasyltech.com>
|
8 |
* Author URI: https://vasyltech.com
|
9 |
* Text Domain: advanced-access-manager
|
@@ -20,8 +20,10 @@
|
|
20 |
*
|
21 |
* @package AAM
|
22 |
* @author Vasyl Martyniuk <vasyl@vasyltech.com>
|
|
|
23 |
*/
|
24 |
-
class AAM
|
|
|
25 |
|
26 |
/**
|
27 |
* Single instance of itself
|
@@ -29,6 +31,7 @@ class AAM {
|
|
29 |
* @var AAM
|
30 |
*
|
31 |
* @access private
|
|
|
32 |
*/
|
33 |
private static $_instance = null;
|
34 |
|
@@ -38,6 +41,7 @@ class AAM {
|
|
38 |
* @var AAM_Core_Subject_User|AAM_Core_Subject_Visitor
|
39 |
*
|
40 |
* @access private
|
|
|
41 |
*/
|
42 |
private $_user = null;
|
43 |
|
@@ -47,14 +51,14 @@ class AAM {
|
|
47 |
* @return void
|
48 |
*
|
49 |
* @access protected
|
|
|
50 |
*/
|
51 |
-
protected function __construct()
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
}
|
58 |
}
|
59 |
|
60 |
/**
|
@@ -65,8 +69,10 @@ class AAM {
|
|
65 |
* @return void
|
66 |
*
|
67 |
* @access public
|
|
|
68 |
*/
|
69 |
-
public function setUser(AAM_Core_Subject $user)
|
|
|
70 |
$this->_user = $user;
|
71 |
}
|
72 |
|
@@ -76,9 +82,10 @@ class AAM {
|
|
76 |
* @return AAM_Core_Gateway
|
77 |
*
|
78 |
* @access public
|
79 |
-
* @
|
80 |
*/
|
81 |
-
public static function api()
|
|
|
82 |
return AAM_Core_Gateway::getInstance();
|
83 |
}
|
84 |
|
@@ -88,21 +95,47 @@ class AAM {
|
|
88 |
* @return AAM_Core_Subject
|
89 |
*
|
90 |
* @access public
|
|
|
91 |
*/
|
92 |
-
public static function getUser()
|
|
|
93 |
return self::getInstance()->_user;
|
94 |
}
|
95 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
/**
|
97 |
* Make sure that AAM UI Page is used
|
98 |
*
|
99 |
* @return boolean
|
100 |
*
|
101 |
* @access public
|
|
|
102 |
*/
|
103 |
-
public static function isAAM()
|
104 |
-
|
105 |
-
$
|
|
|
106 |
|
107 |
$intersect = array_intersect(array('aam', 'aamc'), array($page, $action));
|
108 |
|
@@ -110,37 +143,30 @@ class AAM {
|
|
110 |
}
|
111 |
|
112 |
/**
|
113 |
-
* Bootstrap AAM
|
114 |
*
|
115 |
* @return void
|
116 |
*
|
117 |
* @access public
|
118 |
-
* @
|
119 |
*/
|
120 |
-
public static function onPluginsLoaded()
|
121 |
-
|
|
|
122 |
AAM_Core_Config::bootstrap();
|
123 |
|
124 |
-
//
|
125 |
-
|
126 |
-
AAM_Core_Login::bootstrap();
|
127 |
-
}
|
128 |
|
129 |
-
//
|
130 |
-
|
131 |
-
|
|
|
|
|
132 |
}
|
133 |
|
134 |
// Load AAM
|
135 |
AAM::getInstance();
|
136 |
-
|
137 |
-
//load all installed extension
|
138 |
-
if (AAM_Core_Config::get('core.settings.extensionSupport', true)) {
|
139 |
-
AAM_Extension_Repository::getInstance()->load();
|
140 |
-
}
|
141 |
-
|
142 |
-
//load WP Core hooks
|
143 |
-
AAM_Shared_Manager::bootstrap();
|
144 |
}
|
145 |
|
146 |
/**
|
@@ -149,14 +175,12 @@ class AAM {
|
|
149 |
* @return void
|
150 |
*
|
151 |
* @access public
|
152 |
-
* @
|
153 |
*/
|
154 |
-
public static function onInit()
|
155 |
-
|
156 |
-
if (
|
157 |
AAM_Backend_Manager::bootstrap();
|
158 |
-
} elseif (AAM_Core_Api_Area::isFrontend()) {
|
159 |
-
AAM_Frontend_Manager::bootstrap();
|
160 |
}
|
161 |
}
|
162 |
|
@@ -166,89 +190,60 @@ class AAM {
|
|
166 |
* @return AAM
|
167 |
*
|
168 |
* @access public
|
169 |
-
* @
|
170 |
*/
|
171 |
-
public static function getInstance()
|
|
|
172 |
if (is_null(self::$_instance)) {
|
173 |
self::$_instance = new self;
|
174 |
|
175 |
-
//
|
176 |
-
|
177 |
-
|
178 |
-
// Load user capabilities
|
179 |
-
$user->initialize();
|
180 |
-
|
181 |
-
// Logout user if he/she is blocked
|
182 |
-
$status = $user->getUserStatus();
|
183 |
|
184 |
-
//
|
185 |
-
if (
|
186 |
-
|
187 |
}
|
188 |
-
|
189 |
-
load_plugin_textdomain(AAM_KEY, false, 'advanced-access-manager/lang');
|
190 |
}
|
191 |
|
192 |
return self::$_instance;
|
193 |
}
|
194 |
|
195 |
/**
|
196 |
-
*
|
197 |
-
*
|
198 |
-
* Check server extension versions
|
199 |
-
*
|
200 |
-
* @return void
|
201 |
-
*
|
202 |
-
* @access public
|
203 |
-
*/
|
204 |
-
public static function cron() {
|
205 |
-
$extensions = AAM_Core_API::getOption('aam-extensions', null, 'site');
|
206 |
-
|
207 |
-
if (!empty($extensions) && AAM_Core_Config::get('core.settings.cron', true)) {
|
208 |
-
//grab the server extension list
|
209 |
-
AAM_Core_API::updateOption(
|
210 |
-
'aam-check', AAM_Core_Server::check(), 'site'
|
211 |
-
);
|
212 |
-
}
|
213 |
-
}
|
214 |
-
|
215 |
-
/**
|
216 |
-
* Create aam folder
|
217 |
*
|
218 |
* @return void
|
219 |
*
|
220 |
* @access public
|
|
|
221 |
*/
|
222 |
-
public static function activate()
|
|
|
223 |
global $wp_version;
|
224 |
|
225 |
//check PHP Version
|
226 |
-
if (version_compare(PHP_VERSION, '5.
|
227 |
-
exit(__('PHP 5.
|
228 |
-
} elseif (version_compare($wp_version, '4.0') === -1) {
|
229 |
-
exit(__('WP 4.0 or higher is required.', AAM_KEY));
|
230 |
}
|
231 |
}
|
232 |
|
233 |
/**
|
234 |
-
*
|
235 |
*
|
236 |
* Remove all leftovers from AAM execution
|
237 |
*
|
238 |
* @return void
|
239 |
*
|
240 |
* @access public
|
|
|
241 |
*/
|
242 |
-
public static function uninstall()
|
|
|
243 |
//trigger any uninstall hook that is registered by any extension
|
244 |
do_action('aam-uninstall-action');
|
245 |
|
246 |
-
//remove aam directory if exists
|
247 |
-
$dirname = WP_CONTENT_DIR . '/aam';
|
248 |
-
if (file_exists($dirname)) {
|
249 |
-
AAM_Core_API::removeDirectory($dirname);
|
250 |
-
}
|
251 |
-
|
252 |
//clear all AAM settings
|
253 |
AAM_Core_API::clearSettings();
|
254 |
|
@@ -260,19 +255,16 @@ class AAM {
|
|
260 |
|
261 |
if (defined('ABSPATH')) {
|
262 |
//define few common constants
|
263 |
-
define(
|
264 |
-
'AAM_MEDIA',
|
265 |
-
preg_replace('/^http[s]?:/', '', plugins_url('/media', __FILE__))
|
266 |
-
);
|
267 |
define('AAM_KEY', 'advanced-access-manager');
|
268 |
-
define('
|
269 |
-
define('AAM_BASEDIR',
|
270 |
|
271 |
//load vendor
|
272 |
-
require
|
273 |
|
274 |
//register autoloader
|
275 |
-
require
|
276 |
AAM_Autoloader::register();
|
277 |
|
278 |
// Keep this as the lowest priority
|
@@ -282,15 +274,6 @@ if (defined('ABSPATH')) {
|
|
282 |
//this is important to have to catch events like register core post types
|
283 |
add_action('init', 'AAM::onInit', -1);
|
284 |
|
285 |
-
//register API manager is applicable
|
286 |
-
add_action('parse_request', 'AAM_Api_Manager::bootstrap', 1);
|
287 |
-
|
288 |
-
//schedule cron
|
289 |
-
if (!wp_next_scheduled('aam-cron')) {
|
290 |
-
wp_schedule_event(time(), 'daily', 'aam-cron');
|
291 |
-
}
|
292 |
-
add_action('aam-cron', 'AAM::cron');
|
293 |
-
|
294 |
//activation & deactivation hooks
|
295 |
register_activation_hook(__FILE__, array('AAM', 'activate'));
|
296 |
register_uninstall_hook(__FILE__, array('AAM', 'uninstall'));
|
3 |
/**
|
4 |
* Plugin Name: Advanced Access Manager
|
5 |
* Description: Collection of features to manage your WordPress website authentication, authorization and monitoring
|
6 |
+
* Version: 6.0.0-alpha.1
|
7 |
* Author: Vasyl Martyniuk <vasyl@vasyltech.com>
|
8 |
* Author URI: https://vasyltech.com
|
9 |
* Text Domain: advanced-access-manager
|
20 |
*
|
21 |
* @package AAM
|
22 |
* @author Vasyl Martyniuk <vasyl@vasyltech.com>
|
23 |
+
* @version 6.0.0
|
24 |
*/
|
25 |
+
class AAM
|
26 |
+
{
|
27 |
|
28 |
/**
|
29 |
* Single instance of itself
|
31 |
* @var AAM
|
32 |
*
|
33 |
* @access private
|
34 |
+
* @version 6.0.0
|
35 |
*/
|
36 |
private static $_instance = null;
|
37 |
|
41 |
* @var AAM_Core_Subject_User|AAM_Core_Subject_Visitor
|
42 |
*
|
43 |
* @access private
|
44 |
+
* @version 6.0.0
|
45 |
*/
|
46 |
private $_user = null;
|
47 |
|
51 |
* @return void
|
52 |
*
|
53 |
* @access protected
|
54 |
+
* @version 6.0.0
|
55 |
*/
|
56 |
+
protected function __construct()
|
57 |
+
{
|
58 |
+
// Initialize current subject
|
59 |
+
$this->changeUser();
|
60 |
+
|
61 |
+
add_action('set_current_user', array($this, 'changeUser'));
|
|
|
62 |
}
|
63 |
|
64 |
/**
|
69 |
* @return void
|
70 |
*
|
71 |
* @access public
|
72 |
+
* @version 6.0.0
|
73 |
*/
|
74 |
+
public function setUser(AAM_Core_Subject $user)
|
75 |
+
{
|
76 |
$this->_user = $user;
|
77 |
}
|
78 |
|
82 |
* @return AAM_Core_Gateway
|
83 |
*
|
84 |
* @access public
|
85 |
+
* @version 6.0.0
|
86 |
*/
|
87 |
+
public static function api()
|
88 |
+
{
|
89 |
return AAM_Core_Gateway::getInstance();
|
90 |
}
|
91 |
|
95 |
* @return AAM_Core_Subject
|
96 |
*
|
97 |
* @access public
|
98 |
+
* @version 6.0.0
|
99 |
*/
|
100 |
+
public static function getUser()
|
101 |
+
{
|
102 |
return self::getInstance()->_user;
|
103 |
}
|
104 |
|
105 |
+
/**
|
106 |
+
* Change current user
|
107 |
+
*
|
108 |
+
* This method is triggered if some process updates current user
|
109 |
+
*
|
110 |
+
* @return void
|
111 |
+
*
|
112 |
+
* @access public
|
113 |
+
* @version 6.0.0
|
114 |
+
*/
|
115 |
+
public function changeUser()
|
116 |
+
{
|
117 |
+
$id = get_current_user_id();
|
118 |
+
|
119 |
+
// Change current user
|
120 |
+
if ($id) {
|
121 |
+
$this->setUser(new AAM_Core_Subject_User($id));
|
122 |
+
} else {
|
123 |
+
$this->setUser(new AAM_Core_Subject_Visitor());
|
124 |
+
}
|
125 |
+
}
|
126 |
+
|
127 |
/**
|
128 |
* Make sure that AAM UI Page is used
|
129 |
*
|
130 |
* @return boolean
|
131 |
*
|
132 |
* @access public
|
133 |
+
* @version 6.0.0
|
134 |
*/
|
135 |
+
public static function isAAM()
|
136 |
+
{
|
137 |
+
$page = filter_input(INPUT_GET, 'page');
|
138 |
+
$action = filter_input(INPUT_POST, 'action');
|
139 |
|
140 |
$intersect = array_intersect(array('aam', 'aamc'), array($page, $action));
|
141 |
|
143 |
}
|
144 |
|
145 |
/**
|
146 |
+
* Bootstrap AAM when all plugins are loaded
|
147 |
*
|
148 |
* @return void
|
149 |
*
|
150 |
* @access public
|
151 |
+
* @version 6.0.0
|
152 |
*/
|
153 |
+
public static function onPluginsLoaded()
|
154 |
+
{
|
155 |
+
// Load AAM core config
|
156 |
AAM_Core_Config::bootstrap();
|
157 |
|
158 |
+
// Load the core service first
|
159 |
+
require_once __DIR__ . '/application/Service/Core.php';
|
|
|
|
|
160 |
|
161 |
+
// Load all the defined AAM services
|
162 |
+
foreach (new DirectoryIterator(__DIR__ . '/application/Service') as $service) {
|
163 |
+
if ($service->isFile()) {
|
164 |
+
require_once $service->getPathname();
|
165 |
+
}
|
166 |
}
|
167 |
|
168 |
// Load AAM
|
169 |
AAM::getInstance();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
170 |
}
|
171 |
|
172 |
/**
|
175 |
* @return void
|
176 |
*
|
177 |
* @access public
|
178 |
+
* @version 6.0.0
|
179 |
*/
|
180 |
+
public static function onInit()
|
181 |
+
{
|
182 |
+
if (is_admin()) {
|
183 |
AAM_Backend_Manager::bootstrap();
|
|
|
|
|
184 |
}
|
185 |
}
|
186 |
|
190 |
* @return AAM
|
191 |
*
|
192 |
* @access public
|
193 |
+
* @version 6.0.0
|
194 |
*/
|
195 |
+
public static function getInstance()
|
196 |
+
{
|
197 |
if (is_null(self::$_instance)) {
|
198 |
self::$_instance = new self;
|
199 |
|
200 |
+
// Load AAM internationalization
|
201 |
+
load_plugin_textdomain(AAM_KEY, false, 'advanced-access-manager/lang');
|
|
|
|
|
|
|
|
|
|
|
|
|
202 |
|
203 |
+
// Validate logged in user status
|
204 |
+
if (is_user_logged_in()) {
|
205 |
+
AAM::getUser()->validateStatus();
|
206 |
}
|
|
|
|
|
207 |
}
|
208 |
|
209 |
return self::$_instance;
|
210 |
}
|
211 |
|
212 |
/**
|
213 |
+
* Activation hook
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
214 |
*
|
215 |
* @return void
|
216 |
*
|
217 |
* @access public
|
218 |
+
* @version 6.0.0
|
219 |
*/
|
220 |
+
public static function activate()
|
221 |
+
{
|
222 |
global $wp_version;
|
223 |
|
224 |
//check PHP Version
|
225 |
+
if (version_compare(PHP_VERSION, '5.6.40') === -1) {
|
226 |
+
exit(__('PHP 5.6.40 or higher is required.', AAM_KEY));
|
227 |
+
} elseif (version_compare($wp_version, '4.7.0') === -1) {
|
228 |
+
exit(__('WP 4.7.0 or higher is required.', AAM_KEY));
|
229 |
}
|
230 |
}
|
231 |
|
232 |
/**
|
233 |
+
* Deactivate hook
|
234 |
*
|
235 |
* Remove all leftovers from AAM execution
|
236 |
*
|
237 |
* @return void
|
238 |
*
|
239 |
* @access public
|
240 |
+
* @version 6.0.0
|
241 |
*/
|
242 |
+
public static function uninstall()
|
243 |
+
{
|
244 |
//trigger any uninstall hook that is registered by any extension
|
245 |
do_action('aam-uninstall-action');
|
246 |
|
|
|
|
|
|
|
|
|
|
|
|
|
247 |
//clear all AAM settings
|
248 |
AAM_Core_API::clearSettings();
|
249 |
|
255 |
|
256 |
if (defined('ABSPATH')) {
|
257 |
//define few common constants
|
258 |
+
define('AAM_MEDIA', plugins_url('/media', __FILE__));
|
|
|
|
|
|
|
259 |
define('AAM_KEY', 'advanced-access-manager');
|
260 |
+
define('AAM_VERSION', '6.0.0');
|
261 |
+
define('AAM_BASEDIR', __DIR__);
|
262 |
|
263 |
//load vendor
|
264 |
+
require __DIR__ . '/vendor/autoload.php';
|
265 |
|
266 |
//register autoloader
|
267 |
+
require(__DIR__ . '/autoloader.php');
|
268 |
AAM_Autoloader::register();
|
269 |
|
270 |
// Keep this as the lowest priority
|
274 |
//this is important to have to catch events like register core post types
|
275 |
add_action('init', 'AAM::onInit', -1);
|
276 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
277 |
//activation & deactivation hooks
|
278 |
register_activation_hook(__FILE__, array('AAM', 'activate'));
|
279 |
register_uninstall_hook(__FILE__, array('AAM', 'uninstall'));
|
application/Addon/Repository.php
ADDED
@@ -0,0 +1,262 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* ======================================================================
|
5 |
+
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
+
* file 'license.txt', which is part of this source code package. *
|
7 |
+
* ======================================================================
|
8 |
+
*
|
9 |
+
* @version 6.0.0
|
10 |
+
*/
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Addon repository
|
14 |
+
*
|
15 |
+
* @package AAM
|
16 |
+
* @version 6.0.0
|
17 |
+
*/
|
18 |
+
class AAM_Addon_Repository
|
19 |
+
{
|
20 |
+
|
21 |
+
use AAM_Core_Contract_SingletonTrait;
|
22 |
+
|
23 |
+
/**
|
24 |
+
* DB options name
|
25 |
+
*
|
26 |
+
* @version 6.0.0
|
27 |
+
*/
|
28 |
+
const REGISTRY_OPTION = 'aam_addons';
|
29 |
+
|
30 |
+
/**
|
31 |
+
* Constructor
|
32 |
+
*
|
33 |
+
* @return void
|
34 |
+
*
|
35 |
+
* @access protected
|
36 |
+
* @version 6.0.0
|
37 |
+
*/
|
38 |
+
protected function __construct()
|
39 |
+
{
|
40 |
+
if (file_exists(ABSPATH . 'wp-admin/includes/plugin.php')) {
|
41 |
+
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
42 |
+
}
|
43 |
+
}
|
44 |
+
|
45 |
+
/**
|
46 |
+
* Get license registry
|
47 |
+
*
|
48 |
+
* @return array
|
49 |
+
*
|
50 |
+
* @access public
|
51 |
+
* @version 6.0.0
|
52 |
+
*/
|
53 |
+
public function getRegistry()
|
54 |
+
{
|
55 |
+
return AAM_Core_API::getOption(self::REGISTRY_OPTION, array(), 'site');
|
56 |
+
}
|
57 |
+
|
58 |
+
/**
|
59 |
+
* Check if there is at least one license registered
|
60 |
+
*
|
61 |
+
* @return boolean
|
62 |
+
*
|
63 |
+
* @access public
|
64 |
+
* @version 6.0.0
|
65 |
+
*/
|
66 |
+
public function hasRegistry()
|
67 |
+
{
|
68 |
+
return count($this->getRegistry()) > 0;
|
69 |
+
}
|
70 |
+
|
71 |
+
/**
|
72 |
+
* Store the license key
|
73 |
+
*
|
74 |
+
* @param object $package
|
75 |
+
* @param string $license
|
76 |
+
*
|
77 |
+
* @return void
|
78 |
+
*
|
79 |
+
* @access public
|
80 |
+
* @version 6.0.0
|
81 |
+
*/
|
82 |
+
public function storeLicense($package, $license)
|
83 |
+
{
|
84 |
+
$list = $this->getRegistry();
|
85 |
+
|
86 |
+
$list[$package->id] = array(
|
87 |
+
'license' => $license, 'expire' => $package->expire
|
88 |
+
);
|
89 |
+
|
90 |
+
// Update the registry
|
91 |
+
AAM_Core_API::updateOption(self::REGISTRY_OPTION, $list);
|
92 |
+
}
|
93 |
+
|
94 |
+
/**
|
95 |
+
* Get list of all addons with detailed information about each
|
96 |
+
*
|
97 |
+
* @return array
|
98 |
+
*
|
99 |
+
* @access public
|
100 |
+
* @version 6.0.0
|
101 |
+
*/
|
102 |
+
public function getList()
|
103 |
+
{
|
104 |
+
return array(
|
105 |
+
'aam-plus-package' => $this->buildAddonObject(
|
106 |
+
'Plus Package',
|
107 |
+
'plus-package',
|
108 |
+
__('Manage access to your WordPress website posts, pages, media, custom post types, categories, tags and custom taxonomies for any role, individual user, visitors or even define default access for everybody; and do this separately for frontend, backend or API levels.', AAM_KEY)
|
109 |
+
),
|
110 |
+
'aam-' => $this->buildAddonObject(
|
111 |
+
'IP Check',
|
112 |
+
'ip-check',
|
113 |
+
__('Manage access to your WordPress website by users IP address or referred host and completely lock down the entire website if necessary. Define the unlimited number of whitelisted or blacklisted IPs or hosts.', AAM_KEY)
|
114 |
+
),
|
115 |
+
'aam-' => $this->buildAddonObject(
|
116 |
+
'Role Hierarchy',
|
117 |
+
'role-hierarchy',
|
118 |
+
__('Define and manage complex WordPress role hierarchy where all the access settings are propagated down the tree with the ability to override any settings for any specific role.', AAM_KEY)
|
119 |
+
),
|
120 |
+
/**
|
121 |
+
* TODO: Release this extension after AAM 6.0.0. Enhance it with
|
122 |
+
* subscription functionality and possibly with email notification
|
123 |
+
* integration
|
124 |
+
'aam-ecommerce' => $this->buildAddonObject(
|
125 |
+
'E-Commerce',
|
126 |
+
'ecommerce',
|
127 |
+
__('Start monetizing access to your premium content. Restrict access to read any WordPress post, page or custom post type until user purchase access to it.', AAM_KEY)
|
128 |
+
),
|
129 |
+
*/
|
130 |
+
'aam-complete-package' => $this->buildAddonObject(
|
131 |
+
'Complete Package',
|
132 |
+
'complete-package',
|
133 |
+
__('Get the complete list of all premium AAM addons in one package and all future premium addons will be included for now additional cost.', AAM_KEY)
|
134 |
+
)
|
135 |
+
);
|
136 |
+
}
|
137 |
+
|
138 |
+
/**
|
139 |
+
* Build add-on data model
|
140 |
+
*
|
141 |
+
* @param string $title
|
142 |
+
* @param string $slug
|
143 |
+
* @param string $description
|
144 |
+
*
|
145 |
+
* @return array
|
146 |
+
*
|
147 |
+
* @access protected
|
148 |
+
* @version 6.0.0
|
149 |
+
*/
|
150 |
+
protected function buildAddonObject($title, $slug, $description)
|
151 |
+
{
|
152 |
+
return array(
|
153 |
+
'title' => $title,
|
154 |
+
'version' => $this->getPluginVersion("aam-{$slug}/bootstrap.php"),
|
155 |
+
'isActive' => $this->isPluginActive("aam-{$slug}/bootstrap.php"),
|
156 |
+
'expires' => $this->getExpirationDate("aam-{$slug}"),
|
157 |
+
'license' => $this->getPluginLicense("aam-{$slug}"),
|
158 |
+
'type' => 'commercial',
|
159 |
+
'description' => $description,
|
160 |
+
'url' => 'https://aamplugin.com/pricing/' . $slug
|
161 |
+
);
|
162 |
+
}
|
163 |
+
|
164 |
+
/**
|
165 |
+
* Get plugin version
|
166 |
+
*
|
167 |
+
* @param string $plugin
|
168 |
+
*
|
169 |
+
* @return string
|
170 |
+
*
|
171 |
+
* @access public
|
172 |
+
* @version 6.0.0
|
173 |
+
*/
|
174 |
+
public function getPluginVersion($plugin)
|
175 |
+
{
|
176 |
+
$data = $this->getPluginData($plugin);
|
177 |
+
$version = (isset($data['Version']) ? $data['Version'] : null);
|
178 |
+
|
179 |
+
return (!empty($version) ? $version : null);
|
180 |
+
}
|
181 |
+
|
182 |
+
/**
|
183 |
+
* Get plugin details from the WP core
|
184 |
+
*
|
185 |
+
* @param string $plugin
|
186 |
+
*
|
187 |
+
* @return array|null
|
188 |
+
*
|
189 |
+
* @access protected
|
190 |
+
* @version 6.0.0
|
191 |
+
*/
|
192 |
+
protected function getPluginData($plugin)
|
193 |
+
{
|
194 |
+
$filename = WP_PLUGIN_DIR . '/' . $plugin;
|
195 |
+
|
196 |
+
if (function_exists('get_plugin_data') && file_exists($filename)) {
|
197 |
+
$data = get_plugin_data($filename);
|
198 |
+
} else {
|
199 |
+
$data = null;
|
200 |
+
}
|
201 |
+
|
202 |
+
return $data;
|
203 |
+
}
|
204 |
+
|
205 |
+
/**
|
206 |
+
* Check if plugin is active
|
207 |
+
*
|
208 |
+
* @param string $plugin
|
209 |
+
*
|
210 |
+
* @return boolean
|
211 |
+
*
|
212 |
+
* @access protected
|
213 |
+
* @version 6.0.0
|
214 |
+
*/
|
215 |
+
protected function isPluginActive($plugin)
|
216 |
+
{
|
217 |
+
$data = self::getPluginData($plugin);
|
218 |
+
|
219 |
+
if (!empty($data)) {
|
220 |
+
$active = is_plugin_active($plugin);
|
221 |
+
} else {
|
222 |
+
$active = false;
|
223 |
+
}
|
224 |
+
|
225 |
+
return $active;
|
226 |
+
}
|
227 |
+
|
228 |
+
/**
|
229 |
+
* Get license expiration date
|
230 |
+
*
|
231 |
+
* @param string $plugin
|
232 |
+
*
|
233 |
+
* @return string|null
|
234 |
+
*
|
235 |
+
* @access protected
|
236 |
+
* @version 6.0.0
|
237 |
+
*/
|
238 |
+
protected function getExpirationDate($plugin)
|
239 |
+
{
|
240 |
+
$registry = $this->getRegistry();
|
241 |
+
|
242 |
+
return (isset($registry[$plugin]) ? $registry[$plugin]['expires'] : null);
|
243 |
+
}
|
244 |
+
|
245 |
+
/**
|
246 |
+
* Get plugin license key
|
247 |
+
*
|
248 |
+
* @param string $plugin
|
249 |
+
*
|
250 |
+
* @return string|null
|
251 |
+
*
|
252 |
+
* @access protected
|
253 |
+
* @version 6.0.0
|
254 |
+
*/
|
255 |
+
protected function getPluginLicense($plugin)
|
256 |
+
{
|
257 |
+
$registry = $this->getRegistry();
|
258 |
+
|
259 |
+
return (isset($registry[$plugin]) ? $registry[$plugin]['license'] : null);
|
260 |
+
}
|
261 |
+
|
262 |
+
}
|
application/Api/Manager.php
DELETED
@@ -1,157 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* ======================================================================
|
5 |
-
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
-
* file 'license.txt', which is part of this source code package. *
|
7 |
-
* ======================================================================
|
8 |
-
*/
|
9 |
-
|
10 |
-
/**
|
11 |
-
* AAM Api access manager
|
12 |
-
*
|
13 |
-
* @package AAM
|
14 |
-
* @author Vasyl Martyniuk <vasyl@vasyltech.com>
|
15 |
-
*/
|
16 |
-
class AAM_Api_Manager {
|
17 |
-
|
18 |
-
/**
|
19 |
-
* Instance of itself
|
20 |
-
*
|
21 |
-
* @var AAM_Api_Manager
|
22 |
-
*
|
23 |
-
* @access private
|
24 |
-
*/
|
25 |
-
private static $_instance = null;
|
26 |
-
|
27 |
-
/**
|
28 |
-
* Map of routes and resources
|
29 |
-
*
|
30 |
-
* @var array
|
31 |
-
*
|
32 |
-
* @access protected
|
33 |
-
*/
|
34 |
-
protected $resources = array(
|
35 |
-
'post' => array (
|
36 |
-
'/wp/v2/posts',
|
37 |
-
'/wp/v2/posts/(?P<id>[\d]+)',
|
38 |
-
'/wp/v2/pages',
|
39 |
-
'/wp/v2/pages/(?P<id>[\d]+)',
|
40 |
-
'/wp/v2/media',
|
41 |
-
'/wp/v2/media/(?P<id>[\d]+)',
|
42 |
-
),
|
43 |
-
'user' => array (
|
44 |
-
'/wp/v2/users'
|
45 |
-
),
|
46 |
-
'revision' => array (
|
47 |
-
'/wp/v2/posts/(?P<parent>[\d]+)/revisions/(?P<id>[\d]+)',
|
48 |
-
'/wp/v2/pages/(?P<parent>[\d]+)/revisions/(?P<id>[\d]+)'
|
49 |
-
)
|
50 |
-
);
|
51 |
-
|
52 |
-
/**
|
53 |
-
* Construct the manager
|
54 |
-
*
|
55 |
-
* @return void
|
56 |
-
*
|
57 |
-
* @access public
|
58 |
-
*/
|
59 |
-
protected function __construct() {
|
60 |
-
if (AAM_Core_Config::get('core.settings.apiAccessControl', true)) {
|
61 |
-
// REST API action authorization. Triggered before call is dispatched
|
62 |
-
add_filter(
|
63 |
-
'rest_request_before_callbacks', array($this, 'beforeDispatch'), 10, 3
|
64 |
-
);
|
65 |
-
|
66 |
-
// Manage access to the RESTful endpoints
|
67 |
-
add_filter('rest_pre_dispatch', array($this, 'authorizeRest'), 1, 3);
|
68 |
-
|
69 |
-
// Register any additional endpoints with ConfigPress
|
70 |
-
$additional = AAM_Core_Config::get('rest.manage.endpoint');
|
71 |
-
|
72 |
-
if (!empty($additional) && is_array($additional)) {
|
73 |
-
$this->resources = array_merge_recursive($this->resources, $additional);
|
74 |
-
}
|
75 |
-
}
|
76 |
-
}
|
77 |
-
|
78 |
-
/**
|
79 |
-
* Authorize RESTful action before it is dispatched by RESTful Server
|
80 |
-
*
|
81 |
-
* @param mixed $response
|
82 |
-
* @param object $handler
|
83 |
-
* @param object $request
|
84 |
-
*
|
85 |
-
* @return mixed
|
86 |
-
*
|
87 |
-
* @access public
|
88 |
-
*/
|
89 |
-
public function beforeDispatch($response, $handler, $request) {
|
90 |
-
$result = null;
|
91 |
-
|
92 |
-
foreach($this->resources as $res => $routes) {
|
93 |
-
foreach($routes as $regex) {
|
94 |
-
// Route to work with single post
|
95 |
-
if(preg_match('#^' . $regex . '$#i', $request->get_route())) {
|
96 |
-
$classname = 'AAM_Api_Rest_Resource_' . ucfirst($res);
|
97 |
-
$result = $classname::getInstance()->authorize($request);
|
98 |
-
}
|
99 |
-
}
|
100 |
-
}
|
101 |
-
|
102 |
-
return (is_null($result) ? $response : $result);
|
103 |
-
}
|
104 |
-
|
105 |
-
/**
|
106 |
-
* Authorize REST request
|
107 |
-
*
|
108 |
-
* Based on the matched route, check if it is disabled for current user
|
109 |
-
*
|
110 |
-
* @param WP_Error|null $response
|
111 |
-
* @param WP_REST_Server $server
|
112 |
-
* @param WP_REST_Request $request
|
113 |
-
*
|
114 |
-
* @return WP_Error|null
|
115 |
-
*
|
116 |
-
* @access public
|
117 |
-
*/
|
118 |
-
public function authorizeRest($response, $server, $request) {
|
119 |
-
$user = AAM::getUser();
|
120 |
-
$object = $user->getObject('route');
|
121 |
-
$matched = $request->get_route();
|
122 |
-
$method = $request->get_method();
|
123 |
-
|
124 |
-
foreach(array_keys($server->get_routes()) as $route) {
|
125 |
-
if ($route === $matched || preg_match("#^{$route}$#i", $matched)) {
|
126 |
-
if ($object->has('restful', $route, $method)) {
|
127 |
-
$response = new WP_Error(
|
128 |
-
'rest_access_denied',
|
129 |
-
__('Access denied', AAM_KEY),
|
130 |
-
array('status' => 401)
|
131 |
-
);
|
132 |
-
break;
|
133 |
-
}
|
134 |
-
}
|
135 |
-
}
|
136 |
-
|
137 |
-
return $response;
|
138 |
-
}
|
139 |
-
|
140 |
-
/**
|
141 |
-
* Bootstrap the manager
|
142 |
-
*
|
143 |
-
* @return void
|
144 |
-
*
|
145 |
-
* @access public
|
146 |
-
*/
|
147 |
-
public static function bootstrap() {
|
148 |
-
global $wp;
|
149 |
-
|
150 |
-
if (!empty($wp->query_vars['rest_route'])) {
|
151 |
-
if (is_null(self::$_instance)) {
|
152 |
-
self::$_instance = new self;
|
153 |
-
}
|
154 |
-
}
|
155 |
-
}
|
156 |
-
|
157 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
application/Api/Rest/Resource/Post.php
DELETED
@@ -1,432 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* ======================================================================
|
5 |
-
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
-
* file 'license.txt', which is part of this source code package. *
|
7 |
-
* ======================================================================
|
8 |
-
*/
|
9 |
-
|
10 |
-
/**
|
11 |
-
* AAM RESTful Posts Resource
|
12 |
-
*
|
13 |
-
* @package AAM
|
14 |
-
* @author Vasyl Martyniuk <vasyl@vasyltech.com>
|
15 |
-
* @todo Rethink about DRY approach to the post access control
|
16 |
-
*/
|
17 |
-
class AAM_Api_Rest_Resource_Post {
|
18 |
-
|
19 |
-
/**
|
20 |
-
* Instance of itself
|
21 |
-
*
|
22 |
-
* @var AAM_Api_Rest_Resource_Post
|
23 |
-
*
|
24 |
-
* @access private
|
25 |
-
*/
|
26 |
-
private static $_instance = null;
|
27 |
-
|
28 |
-
/**
|
29 |
-
* Authorize Post actions
|
30 |
-
*
|
31 |
-
* @param WP_REST_Request $request
|
32 |
-
*
|
33 |
-
* @return WP_Error|null
|
34 |
-
*
|
35 |
-
* @access public
|
36 |
-
*/
|
37 |
-
public function authorize($request) {
|
38 |
-
$result = null;
|
39 |
-
|
40 |
-
if ($request['id']) {
|
41 |
-
$post = AAM::getUser()->getObject('post', $request['id']);
|
42 |
-
|
43 |
-
switch($request->get_method()) {
|
44 |
-
case 'GET':
|
45 |
-
$result = $this->authorizeRead($post, $request);
|
46 |
-
break;
|
47 |
-
|
48 |
-
case 'POST':
|
49 |
-
case 'PUT':
|
50 |
-
case 'PATCH':
|
51 |
-
if ($request['status'] === 'publish') {
|
52 |
-
$result = $this->authorizePublish($post);
|
53 |
-
} else {
|
54 |
-
$result = $this->authorizeUpdate($post);
|
55 |
-
}
|
56 |
-
break;
|
57 |
-
|
58 |
-
case 'DELETE':
|
59 |
-
$result = $this->authorizeDelete($post);
|
60 |
-
break;
|
61 |
-
|
62 |
-
default:
|
63 |
-
break;
|
64 |
-
}
|
65 |
-
}
|
66 |
-
|
67 |
-
return $result;
|
68 |
-
}
|
69 |
-
|
70 |
-
/**
|
71 |
-
* Check post access
|
72 |
-
*
|
73 |
-
* Based on the provided post object, check if current user has access to it.
|
74 |
-
* This method run multiple checks at-once
|
75 |
-
*
|
76 |
-
* @param AAM_Core_Object_Post $post
|
77 |
-
* @param WP_REST_Request $request
|
78 |
-
*
|
79 |
-
* @return void
|
80 |
-
*
|
81 |
-
* @access protected
|
82 |
-
*/
|
83 |
-
protected function authorizeRead(AAM_Core_Object_Post $post, $request) {
|
84 |
-
$steps = array(
|
85 |
-
// Step #1. Check if access expired to the post
|
86 |
-
array($this, 'checkExpiration'),
|
87 |
-
// Step #2. Check if user has access to read the post
|
88 |
-
array($this, 'checkReadAccess'),
|
89 |
-
// Step #3. Check if counter exceeded max allowed views
|
90 |
-
array($this, 'checkCounter'),
|
91 |
-
// Step #4. Check if redirect is defined for the post
|
92 |
-
array($this, 'checkRedirect'),
|
93 |
-
// Step #5. Check if post is password protected
|
94 |
-
array($this, 'checkPassword')
|
95 |
-
);
|
96 |
-
|
97 |
-
return $this->processPipeline($steps, $post, $request);
|
98 |
-
}
|
99 |
-
|
100 |
-
/**
|
101 |
-
*
|
102 |
-
* @param AAM_Core_Object_Post $post
|
103 |
-
* @return type
|
104 |
-
*/
|
105 |
-
protected function authorizePublish(AAM_Core_Object_Post $post) {
|
106 |
-
$steps = array(
|
107 |
-
// Step #1. Check if publish action is allowed
|
108 |
-
array($this, 'checkPublish'),
|
109 |
-
);
|
110 |
-
|
111 |
-
return $this->processPipeline($steps, $post);
|
112 |
-
}
|
113 |
-
|
114 |
-
/**
|
115 |
-
*
|
116 |
-
* @param AAM_Core_Object_Post $post
|
117 |
-
* @return type
|
118 |
-
*/
|
119 |
-
protected function authorizeUpdate(AAM_Core_Object_Post $post) {
|
120 |
-
$steps = array(
|
121 |
-
// Step #1. Check if edit action is allowed
|
122 |
-
array($this, 'checkUpdate'),
|
123 |
-
);
|
124 |
-
|
125 |
-
return $this->processPipeline($steps, $post);
|
126 |
-
}
|
127 |
-
|
128 |
-
/**
|
129 |
-
*
|
130 |
-
* @param AAM_Core_Object_Post $post
|
131 |
-
* @return type
|
132 |
-
*/
|
133 |
-
protected function authorizeDelete(AAM_Core_Object_Post $post) {
|
134 |
-
$steps = array(
|
135 |
-
// Step #1. Check if edit action is allowed
|
136 |
-
array($this, 'checkDelete'),
|
137 |
-
);
|
138 |
-
|
139 |
-
return $this->processPipeline($steps, $post);
|
140 |
-
}
|
141 |
-
|
142 |
-
/**
|
143 |
-
*
|
144 |
-
* @param array $pipeline
|
145 |
-
* @param type $post
|
146 |
-
* @param type $request
|
147 |
-
* @return type
|
148 |
-
*/
|
149 |
-
protected function processPipeline(array $pipeline, $post, $request = null) {
|
150 |
-
foreach($pipeline as $callback) {
|
151 |
-
$result = call_user_func_array($callback, array($post, $request));
|
152 |
-
|
153 |
-
if (is_wp_error($result)) { break; }
|
154 |
-
}
|
155 |
-
|
156 |
-
return $result;
|
157 |
-
}
|
158 |
-
|
159 |
-
/**
|
160 |
-
* Check ACCESS_EXPIRATION option
|
161 |
-
*
|
162 |
-
* If access is expired, override the access settings based on the
|
163 |
-
* post.access.expired ConfigPress settings (default frontend.read)
|
164 |
-
*
|
165 |
-
* @param AAM_Core_Object_Post $post
|
166 |
-
*
|
167 |
-
* @return void
|
168 |
-
*
|
169 |
-
* @access protected
|
170 |
-
*/
|
171 |
-
protected function checkExpiration($post) {
|
172 |
-
$expire = $post->has('api.expire');
|
173 |
-
|
174 |
-
if ($expire) {
|
175 |
-
$date = strtotime($post->get('api.expire_datetime'));
|
176 |
-
if ($date <= time()) {
|
177 |
-
$actions = AAM_Core_Config::get(
|
178 |
-
'feature.api.postAccess.expired', 'api.read'
|
179 |
-
);
|
180 |
-
|
181 |
-
foreach(array_map('trim', explode(',', $actions)) as $action) {
|
182 |
-
$post->set($action, 1);
|
183 |
-
}
|
184 |
-
}
|
185 |
-
}
|
186 |
-
}
|
187 |
-
|
188 |
-
/**
|
189 |
-
* Check READ & READ_OTHERS options
|
190 |
-
*
|
191 |
-
* @param AAM_Core_Object_Post $post
|
192 |
-
*
|
193 |
-
* @return void
|
194 |
-
*
|
195 |
-
* @access protected
|
196 |
-
*/
|
197 |
-
protected function checkReadAccess(AAM_Core_Object_Post $post) {
|
198 |
-
$result = null;
|
199 |
-
|
200 |
-
if (!$post->allowed('api.read')) {
|
201 |
-
$result = new WP_Error(
|
202 |
-
'rest_post_cannot_read',
|
203 |
-
"User is unauthorized to read the post. Access denied.",
|
204 |
-
array(
|
205 |
-
'action' => 'api.read',
|
206 |
-
'status' => 401
|
207 |
-
)
|
208 |
-
);
|
209 |
-
}
|
210 |
-
|
211 |
-
return $result;
|
212 |
-
}
|
213 |
-
|
214 |
-
/**
|
215 |
-
* Check ACCESS_COUNTER option
|
216 |
-
*
|
217 |
-
* @param AAM_Core_Object_Post $post
|
218 |
-
*
|
219 |
-
* @return void
|
220 |
-
*
|
221 |
-
* @access protected
|
222 |
-
*/
|
223 |
-
protected function checkCounter(AAM_Core_Object_Post $post) {
|
224 |
-
$result = null;
|
225 |
-
$user = get_current_user_id();
|
226 |
-
|
227 |
-
//check counter only for authenticated users and if ACCESS COUNTER is set
|
228 |
-
if ($user && $post->has('api.access_counter')) {
|
229 |
-
$option = 'aam-post-api-' . $post->ID . '-access-counter';
|
230 |
-
$counter = intval(get_user_meta($user, $option, true));
|
231 |
-
|
232 |
-
if ($counter >= $post->get('api.access_counter_limit')) {
|
233 |
-
$result = new WP_Error(
|
234 |
-
'rest_post_cannot_read',
|
235 |
-
"User exceeded allowed read number. Access denied.",
|
236 |
-
array(
|
237 |
-
'action' => 'api.access_counter',
|
238 |
-
'status' => 401
|
239 |
-
)
|
240 |
-
);
|
241 |
-
} else {
|
242 |
-
update_user_meta($user, $option, ++$counter);
|
243 |
-
}
|
244 |
-
}
|
245 |
-
|
246 |
-
return $result;
|
247 |
-
}
|
248 |
-
|
249 |
-
/**
|
250 |
-
* Check REDIRECT option
|
251 |
-
*
|
252 |
-
* @param AAM_Core_Object_Post $post
|
253 |
-
*
|
254 |
-
* @return void
|
255 |
-
*
|
256 |
-
* @access protected
|
257 |
-
*/
|
258 |
-
protected function checkRedirect(AAM_Core_Object_Post $post) {
|
259 |
-
$result = null;
|
260 |
-
|
261 |
-
if ($post->has('api.redirect')) {
|
262 |
-
$rule = explode('|', $post->get('api.location'));
|
263 |
-
|
264 |
-
if (count($rule) === 1) { // TODO: legacy. Remove in Jul 2020
|
265 |
-
$redirect = $rule[0];
|
266 |
-
} elseif ($rule[0] === 'page') {
|
267 |
-
$redirect = get_page_link($rule[1]);
|
268 |
-
} elseif ($rule[0] === 'url') {
|
269 |
-
$redirect = $rule[1];
|
270 |
-
} elseif (($rule[0] === 'callback') && is_callable($rule[1])) {
|
271 |
-
$redirect = call_user_func($rule[1], $post);
|
272 |
-
} else {
|
273 |
-
$redirect = null;
|
274 |
-
}
|
275 |
-
|
276 |
-
$result = new WP_Error(
|
277 |
-
'rest_post_cannot_read',
|
278 |
-
"Direct access is not allowed. Follow the redirect link.",
|
279 |
-
array(
|
280 |
-
'action' => 'api.redirect',
|
281 |
-
'redirect' => $redirect,
|
282 |
-
'status' => 307
|
283 |
-
)
|
284 |
-
);
|
285 |
-
}
|
286 |
-
|
287 |
-
return $result;
|
288 |
-
}
|
289 |
-
|
290 |
-
/**
|
291 |
-
* Check PASSWORD PROTECTED option
|
292 |
-
*
|
293 |
-
* @param AAM_Core_Object_Post $post
|
294 |
-
* @param WP_REST_Request $request
|
295 |
-
*
|
296 |
-
* @return null|WP_Error
|
297 |
-
*
|
298 |
-
* @access public
|
299 |
-
*/
|
300 |
-
public function checkPassword(AAM_Core_Object_Post $post, $request) {
|
301 |
-
$result = null;
|
302 |
-
|
303 |
-
if ($post->has('api.protected')) {
|
304 |
-
$pass = $post->get('api.password');
|
305 |
-
|
306 |
-
if ($request['password'] !== $pass) {
|
307 |
-
$result = new WP_Error(
|
308 |
-
'rest_post_cannot_read',
|
309 |
-
"The content is password protected. Provide valid password to read.",
|
310 |
-
array(
|
311 |
-
'action' => 'api.protected',
|
312 |
-
'status' => 401
|
313 |
-
)
|
314 |
-
);
|
315 |
-
}
|
316 |
-
|
317 |
-
// Very important! Unset password. Otherwise it will fall back to the
|
318 |
-
// default password verification and this will cause invalid password
|
319 |
-
// response
|
320 |
-
$request['password'] = null;
|
321 |
-
}
|
322 |
-
|
323 |
-
return $result;
|
324 |
-
}
|
325 |
-
|
326 |
-
/**
|
327 |
-
* Check PUBLISH & PUBLISH_BY_OTHERS options
|
328 |
-
*
|
329 |
-
* @param AAM_Core_Object_Post $post
|
330 |
-
*
|
331 |
-
* @return void
|
332 |
-
*
|
333 |
-
* @access protected
|
334 |
-
*/
|
335 |
-
protected function checkPublish(AAM_Core_Object_Post $post) {
|
336 |
-
$result = null;
|
337 |
-
|
338 |
-
// Keep this compatible with older version of Publish (without Gutenberg)
|
339 |
-
if (!$post->allowed('api.publish') || !$post->allowed('backend.publish')) {
|
340 |
-
$result = new WP_Error(
|
341 |
-
'rest_post_cannot_publish',
|
342 |
-
"User is unauthorized to publish the post. Access denied.",
|
343 |
-
array(
|
344 |
-
'action' => 'api.publish',
|
345 |
-
'status' => 401
|
346 |
-
)
|
347 |
-
);
|
348 |
-
}
|
349 |
-
|
350 |
-
return $result;
|
351 |
-
}
|
352 |
-
|
353 |
-
/**
|
354 |
-
* Check EDIT & EDIT_BY_OTHERS options
|
355 |
-
*
|
356 |
-
* @param AAM_Core_Object_Post $post
|
357 |
-
*
|
358 |
-
* @return void
|
359 |
-
*
|
360 |
-
* @access protected
|
361 |
-
*/
|
362 |
-
protected function checkUpdate(AAM_Core_Object_Post $post) {
|
363 |
-
$result = null;
|
364 |
-
|
365 |
-
if (!$post->allowed('api.edit')) {
|
366 |
-
$result = new WP_Error(
|
367 |
-
'rest_post_cannot_update',
|
368 |
-
"User is unauthorized to update the post. Access denied.",
|
369 |
-
array(
|
370 |
-
'action' => 'api.edit',
|
371 |
-
'status' => 401
|
372 |
-
)
|
373 |
-
);
|
374 |
-
}
|
375 |
-
|
376 |
-
return $result;
|
377 |
-
}
|
378 |
-
|
379 |
-
/**
|
380 |
-
* Check DELETE & DELETE_BY_OTHERS options
|
381 |
-
*
|
382 |
-
* @param AAM_Core_Object_Post $post
|
383 |
-
*
|
384 |
-
* @return void
|
385 |
-
*
|
386 |
-
* @access protected
|
387 |
-
*/
|
388 |
-
protected function checkDelete(AAM_Core_Object_Post $post) {
|
389 |
-
$result = null;
|
390 |
-
|
391 |
-
if (!$post->allowed('api.delete')) {
|
392 |
-
$result = new WP_Error(
|
393 |
-
'rest_post_cannot_delete',
|
394 |
-
"User is unauthorized to delete the post. Access denied.",
|
395 |
-
array(
|
396 |
-
'action' => 'api.delete',
|
397 |
-
'status' => 401
|
398 |
-
)
|
399 |
-
);
|
400 |
-
}
|
401 |
-
|
402 |
-
return $result;
|
403 |
-
}
|
404 |
-
|
405 |
-
/**
|
406 |
-
* Alias for the bootstrap
|
407 |
-
*
|
408 |
-
* @return AAM_Api_Rest_Resource_Post
|
409 |
-
*
|
410 |
-
* @access public
|
411 |
-
* @static
|
412 |
-
*/
|
413 |
-
public static function getInstance() {
|
414 |
-
return self::bootstrap();
|
415 |
-
}
|
416 |
-
|
417 |
-
/**
|
418 |
-
* Bootstrap authorization layer
|
419 |
-
*
|
420 |
-
* @return AAM_Api_Rest_Resource_Post
|
421 |
-
*
|
422 |
-
* @access public
|
423 |
-
*/
|
424 |
-
public static function bootstrap() {
|
425 |
-
if (is_null(self::$_instance)) {
|
426 |
-
self::$_instance = new self;
|
427 |
-
}
|
428 |
-
|
429 |
-
return self::$_instance;
|
430 |
-
}
|
431 |
-
|
432 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
application/Api/Rest/Resource/Revision.php
DELETED
@@ -1,66 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* ======================================================================
|
5 |
-
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
-
* file 'license.txt', which is part of this source code package. *
|
7 |
-
* ======================================================================
|
8 |
-
*/
|
9 |
-
|
10 |
-
/**
|
11 |
-
* AAM REST Revision Resource
|
12 |
-
*
|
13 |
-
* @package AAM
|
14 |
-
* @author Vasyl Martyniuk <vasyl@vasyltech.com>
|
15 |
-
*/
|
16 |
-
class AAM_Api_Rest_Resource_Revision {
|
17 |
-
|
18 |
-
/**
|
19 |
-
* Instance of itself
|
20 |
-
*
|
21 |
-
* @var AAM_Api_Rest_Resource_Revision
|
22 |
-
*
|
23 |
-
* @access private
|
24 |
-
*/
|
25 |
-
private static $_instance = null;
|
26 |
-
|
27 |
-
/**
|
28 |
-
* Authorize User actions
|
29 |
-
*
|
30 |
-
* @param WP_REST_Request $request
|
31 |
-
*
|
32 |
-
* @return WP_Error|null
|
33 |
-
*
|
34 |
-
* @access public
|
35 |
-
*/
|
36 |
-
public function authorize($request) {
|
37 |
-
return null;
|
38 |
-
}
|
39 |
-
|
40 |
-
/**
|
41 |
-
* Alias for the bootstrap
|
42 |
-
*
|
43 |
-
* @return AAM_Api_Rest_Resource_Revision
|
44 |
-
*
|
45 |
-
* @access public
|
46 |
-
* @static
|
47 |
-
*/
|
48 |
-
public static function getInstance() {
|
49 |
-
return self::bootstrap();
|
50 |
-
}
|
51 |
-
|
52 |
-
/**
|
53 |
-
* Bootstrap authorization layer
|
54 |
-
*
|
55 |
-
* @return AAM_Api_Rest_Resource_Revision
|
56 |
-
*
|
57 |
-
* @access public
|
58 |
-
*/
|
59 |
-
public static function bootstrap() {
|
60 |
-
if (is_null(self::$_instance)) {
|
61 |
-
self::$_instance = new self;
|
62 |
-
}
|
63 |
-
|
64 |
-
return self::$_instance;
|
65 |
-
}
|
66 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
application/Api/Rest/Resource/User.php
CHANGED
@@ -5,95 +5,73 @@
|
|
5 |
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
* file 'license.txt', which is part of this source code package. *
|
7 |
* ======================================================================
|
|
|
|
|
8 |
*/
|
9 |
|
10 |
/**
|
11 |
-
* AAM RESTful Users Resource
|
12 |
-
*
|
13 |
* @package AAM
|
14 |
-
* @
|
15 |
*/
|
16 |
-
class AAM_Api_Rest_Resource_User
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
* @var AAM_Api_Rest_Resource_User
|
22 |
-
*
|
23 |
-
* @access private
|
24 |
-
*/
|
25 |
-
private static $_instance = null;
|
26 |
-
|
27 |
/**
|
28 |
-
*
|
|
|
|
|
|
|
|
|
|
|
29 |
*/
|
30 |
-
protected function __construct()
|
|
|
31 |
add_filter('rest_user_query', array($this, 'userQuery'));
|
32 |
}
|
33 |
-
|
34 |
/**
|
35 |
-
* Authorize
|
36 |
-
*
|
37 |
-
* @
|
38 |
-
*
|
39 |
-
* @return WP_Error|null
|
40 |
-
*
|
41 |
* @access public
|
|
|
42 |
*/
|
43 |
-
public function authorize(
|
|
|
44 |
return null;
|
45 |
}
|
46 |
-
|
47 |
/**
|
48 |
* Alter user select query
|
49 |
-
*
|
50 |
* @param array $args
|
51 |
-
*
|
52 |
* @return array
|
53 |
-
*
|
54 |
* @access public
|
|
|
55 |
*/
|
56 |
-
public function userQuery($args)
|
|
|
57 |
//current user max level
|
58 |
$max = AAM::getUser()->getMaxLevel();
|
59 |
$exclude = isset($args['role__not_in']) ? $args['role__not_in'] : array();
|
60 |
$roles = AAM_Core_API::getRoles();
|
61 |
-
|
62 |
-
foreach($roles->role_objects as $id => $role) {
|
63 |
if (AAM_Core_API::maxLevel($role->capabilities) > $max) {
|
64 |
$exclude[] = $id;
|
65 |
}
|
66 |
}
|
67 |
-
|
68 |
$args['role__not_in'] = $exclude;
|
69 |
-
|
70 |
return $args;
|
71 |
}
|
72 |
-
|
73 |
-
/**
|
74 |
-
* Alias for the bootstrap
|
75 |
-
*
|
76 |
-
* @return AAM_Api_Rest_Resource_User
|
77 |
-
*
|
78 |
-
* @access public
|
79 |
-
* @static
|
80 |
-
*/
|
81 |
-
public static function getInstance() {
|
82 |
-
return self::bootstrap();
|
83 |
-
}
|
84 |
-
|
85 |
-
/**
|
86 |
-
* Bootstrap authorization layer
|
87 |
-
*
|
88 |
-
* @return AAM_Api_Rest_Resource_User
|
89 |
-
*
|
90 |
-
* @access public
|
91 |
-
*/
|
92 |
-
public static function bootstrap() {
|
93 |
-
if (is_null(self::$_instance)) {
|
94 |
-
self::$_instance = new self;
|
95 |
-
}
|
96 |
-
|
97 |
-
return self::$_instance;
|
98 |
-
}
|
99 |
}
|
5 |
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
* file 'license.txt', which is part of this source code package. *
|
7 |
* ======================================================================
|
8 |
+
*
|
9 |
+
* @version 6.0.0
|
10 |
*/
|
11 |
|
12 |
/**
|
13 |
+
* AAM RESTful API Users Resource
|
14 |
+
*
|
15 |
* @package AAM
|
16 |
+
* @version 6.0.0
|
17 |
*/
|
18 |
+
class AAM_Api_Rest_Resource_User
|
19 |
+
{
|
20 |
+
|
21 |
+
use AAM_Core_Contract_SingletonTrait;
|
22 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
/**
|
24 |
+
* Constructor
|
25 |
+
*
|
26 |
+
* @return void
|
27 |
+
*
|
28 |
+
* @access protected
|
29 |
+
* @version 6.0.0
|
30 |
*/
|
31 |
+
protected function __construct()
|
32 |
+
{
|
33 |
add_filter('rest_user_query', array($this, 'userQuery'));
|
34 |
}
|
35 |
+
|
36 |
/**
|
37 |
+
* Authorize user actions
|
38 |
+
*
|
39 |
+
* @return null
|
40 |
+
*
|
|
|
|
|
41 |
* @access public
|
42 |
+
* @version 6.0.0
|
43 |
*/
|
44 |
+
public function authorize()
|
45 |
+
{
|
46 |
return null;
|
47 |
}
|
48 |
+
|
49 |
/**
|
50 |
* Alter user select query
|
51 |
+
*
|
52 |
* @param array $args
|
53 |
+
*
|
54 |
* @return array
|
55 |
+
*
|
56 |
* @access public
|
57 |
+
* @version 6.0.0
|
58 |
*/
|
59 |
+
public function userQuery($args)
|
60 |
+
{
|
61 |
//current user max level
|
62 |
$max = AAM::getUser()->getMaxLevel();
|
63 |
$exclude = isset($args['role__not_in']) ? $args['role__not_in'] : array();
|
64 |
$roles = AAM_Core_API::getRoles();
|
65 |
+
|
66 |
+
foreach ($roles->role_objects as $id => $role) {
|
67 |
if (AAM_Core_API::maxLevel($role->capabilities) > $max) {
|
68 |
$exclude[] = $id;
|
69 |
}
|
70 |
}
|
71 |
+
|
72 |
$args['role__not_in'] = $exclude;
|
73 |
+
|
74 |
return $args;
|
75 |
}
|
76 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
}
|
application/Backend/Authorization.php
DELETED
@@ -1,104 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* ======================================================================
|
5 |
-
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
-
* file 'license.txt', which is part of this source code package. *
|
7 |
-
* ======================================================================
|
8 |
-
*/
|
9 |
-
|
10 |
-
/**
|
11 |
-
* Backend authorization
|
12 |
-
*
|
13 |
-
* @package AAM
|
14 |
-
* @author Vasyl Martyniuk <vasyl@vasyltech.com>
|
15 |
-
*/
|
16 |
-
class AAM_Backend_Authorization {
|
17 |
-
|
18 |
-
/**
|
19 |
-
* Instance of itself
|
20 |
-
*
|
21 |
-
* @var AAM_Backend_Authorization
|
22 |
-
*
|
23 |
-
* @access private
|
24 |
-
*/
|
25 |
-
private static $_instance = null;
|
26 |
-
|
27 |
-
/**
|
28 |
-
* Constructor
|
29 |
-
*
|
30 |
-
* @return void
|
31 |
-
*
|
32 |
-
* @access protected
|
33 |
-
*/
|
34 |
-
protected function __construct() {
|
35 |
-
//control admin area
|
36 |
-
if (!defined( 'DOING_AJAX' ) || !DOING_AJAX) {
|
37 |
-
add_action('admin_init', array($this, 'checkScreenAccess'));
|
38 |
-
}
|
39 |
-
}
|
40 |
-
|
41 |
-
/**
|
42 |
-
* Check screen access
|
43 |
-
*
|
44 |
-
* @return void
|
45 |
-
*
|
46 |
-
* @access public
|
47 |
-
* @global string $plugin_page
|
48 |
-
*/
|
49 |
-
public function checkScreenAccess() {
|
50 |
-
global $plugin_page;
|
51 |
-
|
52 |
-
//compile menu
|
53 |
-
$menu = $plugin_page;
|
54 |
-
|
55 |
-
if (empty($menu)){
|
56 |
-
$menu = basename(AAM_Core_Request::server('SCRIPT_NAME'));
|
57 |
-
$taxonomy = AAM_Core_Request::get('taxonomy');
|
58 |
-
$postType = AAM_Core_Request::get('post_type');
|
59 |
-
$page = AAM_Core_Request::get('page');
|
60 |
-
|
61 |
-
if (!empty($taxonomy)) {
|
62 |
-
$menu .= '?taxonomy=' . $taxonomy;
|
63 |
-
} elseif (!empty($postType) && ($postType !== 'post')) {
|
64 |
-
$menu .= '?post_type=' . $postType;
|
65 |
-
} elseif (!empty($page)) {
|
66 |
-
$menu .= '?page=' . $page;
|
67 |
-
}
|
68 |
-
}
|
69 |
-
|
70 |
-
if (AAM::getUser()->getObject('menu')->has($menu, true)) {
|
71 |
-
AAM_Core_API::reject(
|
72 |
-
'backend', array('hook' => 'access_backend_menu', 'id' => $menu)
|
73 |
-
);
|
74 |
-
}
|
75 |
-
}
|
76 |
-
|
77 |
-
/**
|
78 |
-
* Alias for the bootstrap
|
79 |
-
*
|
80 |
-
* @return AAM_Backend_Authorization
|
81 |
-
*
|
82 |
-
* @access public
|
83 |
-
* @static
|
84 |
-
*/
|
85 |
-
public static function getInstance() {
|
86 |
-
return self::bootstrap();
|
87 |
-
}
|
88 |
-
|
89 |
-
/**
|
90 |
-
* Bootstrap authorization layer
|
91 |
-
*
|
92 |
-
* @return AAM_Backend_Authorization
|
93 |
-
*
|
94 |
-
* @access public
|
95 |
-
*/
|
96 |
-
public static function bootstrap() {
|
97 |
-
if (is_null(self::$_instance)) {
|
98 |
-
self::$_instance = new self;
|
99 |
-
}
|
100 |
-
|
101 |
-
return self::$_instance;
|
102 |
-
}
|
103 |
-
|
104 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
application/Backend/Feature.php
CHANGED
@@ -5,17 +5,21 @@
|
|
5 |
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
* file 'license.txt', which is part of this source code package. *
|
7 |
* ======================================================================
|
|
|
|
|
8 |
*/
|
9 |
|
10 |
/**
|
11 |
* AAM Backend Feature
|
12 |
-
*
|
13 |
* This class is used to hold the list of all registered UI features with few neat
|
14 |
* methods to manipulate it.
|
15 |
-
*
|
16 |
-
* @
|
|
|
17 |
*/
|
18 |
-
class AAM_Backend_Feature
|
|
|
19 |
|
20 |
/**
|
21 |
* Collection of features
|
@@ -23,30 +27,31 @@ class AAM_Backend_Feature {
|
|
23 |
* @var array
|
24 |
*
|
25 |
* @access private
|
26 |
-
* @
|
27 |
*/
|
28 |
static private $_features = array();
|
29 |
|
30 |
/**
|
31 |
* Register UI Feature
|
32 |
*
|
33 |
-
* @param
|
34 |
*
|
35 |
* @return boolean
|
36 |
*
|
37 |
* @access public
|
38 |
-
* @
|
39 |
*/
|
40 |
-
public static function registerFeature(
|
|
|
41 |
$response = false;
|
42 |
|
43 |
// Determine correct AAM UI capability
|
44 |
-
if (empty($feature->capability)){
|
45 |
$cap = 'aam_manager';
|
46 |
} else {
|
47 |
$cap = $feature->capability;
|
48 |
}
|
49 |
-
|
50 |
// Determine if minimum required options are enabled
|
51 |
if (isset($feature->option)) {
|
52 |
$show = self::isVisible($feature->option);
|
@@ -54,9 +59,12 @@ class AAM_Backend_Feature {
|
|
54 |
$show = true;
|
55 |
}
|
56 |
|
57 |
-
// Determine that current user has enough level to manage
|
58 |
-
|
59 |
-
|
|
|
|
|
|
|
60 |
if ($show && $allowed && current_user_can($cap)) {
|
61 |
self::$_features[] = $feature;
|
62 |
$response = true;
|
@@ -64,41 +72,44 @@ class AAM_Backend_Feature {
|
|
64 |
|
65 |
return $response;
|
66 |
}
|
67 |
-
|
68 |
/**
|
69 |
* Check if feature is visible
|
70 |
-
*
|
71 |
* There is a way to show/hide feature based on the option. For example some
|
72 |
* features should be visible only when Backend Access options is enabled.
|
73 |
-
*
|
74 |
* @param string $options
|
75 |
-
*
|
76 |
* @return boolean
|
77 |
-
*
|
78 |
* @access protected
|
|
|
79 |
*/
|
80 |
-
protected static function isVisible($options)
|
|
|
81 |
$count = 0;
|
82 |
-
|
83 |
-
foreach(explode(',', $options) as $option) {
|
84 |
$count += AAM_Core_Config::get($option, true);
|
85 |
}
|
86 |
-
|
87 |
return ($count > 0);
|
88 |
}
|
89 |
|
90 |
/**
|
91 |
-
* Initiate the
|
92 |
*
|
93 |
-
* @param
|
94 |
*
|
95 |
-
* @return
|
96 |
*
|
97 |
* @access public
|
98 |
-
* @
|
99 |
*/
|
100 |
-
public static function initView(
|
101 |
-
|
|
|
102 |
$feature->view = new $feature->view(AAM_Backend_Subject::getInstance());
|
103 |
}
|
104 |
|
@@ -109,51 +120,40 @@ class AAM_Backend_Feature {
|
|
109 |
* Retrieve list of features
|
110 |
*
|
111 |
* Retrieve sorted list of featured based on current subject
|
112 |
-
*
|
113 |
* @param string $type
|
114 |
*
|
115 |
* @return array
|
116 |
*
|
117 |
* @access public
|
118 |
-
* @
|
119 |
*/
|
120 |
-
public static function retrieveList($type)
|
|
|
121 |
$response = array();
|
122 |
-
|
123 |
-
$subject = AAM_Backend_Subject::getInstance()->
|
124 |
foreach (self::$_features as $feature) {
|
125 |
-
|
126 |
-
|
127 |
-
|
|
|
128 |
$response[] = self::initView($feature);
|
129 |
}
|
130 |
}
|
131 |
-
usort($response, 'AAM_Backend_Feature::reorder');
|
132 |
|
133 |
-
|
134 |
-
|
|
|
135 |
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
* @param array $features
|
142 |
-
*
|
143 |
-
* @return array
|
144 |
-
*
|
145 |
-
* @access public
|
146 |
-
* @static
|
147 |
-
*/
|
148 |
-
public static function reorder($feature_a, $feature_b){
|
149 |
-
$pos_a = (empty($feature_a->position) ? 9999 : $feature_a->position);
|
150 |
-
$pos_b = (empty($feature_b->position) ? 9999 : $feature_b->position);
|
151 |
|
152 |
-
|
153 |
-
|
154 |
-
} else {
|
155 |
-
$response = ($pos_a < $pos_b ? -1 : 1);
|
156 |
-
}
|
157 |
|
158 |
return $response;
|
159 |
}
|
5 |
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
* file 'license.txt', which is part of this source code package. *
|
7 |
* ======================================================================
|
8 |
+
*
|
9 |
+
* @version 6.0.0
|
10 |
*/
|
11 |
|
12 |
/**
|
13 |
* AAM Backend Feature
|
14 |
+
*
|
15 |
* This class is used to hold the list of all registered UI features with few neat
|
16 |
* methods to manipulate it.
|
17 |
+
*
|
18 |
+
* @package AAM
|
19 |
+
* @version 6.0.0
|
20 |
*/
|
21 |
+
class AAM_Backend_Feature
|
22 |
+
{
|
23 |
|
24 |
/**
|
25 |
* Collection of features
|
27 |
* @var array
|
28 |
*
|
29 |
* @access private
|
30 |
+
* @version 6.0.0
|
31 |
*/
|
32 |
static private $_features = array();
|
33 |
|
34 |
/**
|
35 |
* Register UI Feature
|
36 |
*
|
37 |
+
* @param object $feature
|
38 |
*
|
39 |
* @return boolean
|
40 |
*
|
41 |
* @access public
|
42 |
+
* @version 6.0.0
|
43 |
*/
|
44 |
+
public static function registerFeature($feature)
|
45 |
+
{
|
46 |
$response = false;
|
47 |
|
48 |
// Determine correct AAM UI capability
|
49 |
+
if (empty($feature->capability)) {
|
50 |
$cap = 'aam_manager';
|
51 |
} else {
|
52 |
$cap = $feature->capability;
|
53 |
}
|
54 |
+
|
55 |
// Determine if minimum required options are enabled
|
56 |
if (isset($feature->option)) {
|
57 |
$show = self::isVisible($feature->option);
|
59 |
$show = true;
|
60 |
}
|
61 |
|
62 |
+
// Determine that current user has enough user level to manage
|
63 |
+
// requested subject
|
64 |
+
$allowed = AAM_Core_API::isUserLevelAllowed(
|
65 |
+
AAM_Backend_Subject::getInstance()->getSubject()->getMaxLevel()
|
66 |
+
);
|
67 |
+
|
68 |
if ($show && $allowed && current_user_can($cap)) {
|
69 |
self::$_features[] = $feature;
|
70 |
$response = true;
|
72 |
|
73 |
return $response;
|
74 |
}
|
75 |
+
|
76 |
/**
|
77 |
* Check if feature is visible
|
78 |
+
*
|
79 |
* There is a way to show/hide feature based on the option. For example some
|
80 |
* features should be visible only when Backend Access options is enabled.
|
81 |
+
*
|
82 |
* @param string $options
|
83 |
+
*
|
84 |
* @return boolean
|
85 |
+
*
|
86 |
* @access protected
|
87 |
+
* @version 6.0.0
|
88 |
*/
|
89 |
+
protected static function isVisible($options)
|
90 |
+
{
|
91 |
$count = 0;
|
92 |
+
|
93 |
+
foreach (explode(',', $options) as $option) {
|
94 |
$count += AAM_Core_Config::get($option, true);
|
95 |
}
|
96 |
+
|
97 |
return ($count > 0);
|
98 |
}
|
99 |
|
100 |
/**
|
101 |
+
* Initiate the view controller
|
102 |
*
|
103 |
+
* @param object $feature
|
104 |
*
|
105 |
+
* @return AAM_Backend_Feature_Abstract
|
106 |
*
|
107 |
* @access public
|
108 |
+
* @version 6.0.0
|
109 |
*/
|
110 |
+
public static function initView($feature)
|
111 |
+
{
|
112 |
+
if (is_string($feature->view)) {
|
113 |
$feature->view = new $feature->view(AAM_Backend_Subject::getInstance());
|
114 |
}
|
115 |
|
120 |
* Retrieve list of features
|
121 |
*
|
122 |
* Retrieve sorted list of featured based on current subject
|
123 |
+
*
|
124 |
* @param string $type
|
125 |
*
|
126 |
* @return array
|
127 |
*
|
128 |
* @access public
|
129 |
+
* @version 6.0.0
|
130 |
*/
|
131 |
+
public static function retrieveList($type)
|
132 |
+
{
|
133 |
$response = array();
|
134 |
+
|
135 |
+
$subject = AAM_Backend_Subject::getInstance()->getSubjectType();
|
136 |
foreach (self::$_features as $feature) {
|
137 |
+
if (
|
138 |
+
$feature->type === $type
|
139 |
+
&& (empty($feature->subjects) || in_array($subject, $feature->subjects, true))
|
140 |
+
) {
|
141 |
$response[] = self::initView($feature);
|
142 |
}
|
143 |
}
|
|
|
144 |
|
145 |
+
usort($response, function($feature_a, $feature_b) {
|
146 |
+
$pos_a = (empty($feature_a->position) ? 9999 : $feature_a->position);
|
147 |
+
$pos_b = (empty($feature_b->position) ? 9999 : $feature_b->position);
|
148 |
|
149 |
+
if ($pos_a === $pos_b) {
|
150 |
+
$response = 0;
|
151 |
+
} else {
|
152 |
+
$response = ($pos_a < $pos_b ? -1 : 1);
|
153 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
154 |
|
155 |
+
return $response;
|
156 |
+
});
|
|
|
|
|
|
|
157 |
|
158 |
return $response;
|
159 |
}
|
application/Backend/Feature/Abstract.php
CHANGED
@@ -5,69 +5,133 @@
|
|
5 |
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
* file 'license.txt', which is part of this source code package. *
|
7 |
* ======================================================================
|
|
|
|
|
8 |
*/
|
9 |
|
10 |
/**
|
11 |
-
*
|
12 |
-
*
|
13 |
* @package AAM
|
14 |
-
* @
|
15 |
*/
|
16 |
-
abstract class AAM_Backend_Feature_Abstract
|
17 |
-
|
|
|
|
|
|
|
18 |
/**
|
19 |
-
*
|
20 |
-
*
|
21 |
-
* @
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
* @access public
|
24 |
-
* @
|
25 |
*/
|
26 |
-
public function
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
|
|
32 |
}
|
33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
/**
|
35 |
* Get HTML content
|
36 |
-
*
|
37 |
* @return string
|
38 |
-
*
|
39 |
* @access public
|
|
|
40 |
*/
|
41 |
-
public function getContent()
|
|
|
42 |
ob_start();
|
43 |
-
require_once(dirname(
|
44 |
$content = ob_get_contents();
|
45 |
ob_end_clean();
|
46 |
|
47 |
return $content;
|
48 |
}
|
49 |
-
|
50 |
/**
|
51 |
-
* Get
|
52 |
-
*
|
53 |
-
*
|
54 |
-
*
|
55 |
-
*
|
56 |
-
* @return string
|
57 |
-
*
|
58 |
* @access public
|
|
|
59 |
*/
|
60 |
-
public
|
61 |
-
|
|
|
62 |
}
|
63 |
-
|
64 |
/**
|
65 |
* Register feature
|
66 |
-
*
|
67 |
* @return void
|
68 |
-
*
|
69 |
* @access public
|
|
|
70 |
*/
|
71 |
-
public static function register() {
|
72 |
-
|
73 |
}
|
5 |
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
* file 'license.txt', which is part of this source code package. *
|
7 |
* ======================================================================
|
8 |
+
*
|
9 |
+
* @version 6.0.0
|
10 |
*/
|
11 |
|
12 |
/**
|
13 |
+
* Abstract class for each backend UI feature
|
14 |
+
*
|
15 |
* @package AAM
|
16 |
+
* @version 6.0.0
|
17 |
*/
|
18 |
+
abstract class AAM_Backend_Feature_Abstract
|
19 |
+
{
|
20 |
+
|
21 |
+
use AAM_Core_Contract_RequestTrait;
|
22 |
+
|
23 |
/**
|
24 |
+
* Default access capability to the service
|
25 |
+
*
|
26 |
+
* @version 6.0.0
|
27 |
+
*/
|
28 |
+
const ACCESS_CAPABILITY = 'aam_manager';
|
29 |
+
|
30 |
+
/**
|
31 |
+
* Type of AAM core object
|
32 |
+
*
|
33 |
+
* @version 6.0.0
|
34 |
+
*/
|
35 |
+
const OBJECT_TYPE = null;
|
36 |
+
|
37 |
+
/**
|
38 |
+
* HTML template to render
|
39 |
+
*
|
40 |
+
* @version 6.0.0
|
41 |
+
*/
|
42 |
+
const TEMPLATE = null;
|
43 |
+
|
44 |
+
/**
|
45 |
+
* Save access settings for the specific object
|
46 |
+
*
|
47 |
+
* @return string
|
48 |
+
*
|
49 |
* @access public
|
50 |
+
* @version 6.0.0
|
51 |
*/
|
52 |
+
public function save()
|
53 |
+
{
|
54 |
+
$param = AAM_Core_Request::post('param');
|
55 |
+
$value = AAM_Core_Request::post('value');
|
56 |
+
|
57 |
+
$object = $this->getSubject()->getObject(static::OBJECT_TYPE, null, true);
|
58 |
+
|
59 |
+
$object->updateOptionItem($param, $value)->save();
|
60 |
+
|
61 |
+
return wp_json_encode(array('status' => 'success'));
|
62 |
}
|
63 |
+
|
64 |
+
/**
|
65 |
+
* Rest access settings for the specific object
|
66 |
+
*
|
67 |
+
* @return string
|
68 |
+
*
|
69 |
+
* @access public
|
70 |
+
* @version 6.0.0
|
71 |
+
*/
|
72 |
+
public function reset()
|
73 |
+
{
|
74 |
+
$result = $this->getSubject()->getObject(static::OBJECT_TYPE)->reset();
|
75 |
+
|
76 |
+
return wp_json_encode(array('status' => ($result ? 'success' : 'failure')));
|
77 |
+
}
|
78 |
+
|
79 |
+
/**
|
80 |
+
* Check inheritance status
|
81 |
+
*
|
82 |
+
* Check if access settings are overwritten
|
83 |
+
*
|
84 |
+
* @return boolean
|
85 |
+
*
|
86 |
+
* @access protected
|
87 |
+
* @version 6.0.0
|
88 |
+
*/
|
89 |
+
protected function isOverwritten()
|
90 |
+
{
|
91 |
+
$object = $this->getSubject()->getObject(static::OBJECT_TYPE);
|
92 |
+
|
93 |
+
return $object->isOverwritten();
|
94 |
+
}
|
95 |
+
|
96 |
/**
|
97 |
* Get HTML content
|
98 |
+
*
|
99 |
* @return string
|
100 |
+
*
|
101 |
* @access public
|
102 |
+
* @version 6.0.0
|
103 |
*/
|
104 |
+
public function getContent()
|
105 |
+
{
|
106 |
ob_start();
|
107 |
+
require_once(dirname(__DIR__) . '/phtml/' . static::TEMPLATE);
|
108 |
$content = ob_get_contents();
|
109 |
ob_end_clean();
|
110 |
|
111 |
return $content;
|
112 |
}
|
113 |
+
|
114 |
/**
|
115 |
+
* Get currently managed subject
|
116 |
+
*
|
117 |
+
* @return AAM_Backend_Subject
|
118 |
+
*
|
|
|
|
|
|
|
119 |
* @access public
|
120 |
+
* @version 6.0.0
|
121 |
*/
|
122 |
+
public function getSubject()
|
123 |
+
{
|
124 |
+
return AAM_Backend_Subject::getInstance();
|
125 |
}
|
126 |
+
|
127 |
/**
|
128 |
* Register feature
|
129 |
+
*
|
130 |
* @return void
|
131 |
+
*
|
132 |
* @access public
|
133 |
+
* @version 6.0.0
|
134 |
*/
|
135 |
+
public static function register() {}
|
136 |
+
|
137 |
}
|
application/Backend/Feature/Extension/Manager.php
DELETED
@@ -1,217 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* ======================================================================
|
5 |
-
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
-
* file 'license.txt', which is part of this source code package. *
|
7 |
-
* ======================================================================
|
8 |
-
*/
|
9 |
-
|
10 |
-
/**
|
11 |
-
* Backend extension manager
|
12 |
-
*
|
13 |
-
* @package AAM
|
14 |
-
* @author Vasyl Martyniuk <vasyl@vasyltech.com>
|
15 |
-
*/
|
16 |
-
class AAM_Backend_Feature_Extension_Manager extends AAM_Backend_Feature_Abstract {
|
17 |
-
|
18 |
-
/**
|
19 |
-
*
|
20 |
-
* @var type
|
21 |
-
*/
|
22 |
-
protected static $instance = null;
|
23 |
-
|
24 |
-
/**
|
25 |
-
*
|
26 |
-
*/
|
27 |
-
public function __construct() {
|
28 |
-
parent::__construct();
|
29 |
-
|
30 |
-
if (AAM_Core_Config::get('core.settings.extensionSupport', true) === false) {
|
31 |
-
AAM::api()->denyAccess(array('reason' => 'core.settings.extensionSupport'));
|
32 |
-
} elseif (!current_user_can('aam_manage_extensions')) {
|
33 |
-
AAM::api()->denyAccess(array('reason' => 'aam_manage_extensions'));
|
34 |
-
}
|
35 |
-
}
|
36 |
-
|
37 |
-
/**
|
38 |
-
*
|
39 |
-
*/
|
40 |
-
public function render() {
|
41 |
-
require_once dirname(__FILE__) . '/../../phtml/extensions.phtml';
|
42 |
-
}
|
43 |
-
|
44 |
-
/**
|
45 |
-
* Undocumented function
|
46 |
-
*
|
47 |
-
* @return void
|
48 |
-
*/
|
49 |
-
public function check() {
|
50 |
-
AAM::cron();
|
51 |
-
|
52 |
-
return wp_json_encode(array('status' => 'success'));
|
53 |
-
}
|
54 |
-
|
55 |
-
/**
|
56 |
-
* Install an extension
|
57 |
-
*
|
58 |
-
* @param string $storedLicense
|
59 |
-
*
|
60 |
-
* @return string
|
61 |
-
*
|
62 |
-
* @access public
|
63 |
-
*/
|
64 |
-
public function install($storedLicense = null) {
|
65 |
-
$repo = AAM_Extension_Repository::getInstance();
|
66 |
-
$license = AAM_Core_Request::post('license', $storedLicense);
|
67 |
-
$package = (object) AAM_Core_Request::post('package');
|
68 |
-
|
69 |
-
$error = $repo->checkDirectory();
|
70 |
-
|
71 |
-
if ($error) {
|
72 |
-
$response = $this->installFailureResponse($error, $package);
|
73 |
-
$repo->storeLicense($package, $license);
|
74 |
-
} elseif (empty($package->content)) { //any unpredictable scenario
|
75 |
-
$response = array(
|
76 |
-
'status' => 'failure',
|
77 |
-
'error' => __('Download failure. Try again or contact us.', AAM_KEY)
|
78 |
-
);
|
79 |
-
} else { //otherwise install the extension
|
80 |
-
$result = $repo->add(base64_decode($package->content));
|
81 |
-
if (is_wp_error($result)) {
|
82 |
-
$response = $this->installFailureResponse(
|
83 |
-
$result->get_error_message(), $package
|
84 |
-
);
|
85 |
-
} else {
|
86 |
-
$response = array('status' => 'success');
|
87 |
-
}
|
88 |
-
$repo->storeLicense($package, $license);
|
89 |
-
}
|
90 |
-
|
91 |
-
return json_encode($response);
|
92 |
-
}
|
93 |
-
|
94 |
-
/**
|
95 |
-
* Update the extension
|
96 |
-
*
|
97 |
-
* @return string
|
98 |
-
*
|
99 |
-
* @access public
|
100 |
-
*/
|
101 |
-
public function update() {
|
102 |
-
$id = AAM_Core_Request::post('extension');
|
103 |
-
$licenses = AAM_Core_Compatibility::getLicenseList();
|
104 |
-
|
105 |
-
if (!empty($licenses[$id]['license'])) {
|
106 |
-
$response = $this->install($licenses[$id]['license']);
|
107 |
-
} else {
|
108 |
-
//fallback compatibility
|
109 |
-
$list = AAM_Extension_Repository::getInstance()->getList();
|
110 |
-
if (!empty($list[$id]['license'])) {
|
111 |
-
$response = $this->install($list[$id]['license']);
|
112 |
-
} else {
|
113 |
-
$response = wp_json_encode(array(
|
114 |
-
'status' => 'failure',
|
115 |
-
'error' => __('No valid license key was found.', AAM_KEY)
|
116 |
-
));
|
117 |
-
}
|
118 |
-
}
|
119 |
-
|
120 |
-
return $response;
|
121 |
-
}
|
122 |
-
|
123 |
-
/**
|
124 |
-
*
|
125 |
-
* @return type
|
126 |
-
*/
|
127 |
-
public function deactivate() {
|
128 |
-
AAM_Extension_Repository::getInstance()->updateStatus(
|
129 |
-
AAM_Core_Request::post('extension'),
|
130 |
-
AAM_Extension_Repository::STATUS_INACTIVE
|
131 |
-
);
|
132 |
-
|
133 |
-
return wp_json_encode(array('status' => 'success'));
|
134 |
-
}
|
135 |
-
|
136 |
-
/**
|
137 |
-
*
|
138 |
-
* @return type
|
139 |
-
*/
|
140 |
-
public function activate() {
|
141 |
-
AAM_Extension_Repository::getInstance()->updateStatus(
|
142 |
-
AAM_Core_Request::post('extension'),
|
143 |
-
AAM_Extension_Repository::STATUS_INSTALLED
|
144 |
-
);
|
145 |
-
|
146 |
-
return wp_json_encode(array('status' => 'success'));
|
147 |
-
}
|
148 |
-
|
149 |
-
/**
|
150 |
-
*
|
151 |
-
* @return type
|
152 |
-
*/
|
153 |
-
public function fixDirectoryIssue() {
|
154 |
-
$repo = AAM_Extension_Repository::getInstance();
|
155 |
-
$dirname = $repo->getBasedir();
|
156 |
-
|
157 |
-
if (file_exists($dirname) === false) {
|
158 |
-
@mkdir($dirname, fileperms(ABSPATH) & 0777 | 0755, true);
|
159 |
-
}
|
160 |
-
|
161 |
-
return wp_json_encode(array(
|
162 |
-
'status' => ($repo->isWriteableDirectory() ? 'success' : 'failed')
|
163 |
-
));
|
164 |
-
}
|
165 |
-
|
166 |
-
/**
|
167 |
-
*
|
168 |
-
* @param type $type
|
169 |
-
* @return type
|
170 |
-
*/
|
171 |
-
public function getList($type) {
|
172 |
-
$response = array();
|
173 |
-
|
174 |
-
foreach(AAM_Extension_Repository::getInstance()->getList() as $item) {
|
175 |
-
if ($item['type'] === $type) {
|
176 |
-
$response[] = $item;
|
177 |
-
}
|
178 |
-
}
|
179 |
-
|
180 |
-
return $response;
|
181 |
-
}
|
182 |
-
|
183 |
-
/**
|
184 |
-
* Install extension failure response
|
185 |
-
*
|
186 |
-
* In case the file system fails, AAM allows to download the extension for
|
187 |
-
* manual installation
|
188 |
-
*
|
189 |
-
* @param string $error
|
190 |
-
* @param stdClass $package
|
191 |
-
*
|
192 |
-
* @return array
|
193 |
-
*
|
194 |
-
* @access protected
|
195 |
-
*/
|
196 |
-
protected function installFailureResponse($error, $package) {
|
197 |
-
return array(
|
198 |
-
'status' => 'failure',
|
199 |
-
'error' => $error,
|
200 |
-
'title' => $package->title,
|
201 |
-
'content' => $package->content
|
202 |
-
);
|
203 |
-
}
|
204 |
-
|
205 |
-
/**
|
206 |
-
*
|
207 |
-
* @return AAM_Backend_Feature_Extension_Manager
|
208 |
-
*/
|
209 |
-
public static function getInstance() {
|
210 |
-
if (is_null(self::$instance)) {
|
211 |
-
self::$instance = new self;
|
212 |
-
}
|
213 |
-
|
214 |
-
return self::$instance;
|
215 |
-
}
|
216 |
-
|
217 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
application/Backend/Feature/ISubjectAware.php
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* ======================================================================
|
5 |
+
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
+
* file 'license.txt', which is part of this source code package. *
|
7 |
+
* ======================================================================
|
8 |
+
*
|
9 |
+
* @version 6.0.0
|
10 |
+
*/
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Backend feature that is customizable per subject
|
14 |
+
*
|
15 |
+
* @package AAM
|
16 |
+
* @version 6.0.0
|
17 |
+
*/
|
18 |
+
interface AAM_Backend_Feature_ISubjectAware
|
19 |
+
{ }
|
application/Backend/Feature/Main/404Redirect.php
CHANGED
@@ -5,75 +5,80 @@
|
|
5 |
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
* file 'license.txt', which is part of this source code package. *
|
7 |
* ======================================================================
|
|
|
|
|
8 |
*/
|
9 |
|
10 |
/**
|
11 |
* Backend 404 redirect manager
|
12 |
-
*
|
13 |
* @package AAM
|
14 |
-
* @
|
15 |
*/
|
16 |
-
class AAM_Backend_Feature_Main_404Redirect
|
17 |
-
|
|
|
|
|
|
|
|
|
18 |
/**
|
19 |
-
*
|
|
|
|
|
20 |
*/
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
$allowed = AAM_Backend_Subject::getInstance()->isAllowedToManage();
|
25 |
-
if (!$allowed || !current_user_can('aam_manage_404_redirect')) {
|
26 |
-
AAM::api()->denyAccess(array('reason' => 'aam_manage_404_redirect'));
|
27 |
-
}
|
28 |
-
}
|
29 |
-
|
30 |
/**
|
31 |
-
*
|
|
|
|
|
32 |
*/
|
33 |
-
|
34 |
-
|
35 |
-
}
|
36 |
-
|
37 |
/**
|
38 |
-
* Save
|
39 |
-
*
|
40 |
* @return string
|
41 |
*
|
42 |
* @access public
|
|
|
43 |
*/
|
44 |
-
public function save()
|
45 |
-
|
46 |
-
$
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
|
|
|
|
|
|
51 |
}
|
52 |
-
|
53 |
/**
|
54 |
* Register 404 redirect feature
|
55 |
-
*
|
56 |
* @return void
|
57 |
-
*
|
58 |
* @access public
|
|
|
59 |
*/
|
60 |
-
public static function register()
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
}
|
77 |
}
|
78 |
|
79 |
}
|
5 |
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
* file 'license.txt', which is part of this source code package. *
|
7 |
* ======================================================================
|
8 |
+
*
|
9 |
+
* @version 6.0.0
|
10 |
*/
|
11 |
|
12 |
/**
|
13 |
* Backend 404 redirect manager
|
14 |
+
*
|
15 |
* @package AAM
|
16 |
+
* @version 6.0.0
|
17 |
*/
|
18 |
+
class AAM_Backend_Feature_Main_404Redirect
|
19 |
+
extends AAM_Backend_Feature_Abstract implements AAM_Backend_Feature_ISubjectAware
|
20 |
+
{
|
21 |
+
|
22 |
+
use AAM_Core_Contract_RequestTrait;
|
23 |
+
|
24 |
/**
|
25 |
+
* Default access capability to the service
|
26 |
+
*
|
27 |
+
* @version 6.0.0
|
28 |
*/
|
29 |
+
const ACCESS_CAPABILITY = 'aam_manage_404_redirect';
|
30 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
/**
|
32 |
+
* HTML template to render
|
33 |
+
*
|
34 |
+
* @version 6.0.0
|
35 |
*/
|
36 |
+
const TEMPLATE = 'service/404redirect.phtml';
|
37 |
+
|
|
|
|
|
38 |
/**
|
39 |
+
* Save 404 redirect options
|
40 |
+
*
|
41 |
* @return string
|
42 |
*
|
43 |
* @access public
|
44 |
+
* @version 6.0.0
|
45 |
*/
|
46 |
+
public function save()
|
47 |
+
{
|
48 |
+
$param = AAM_Core_Request::post('param');
|
49 |
+
$value = $this->getFromPost('value');
|
50 |
+
|
51 |
+
$result = AAM_Core_Config::set($param, $value);
|
52 |
+
|
53 |
+
return wp_json_encode(
|
54 |
+
array('status' => $result ? 'success' : 'failure')
|
55 |
+
);
|
56 |
}
|
57 |
+
|
58 |
/**
|
59 |
* Register 404 redirect feature
|
60 |
+
*
|
61 |
* @return void
|
62 |
+
*
|
63 |
* @access public
|
64 |
+
* @version 6.0.0
|
65 |
*/
|
66 |
+
public static function register()
|
67 |
+
{
|
68 |
+
AAM_Backend_Feature::registerFeature((object)array(
|
69 |
+
'uid' => '404redirect',
|
70 |
+
'position' => 50,
|
71 |
+
'title' => __('404 Redirect', AAM_KEY),
|
72 |
+
'capability' => self::ACCESS_CAPABILITY,
|
73 |
+
'type' => 'main',
|
74 |
+
'subjects' => array(
|
75 |
+
AAM_Core_Subject_Default::UID,
|
76 |
+
AAM_Core_Subject_Role::UID,
|
77 |
+
AAM_Core_Subject_User::UID,
|
78 |
+
AAM_Core_Subject_Visitor::UID
|
79 |
+
),
|
80 |
+
'view' => __CLASS__
|
81 |
+
));
|
|
|
82 |
}
|
83 |
|
84 |
}
|
application/Backend/Feature/Main/Capability.php
CHANGED
@@ -5,22 +5,41 @@
|
|
5 |
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
* file 'license.txt', which is part of this source code package. *
|
7 |
* ======================================================================
|
|
|
|
|
8 |
*/
|
9 |
|
10 |
/**
|
11 |
* Backend capability manager
|
12 |
-
*
|
13 |
* @package AAM
|
14 |
-
* @
|
15 |
*/
|
16 |
-
class AAM_Backend_Feature_Main_Capability
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
/**
|
19 |
* Capability groups
|
20 |
-
*
|
21 |
* @var array
|
22 |
-
*
|
23 |
-
* @access
|
|
|
24 |
*/
|
25 |
public static $groups = array(
|
26 |
'system' => array(
|
@@ -44,89 +63,130 @@ class AAM_Backend_Feature_Main_Capability extends AAM_Backend_Feature_Abstract {
|
|
44 |
'manage_options', 'manage_links', 'manage_categories', 'customize',
|
45 |
'unfiltered_html', 'unfiltered_upload', 'update_themes',
|
46 |
'update_core', 'upload_files', 'delete_plugins', 'remove_users',
|
47 |
-
'switch_themes', 'list_users', 'promote_users', 'create_users',
|
48 |
-
|
49 |
-
'aam' => array(
|
50 |
-
'aam_manage_admin_menu', 'aam_manage_metaboxes', 'aam_manage_capabilities',
|
51 |
-
'aam_manage_posts', 'aam_manage_access_denied_redirect', 'aam_create_roles',
|
52 |
-
'aam_manage_login_redirect', 'aam_manage_logout_redirect', 'aam_manager',
|
53 |
-
'aam_manage_settings', 'aam_manage_extensions', 'aam_show_notifications',
|
54 |
-
'aam_manage_404_redirect', 'aam_manage_ip_check', 'aam_manage_admin_toolbar',
|
55 |
-
'aam_manage_default', 'aam_manage_visitors', 'aam_manage_roles', 'aam_manage_users',
|
56 |
-
'aam_edit_roles', 'aam_delete_roles', 'aam_toggle_users', 'aam_switch_users',
|
57 |
-
'aam_manage_configpress', 'aam_manage_api_routes', 'aam_manage_uri', 'aam_manage_policy',
|
58 |
-
'aam_view_help_btn', 'aam_edit_policy', 'aam_read_policy', 'aam_delete_policy',
|
59 |
-
'aam_delete_policies', 'aam_edit_policies', 'aam_edit_others_policies', 'aam_publish_policies',
|
60 |
-
'aam_manage_jwt'
|
61 |
)
|
62 |
);
|
63 |
-
|
64 |
/**
|
65 |
-
*
|
|
|
|
|
|
|
|
|
|
|
66 |
*/
|
67 |
-
public function
|
68 |
-
|
69 |
-
|
70 |
-
$
|
71 |
-
|
72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
}
|
|
|
|
|
|
|
|
|
74 |
}
|
75 |
-
|
76 |
/**
|
77 |
-
*
|
78 |
*
|
79 |
* @return string
|
80 |
-
*
|
81 |
* @access public
|
|
|
82 |
*/
|
83 |
-
public function
|
84 |
-
|
85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
|
87 |
-
|
88 |
-
|
89 |
|
90 |
-
return wp_json_encode(
|
91 |
-
'status' => ($result ? 'success' : 'failure')
|
92 |
-
));
|
93 |
}
|
94 |
-
|
95 |
/**
|
96 |
-
*
|
97 |
-
*
|
|
|
|
|
|
|
98 |
* @return string
|
99 |
-
*
|
100 |
* @access public
|
|
|
101 |
*/
|
102 |
-
public function
|
103 |
-
|
|
|
|
|
104 |
|
105 |
-
|
106 |
-
|
107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
}
|
109 |
|
110 |
/**
|
111 |
* Get list of capabilities for table view
|
112 |
-
*
|
113 |
* @return string
|
114 |
-
*
|
115 |
* @access public
|
|
|
116 |
*/
|
117 |
-
public function getTable()
|
118 |
-
|
119 |
-
$
|
120 |
-
$manager = AAM::api()->getPolicyManager();
|
121 |
|
122 |
// Compile the complete list of capabilities
|
123 |
$caps = AAM_Core_API::getAllCapabilities();
|
124 |
|
125 |
// Add also subject specific capabilities
|
126 |
-
$caps = array_merge($caps, $
|
127 |
|
128 |
foreach (array_keys($caps) as $cap) {
|
129 |
-
if (
|
130 |
$data[] = array(
|
131 |
$cap,
|
132 |
$this->getGroup($cap),
|
@@ -138,40 +198,33 @@ class AAM_Backend_Feature_Main_Capability extends AAM_Backend_Feature_Abstract {
|
|
138 |
|
139 |
return wp_json_encode(array('data' => $data));
|
140 |
}
|
141 |
-
|
142 |
-
/**
|
143 |
-
* @inheritdoc
|
144 |
-
*/
|
145 |
-
public static function getTemplate() {
|
146 |
-
return 'main/capability.phtml';
|
147 |
-
}
|
148 |
-
|
149 |
/**
|
150 |
* Prepare row actions
|
151 |
-
*
|
152 |
* Based on current user permissions and subject's capability ownership, prepare
|
153 |
* the correct list of actions
|
154 |
-
*
|
155 |
* @param string $cap
|
156 |
-
*
|
157 |
* @return string
|
158 |
-
*
|
159 |
* @access protected
|
|
|
160 |
*/
|
161 |
-
protected function prepareActionList($cap)
|
162 |
-
|
163 |
$actions = array();
|
164 |
-
|
|
|
165 |
$toggle = ($subject->hasCapability($cap) ? 'checked' : 'unchecked');
|
166 |
-
$manager = AAM::api()->getPolicyManager();
|
167 |
|
168 |
-
if (
|
169 |
$toggle = 'no-' . $toggle;
|
170 |
}
|
171 |
-
|
172 |
$actions[] = $toggle;
|
173 |
-
|
174 |
-
//allow to delete or update capability only for roles!
|
175 |
$edit = 'edit';
|
176 |
$delete = 'delete';
|
177 |
|
@@ -185,83 +238,85 @@ class AAM_Backend_Feature_Main_Capability extends AAM_Backend_Feature_Abstract {
|
|
185 |
|
186 |
$actions[] = $edit;
|
187 |
$actions[] = $delete;
|
188 |
-
|
189 |
return implode(',', $actions);
|
190 |
}
|
191 |
|
192 |
/**
|
193 |
* Check if current user can edit capability
|
194 |
-
*
|
195 |
* @param string $cap
|
196 |
-
*
|
197 |
* @return boolean
|
198 |
-
*
|
199 |
* @access protected
|
|
|
200 |
*/
|
201 |
-
protected function isAllowedToEdit($cap)
|
|
|
202 |
$allowed = false;
|
203 |
-
|
204 |
if (AAM_Core_Config::get('core.settings.editCapabilities', true)) {
|
205 |
$allowed = true;
|
206 |
}
|
207 |
|
208 |
// Access & Security policy has higher priority
|
209 |
-
$
|
210 |
-
if ($manager->isAllowed("Capability:{$cap}:AAM:update") === false) {
|
211 |
$allowed = false;
|
212 |
}
|
213 |
|
214 |
// Check if current subject contains the capability and if so, allow to
|
215 |
// edit it
|
216 |
-
$subject = AAM_Backend_Subject::getInstance();
|
217 |
if ($allowed) {
|
218 |
-
$allowed = array_key_exists($cap, $
|
219 |
-
}
|
220 |
-
|
221 |
return $allowed;
|
222 |
}
|
223 |
-
|
224 |
/**
|
225 |
* Check if current user can delete capability
|
226 |
-
*
|
227 |
* @param string $cap
|
228 |
-
*
|
229 |
* @return boolean
|
230 |
-
*
|
231 |
* @access protected
|
|
|
232 |
*/
|
233 |
-
protected function isAllowedToDelete($cap)
|
|
|
234 |
$allowed = false;
|
235 |
-
|
236 |
if (AAM_Core_Config::get('core.settings.editCapabilities', true)) {
|
237 |
$allowed = true;
|
238 |
}
|
239 |
|
240 |
// Access & Security policy has higher priority
|
241 |
-
$
|
242 |
-
if ($manager->isAllowed("Capability:{$cap}:AAM:delete") === false) {
|
243 |
$allowed = false;
|
244 |
}
|
245 |
|
246 |
// Check if current subject contains the capability and if so, allow to
|
247 |
// delete it
|
248 |
-
$subject = AAM_Backend_Subject::getInstance();
|
249 |
if ($allowed) {
|
250 |
-
$allowed = array_key_exists($cap, $
|
251 |
-
}
|
252 |
-
|
253 |
return $allowed;
|
254 |
}
|
255 |
|
256 |
/**
|
257 |
* Get capability group list
|
258 |
-
*
|
259 |
* @return array
|
260 |
-
*
|
261 |
* @access public
|
|
|
262 |
*/
|
263 |
-
public function getGroupList()
|
264 |
-
|
|
|
265 |
__('System', AAM_KEY),
|
266 |
__('Posts & Pages', AAM_KEY),
|
267 |
__('Backend', AAM_KEY),
|
@@ -270,147 +325,51 @@ class AAM_Backend_Feature_Main_Capability extends AAM_Backend_Feature_Abstract {
|
|
270 |
));
|
271 |
}
|
272 |
|
273 |
-
/**
|
274 |
-
* Add new capability
|
275 |
-
*
|
276 |
-
* @return string
|
277 |
-
*
|
278 |
-
* @access public
|
279 |
-
*/
|
280 |
-
public function add() {
|
281 |
-
$capability = sanitize_text_field(AAM_Core_Request::post('capability'));
|
282 |
-
$assign = filter_input(INPUT_POST, 'assign', FILTER_VALIDATE_INT);
|
283 |
-
|
284 |
-
if ($capability) {
|
285 |
-
// Add capability to current user if checkbox checked
|
286 |
-
if ($assign === 1) {
|
287 |
-
AAM::api()->getUser()->addCapability($capability);
|
288 |
-
}
|
289 |
-
|
290 |
-
$result = AAM_Backend_Subject::getInstance()->addCapability($capability);
|
291 |
-
|
292 |
-
$response = array('status' => ($result ? 'success' : 'failure'));
|
293 |
-
} else {
|
294 |
-
$response = array('status' => 'failure');
|
295 |
-
}
|
296 |
-
|
297 |
-
return wp_json_encode($response);
|
298 |
-
}
|
299 |
-
|
300 |
-
/**
|
301 |
-
* Update capability tag
|
302 |
-
*
|
303 |
-
* @return string
|
304 |
-
*
|
305 |
-
* @access public
|
306 |
-
*/
|
307 |
-
public function update() {
|
308 |
-
$capability = AAM_Core_Request::post('capability');
|
309 |
-
$updated = AAM_Core_Request::post('updated');
|
310 |
-
$subject = AAM_Backend_Subject::getInstance();
|
311 |
-
|
312 |
-
if ($this->isAllowedToEdit($capability) === false) {
|
313 |
-
$response = array(
|
314 |
-
'status' => 'failure',
|
315 |
-
'message' => __('Permission denied to update this capability', AAM_KEY)
|
316 |
-
);
|
317 |
-
} else {
|
318 |
-
// First we need to get the current grant status for updating capability
|
319 |
-
$status = $subject->hasCapability($capability);
|
320 |
-
// Remove updating capability
|
321 |
-
if ($subject->removeCapability($capability)) {
|
322 |
-
// Add new capability with the original grant status
|
323 |
-
$result = $subject->addCapability($updated, $status);
|
324 |
-
}
|
325 |
-
|
326 |
-
$response = array('status' => (!empty($result) ? 'success' : 'failure'));
|
327 |
-
}
|
328 |
-
|
329 |
-
return wp_json_encode($response);
|
330 |
-
}
|
331 |
-
|
332 |
-
/**
|
333 |
-
* Delete capability
|
334 |
-
*
|
335 |
-
* This function delete capability in all roles.
|
336 |
-
*
|
337 |
-
* @return string
|
338 |
-
*
|
339 |
-
* @access public
|
340 |
-
*/
|
341 |
-
public function delete() {
|
342 |
-
$capability = AAM_Core_Request::post('capability');
|
343 |
-
$subject = AAM_Backend_Subject::getInstance();
|
344 |
-
|
345 |
-
if ($this->isAllowedToDelete($capability) === false) {
|
346 |
-
$response = array(
|
347 |
-
'status' => 'failure',
|
348 |
-
'message' => __('Permission denied to delete this capability', AAM_KEY)
|
349 |
-
);
|
350 |
-
} else {
|
351 |
-
$result = $subject->removeCapability($capability);
|
352 |
-
$response = array('status' => ($result ? 'success' : 'failure'));
|
353 |
-
}
|
354 |
-
|
355 |
-
return wp_json_encode($response);
|
356 |
-
}
|
357 |
-
|
358 |
/**
|
359 |
* Get capability group name
|
360 |
-
*
|
361 |
* @param string $capability
|
362 |
-
*
|
363 |
* @return string
|
364 |
-
*
|
365 |
* @access protected
|
|
|
366 |
*/
|
367 |
-
protected function getGroup($capability)
|
|
|
368 |
if (in_array($capability, self::$groups['system'], true)) {
|
369 |
$response = __('System', AAM_KEY);
|
370 |
} elseif (in_array($capability, self::$groups['post'], true)) {
|
371 |
$response = __('Posts & Pages', AAM_KEY);
|
372 |
} elseif (in_array($capability, self::$groups['backend'], true)) {
|
373 |
$response = __('Backend', AAM_KEY);
|
374 |
-
} elseif (
|
375 |
$response = __('AAM Interface', AAM_KEY);
|
376 |
} else {
|
377 |
$response = __('Miscellaneous', AAM_KEY);
|
378 |
}
|
379 |
|
380 |
-
return apply_filters(
|
381 |
-
'aam-capability-group-filter', $response, $capability
|
382 |
-
);
|
383 |
}
|
384 |
-
|
385 |
-
/**
|
386 |
-
* Check overwritten status
|
387 |
-
*
|
388 |
-
* @return boolean
|
389 |
-
*
|
390 |
-
* @access protected
|
391 |
-
*/
|
392 |
-
protected function isOverwritten() {
|
393 |
-
$object = AAM_Backend_Subject::getInstance()->getObject('capability');
|
394 |
-
|
395 |
-
return $object->isOverwritten();
|
396 |
-
}
|
397 |
-
|
398 |
/**
|
399 |
-
* Register
|
400 |
-
*
|
401 |
* @return void
|
402 |
-
*
|
403 |
* @access public
|
|
|
404 |
*/
|
405 |
-
public static function register()
|
|
|
406 |
AAM_Backend_Feature::registerFeature((object) array(
|
407 |
'uid' => 'capability',
|
408 |
'position' => 15,
|
409 |
'title' => __('Capabilities', AAM_KEY),
|
410 |
-
'capability' =>
|
411 |
'type' => 'main',
|
412 |
'subjects' => array(
|
413 |
-
AAM_Core_Subject_Role::UID,
|
414 |
AAM_Core_Subject_User::UID
|
415 |
),
|
416 |
'view' => __CLASS__
|
5 |
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
* file 'license.txt', which is part of this source code package. *
|
7 |
* ======================================================================
|
8 |
+
*
|
9 |
+
* @version 6.0.0
|
10 |
*/
|
11 |
|
12 |
/**
|
13 |
* Backend capability manager
|
14 |
+
*
|
15 |
* @package AAM
|
16 |
+
* @version 6.0.0
|
17 |
*/
|
18 |
+
class AAM_Backend_Feature_Main_Capability
|
19 |
+
extends AAM_Backend_Feature_Abstract implements AAM_Backend_Feature_ISubjectAware
|
20 |
+
{
|
21 |
+
|
22 |
+
/**
|
23 |
+
* Default access capability to the service
|
24 |
+
*
|
25 |
+
* @version 6.0.0
|
26 |
+
*/
|
27 |
+
const ACCESS_CAPABILITY = 'aam_manage_capabilities';
|
28 |
+
|
29 |
+
/**
|
30 |
+
* HTML template to render
|
31 |
+
*
|
32 |
+
* @version 6.0.0
|
33 |
+
*/
|
34 |
+
const TEMPLATE = 'service/capability.phtml';
|
35 |
+
|
36 |
/**
|
37 |
* Capability groups
|
38 |
+
*
|
39 |
* @var array
|
40 |
+
*
|
41 |
+
* @access public
|
42 |
+
* @version 6.0.0
|
43 |
*/
|
44 |
public static $groups = array(
|
45 |
'system' => array(
|
63 |
'manage_options', 'manage_links', 'manage_categories', 'customize',
|
64 |
'unfiltered_html', 'unfiltered_upload', 'update_themes',
|
65 |
'update_core', 'upload_files', 'delete_plugins', 'remove_users',
|
66 |
+
'switch_themes', 'list_users', 'promote_users', 'create_users',
|
67 |
+
'delete_site'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
)
|
69 |
);
|
70 |
+
|
71 |
/**
|
72 |
+
* Save capability status
|
73 |
+
*
|
74 |
+
* @return string
|
75 |
+
*
|
76 |
+
* @access public
|
77 |
+
* @version 6.0.0
|
78 |
*/
|
79 |
+
public function save()
|
80 |
+
{
|
81 |
+
$result = false;
|
82 |
+
$cap = sanitize_text_field($this->getFromPost('capability'));
|
83 |
+
$effect = $this->getFromPost('effect', FILTER_VALIDATE_BOOLEAN);
|
84 |
+
$assign = $this->getFromPost('assignToMe', FILTER_VALIDATE_BOOLEAN);
|
85 |
+
|
86 |
+
if ($cap) {
|
87 |
+
// Add capability to current user if checkbox checked
|
88 |
+
if ($assign === true) {
|
89 |
+
AAM::getUser()->addCapability($cap);
|
90 |
+
}
|
91 |
+
|
92 |
+
$result = $this->getSubject()->addCapability($cap, $effect);
|
93 |
}
|
94 |
+
|
95 |
+
return wp_json_encode(array(
|
96 |
+
'status' => ($result ? 'success' : 'failure')
|
97 |
+
));
|
98 |
}
|
99 |
+
|
100 |
/**
|
101 |
+
* Update capability slug
|
102 |
*
|
103 |
* @return string
|
104 |
+
*
|
105 |
* @access public
|
106 |
+
* @version 6.0.0
|
107 |
*/
|
108 |
+
public function update()
|
109 |
+
{
|
110 |
+
$capability = $this->getFromPost('capability');
|
111 |
+
$updated = sanitize_text_field($this->getFromPost('updated'));
|
112 |
+
$subject = $this->getSubject();
|
113 |
+
|
114 |
+
if ($this->isAllowedToEdit($capability) === false) {
|
115 |
+
$response = array(
|
116 |
+
'status' => 'failure',
|
117 |
+
'message' => __('Permission denied to update this capability', AAM_KEY)
|
118 |
+
);
|
119 |
+
} else {
|
120 |
+
// First we need to get the current grant status for updating capability
|
121 |
+
$status = $subject->hasCapability($capability);
|
122 |
+
// Remove updating capability
|
123 |
+
if ($subject->removeCapability($capability)) {
|
124 |
+
// Add new capability with the original grant status
|
125 |
+
$result = $subject->addCapability($updated, $status);
|
126 |
+
}
|
127 |
|
128 |
+
$response = array('status' => (!empty($result) ? 'success' : 'failure'));
|
129 |
+
}
|
130 |
|
131 |
+
return wp_json_encode($response);
|
|
|
|
|
132 |
}
|
133 |
+
|
134 |
/**
|
135 |
+
* Delete capability
|
136 |
+
*
|
137 |
+
* This function delete capability in all roles or only for very specific subject.
|
138 |
+
* It all depends on the "subjectOnly" POST param.
|
139 |
+
*
|
140 |
* @return string
|
141 |
+
*
|
142 |
* @access public
|
143 |
+
* @version 6.0.0
|
144 |
*/
|
145 |
+
public function delete()
|
146 |
+
{
|
147 |
+
$capability = $this->getFromPost('capability');
|
148 |
+
$subjectOnly = $this->getFromPost('subjectOnly', FILTER_VALIDATE_BOOLEAN);
|
149 |
|
150 |
+
if ($this->isAllowedToDelete($capability) === false) {
|
151 |
+
$response = array(
|
152 |
+
'status' => 'failure',
|
153 |
+
'message' => __('Permission denied to delete this capability', AAM_KEY)
|
154 |
+
);
|
155 |
+
} else {
|
156 |
+
if ($subjectOnly === true) {
|
157 |
+
$this->getSubject()->removeCapability($capability);
|
158 |
+
} else {
|
159 |
+
$roles = AAM_Core_API::getRoles();
|
160 |
+
foreach (array_keys($roles->roles) as $roleId) {
|
161 |
+
$roles->remove_cap($roleId, $capability);
|
162 |
+
}
|
163 |
+
}
|
164 |
+
$response = array('status' => 'success');
|
165 |
+
}
|
166 |
+
|
167 |
+
return wp_json_encode($response);
|
168 |
}
|
169 |
|
170 |
/**
|
171 |
* Get list of capabilities for table view
|
172 |
+
*
|
173 |
* @return string
|
174 |
+
*
|
175 |
* @access public
|
176 |
+
* @version 6.0.0
|
177 |
*/
|
178 |
+
public function getTable()
|
179 |
+
{
|
180 |
+
$data = array();
|
|
|
181 |
|
182 |
// Compile the complete list of capabilities
|
183 |
$caps = AAM_Core_API::getAllCapabilities();
|
184 |
|
185 |
// Add also subject specific capabilities
|
186 |
+
$caps = array_merge($caps, $this->getSubject()->getCapabilities());
|
187 |
|
188 |
foreach (array_keys($caps) as $cap) {
|
189 |
+
if (apply_filters('aam_allowed_cap_filter', true, $cap, 'list') !== false) {
|
190 |
$data[] = array(
|
191 |
$cap,
|
192 |
$this->getGroup($cap),
|
198 |
|
199 |
return wp_json_encode(array('data' => $data));
|
200 |
}
|
201 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
202 |
/**
|
203 |
* Prepare row actions
|
204 |
+
*
|
205 |
* Based on current user permissions and subject's capability ownership, prepare
|
206 |
* the correct list of actions
|
207 |
+
*
|
208 |
* @param string $cap
|
209 |
+
*
|
210 |
* @return string
|
211 |
+
*
|
212 |
* @access protected
|
213 |
+
* @version 6.0.0
|
214 |
*/
|
215 |
+
protected function prepareActionList($cap)
|
216 |
+
{
|
217 |
$actions = array();
|
218 |
+
$subject = $this->getSubject();
|
219 |
+
|
220 |
$toggle = ($subject->hasCapability($cap) ? 'checked' : 'unchecked');
|
|
|
221 |
|
222 |
+
if (apply_filters('aam_allowed_cap_filter', true, $cap, 'toggle') === false) {
|
223 |
$toggle = 'no-' . $toggle;
|
224 |
}
|
225 |
+
|
226 |
$actions[] = $toggle;
|
227 |
+
|
|
|
228 |
$edit = 'edit';
|
229 |
$delete = 'delete';
|
230 |
|
238 |
|
239 |
$actions[] = $edit;
|
240 |
$actions[] = $delete;
|
241 |
+
|
242 |
return implode(',', $actions);
|
243 |
}
|
244 |
|
245 |
/**
|
246 |
* Check if current user can edit capability
|
247 |
+
*
|
248 |
* @param string $cap
|
249 |
+
*
|
250 |
* @return boolean
|
251 |
+
*
|
252 |
* @access protected
|
253 |
+
* @version 6.0.0
|
254 |
*/
|
255 |
+
protected function isAllowedToEdit($cap)
|
256 |
+
{
|
257 |
$allowed = false;
|
258 |
+
|
259 |
if (AAM_Core_Config::get('core.settings.editCapabilities', true)) {
|
260 |
$allowed = true;
|
261 |
}
|
262 |
|
263 |
// Access & Security policy has higher priority
|
264 |
+
if (apply_filters('aam_allowed_cap_filter', true, $cap, 'update') === false) {
|
|
|
265 |
$allowed = false;
|
266 |
}
|
267 |
|
268 |
// Check if current subject contains the capability and if so, allow to
|
269 |
// edit it
|
|
|
270 |
if ($allowed) {
|
271 |
+
$allowed = array_key_exists($cap, $this->getSubject()->getCapabilities());
|
272 |
+
}
|
273 |
+
|
274 |
return $allowed;
|
275 |
}
|
276 |
+
|
277 |
/**
|
278 |
* Check if current user can delete capability
|
279 |
+
*
|
280 |
* @param string $cap
|
281 |
+
*
|
282 |
* @return boolean
|
283 |
+
*
|
284 |
* @access protected
|
285 |
+
* @version 6.0.0
|
286 |
*/
|
287 |
+
protected function isAllowedToDelete($cap)
|
288 |
+
{
|
289 |
$allowed = false;
|
290 |
+
|
291 |
if (AAM_Core_Config::get('core.settings.editCapabilities', true)) {
|
292 |
$allowed = true;
|
293 |
}
|
294 |
|
295 |
// Access & Security policy has higher priority
|
296 |
+
if (apply_filters('aam_allowed_cap_filter', true, $cap, 'delete') === false) {
|
|
|
297 |
$allowed = false;
|
298 |
}
|
299 |
|
300 |
// Check if current subject contains the capability and if so, allow to
|
301 |
// delete it
|
|
|
302 |
if ($allowed) {
|
303 |
+
$allowed = array_key_exists($cap, $this->getSubject()->getCapabilities());
|
304 |
+
}
|
305 |
+
|
306 |
return $allowed;
|
307 |
}
|
308 |
|
309 |
/**
|
310 |
* Get capability group list
|
311 |
+
*
|
312 |
* @return array
|
313 |
+
*
|
314 |
* @access public
|
315 |
+
* @version 6.0.0
|
316 |
*/
|
317 |
+
public function getGroupList()
|
318 |
+
{
|
319 |
+
return apply_filters('aam_capability_groups_filter', array(
|
320 |
__('System', AAM_KEY),
|
321 |
__('Posts & Pages', AAM_KEY),
|
322 |
__('Backend', AAM_KEY),
|
325 |
));
|
326 |
}
|
327 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
328 |
/**
|
329 |
* Get capability group name
|
330 |
+
*
|
331 |
* @param string $capability
|
332 |
+
*
|
333 |
* @return string
|
334 |
+
*
|
335 |
* @access protected
|
336 |
+
* @version 6.0.0
|
337 |
*/
|
338 |
+
protected function getGroup($capability)
|
339 |
+
{
|
340 |
if (in_array($capability, self::$groups['system'], true)) {
|
341 |
$response = __('System', AAM_KEY);
|
342 |
} elseif (in_array($capability, self::$groups['post'], true)) {
|
343 |
$response = __('Posts & Pages', AAM_KEY);
|
344 |
} elseif (in_array($capability, self::$groups['backend'], true)) {
|
345 |
$response = __('Backend', AAM_KEY);
|
346 |
+
} elseif (strpos($capability, 'aam_') === 0) {
|
347 |
$response = __('AAM Interface', AAM_KEY);
|
348 |
} else {
|
349 |
$response = __('Miscellaneous', AAM_KEY);
|
350 |
}
|
351 |
|
352 |
+
return apply_filters('aam_capability_group_filter', $response, $capability);
|
|
|
|
|
353 |
}
|
354 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
355 |
/**
|
356 |
+
* Register Capability service UI
|
357 |
+
*
|
358 |
* @return void
|
359 |
+
*
|
360 |
* @access public
|
361 |
+
* @version 6.0.0
|
362 |
*/
|
363 |
+
public static function register()
|
364 |
+
{
|
365 |
AAM_Backend_Feature::registerFeature((object) array(
|
366 |
'uid' => 'capability',
|
367 |
'position' => 15,
|
368 |
'title' => __('Capabilities', AAM_KEY),
|
369 |
+
'capability' => self::ACCESS_CAPABILITY,
|
370 |
'type' => 'main',
|
371 |
'subjects' => array(
|
372 |
+
AAM_Core_Subject_Role::UID,
|
373 |
AAM_Core_Subject_User::UID
|
374 |
),
|
375 |
'view' => __CLASS__
|
application/Backend/Feature/Main/Jwt.php
CHANGED
@@ -5,132 +5,167 @@
|
|
5 |
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
* file 'license.txt', which is part of this source code package. *
|
7 |
* ======================================================================
|
|
|
|
|
8 |
*/
|
9 |
|
10 |
/**
|
11 |
-
* JWT manager
|
12 |
-
*
|
13 |
* @package AAM
|
14 |
-
* @
|
15 |
*/
|
16 |
-
class AAM_Backend_Feature_Main_Jwt
|
17 |
-
|
|
|
|
|
|
|
|
|
18 |
/**
|
19 |
-
*
|
|
|
|
|
20 |
*/
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
$allowed = AAM_Backend_Subject::getInstance()->isAllowedToManage();
|
25 |
-
if (!$allowed || !current_user_can('aam_manage_jwt')) {
|
26 |
-
AAM::api()->denyAccess(array('reason' => 'aam_manage_jwt'));
|
27 |
-
}
|
28 |
-
}
|
29 |
-
|
30 |
/**
|
31 |
-
*
|
32 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
*/
|
34 |
-
public function getTable()
|
|
|
35 |
return wp_json_encode($this->retrieveList());
|
36 |
}
|
37 |
|
38 |
/**
|
39 |
-
*
|
40 |
-
*
|
|
|
|
|
|
|
|
|
41 |
*/
|
42 |
-
public function generate()
|
43 |
-
|
44 |
-
$
|
45 |
-
$
|
|
|
|
|
|
|
|
|
|
|
46 |
|
47 |
-
|
48 |
$max = AAM::getUser()->getMaxLevel();
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
}
|
66 |
-
}
|
67 |
-
$result =
|
68 |
}
|
69 |
-
|
70 |
return wp_json_encode($result);
|
71 |
}
|
72 |
|
73 |
/**
|
74 |
-
*
|
75 |
-
*
|
|
|
|
|
|
|
|
|
76 |
*/
|
77 |
-
public function save()
|
78 |
-
|
|
|
79 |
$token = filter_input(INPUT_POST, 'token');
|
80 |
-
$
|
81 |
-
|
82 |
-
$result = AAM_Core_Jwt_Manager::getInstance()->registerToken(
|
83 |
-
$user->ID,
|
84 |
-
$token
|
85 |
-
);
|
86 |
|
87 |
if ($result) {
|
88 |
$response = array('status' => 'success');
|
89 |
} else {
|
90 |
$response = array(
|
91 |
-
'status' => 'failure',
|
92 |
'reason' => __('Failed to register JWT token', AAM_KEY)
|
93 |
);
|
94 |
}
|
95 |
|
96 |
return wp_json_encode($response);
|
97 |
}
|
98 |
-
|
99 |
/**
|
100 |
-
*
|
101 |
-
*
|
|
|
|
|
|
|
|
|
102 |
*/
|
103 |
-
public function delete()
|
104 |
-
|
105 |
-
$
|
106 |
-
$
|
|
|
107 |
|
108 |
if ($result) {
|
109 |
$response = array('status' => 'success');
|
110 |
} else {
|
111 |
$response = array(
|
112 |
-
'status' => 'failure',
|
113 |
'reason' => __('Failed to revoke JWT token', AAM_KEY)
|
114 |
);
|
115 |
}
|
116 |
|
117 |
-
|
118 |
}
|
119 |
|
120 |
/**
|
121 |
-
*
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
/**
|
128 |
-
*
|
129 |
-
* @return type
|
130 |
*/
|
131 |
-
protected function retrieveList()
|
132 |
-
|
133 |
-
|
|
|
134 |
);
|
135 |
|
136 |
$response = array(
|
@@ -140,46 +175,42 @@ class AAM_Backend_Feature_Main_Jwt extends AAM_Backend_Feature_Abstract {
|
|
140 |
'data' => array(),
|
141 |
);
|
142 |
|
143 |
-
$issuer =
|
|
|
|
|
|
|
144 |
|
145 |
-
foreach($tokens as $token) {
|
146 |
-
try {
|
147 |
-
$claims = $issuer->validateToken($token);
|
148 |
-
} catch(Exception $e) {
|
149 |
-
$claims = $issuer->extractTokenClaims($token);
|
150 |
-
$claims->status = 'invalid';
|
151 |
-
}
|
152 |
-
|
153 |
$response['data'][] = array(
|
154 |
$token,
|
155 |
add_query_arg('aam-jwt', $token, site_url()),
|
156 |
-
$claims->
|
157 |
$claims->exp,
|
158 |
'view,delete'
|
159 |
);
|
160 |
}
|
161 |
-
|
162 |
return $response;
|
163 |
}
|
164 |
|
165 |
/**
|
166 |
-
* Register
|
167 |
-
*
|
168 |
* @return void
|
169 |
-
*
|
170 |
* @access public
|
|
|
171 |
*/
|
172 |
-
public static function register()
|
|
|
173 |
AAM_Backend_Feature::registerFeature((object) array(
|
174 |
'uid' => 'jwt',
|
175 |
'position' => 65,
|
176 |
-
'title' => __('JWT Tokens', AAM_KEY)
|
177 |
-
'capability' =>
|
178 |
'type' => 'main',
|
179 |
'subjects' => array(
|
180 |
AAM_Core_Subject_User::UID
|
181 |
),
|
182 |
-
'option' => 'core.settings.jwtAuthentication',
|
183 |
'view' => __CLASS__
|
184 |
));
|
185 |
}
|
5 |
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
* file 'license.txt', which is part of this source code package. *
|
7 |
* ======================================================================
|
8 |
+
*
|
9 |
+
* @version 6.0.0
|
10 |
*/
|
11 |
|
12 |
/**
|
13 |
+
* JWT UI manager
|
14 |
+
*
|
15 |
* @package AAM
|
16 |
+
* @version 6.0.0
|
17 |
*/
|
18 |
+
class AAM_Backend_Feature_Main_Jwt
|
19 |
+
extends AAM_Backend_Feature_Abstract implements AAM_Backend_Feature_ISubjectAware
|
20 |
+
{
|
21 |
+
|
22 |
+
use AAM_Core_Contract_RequestTrait;
|
23 |
+
|
24 |
/**
|
25 |
+
* Default access capability to the service
|
26 |
+
*
|
27 |
+
* @version 6.0.0
|
28 |
*/
|
29 |
+
const ACCESS_CAPABILITY = 'aam_manage_jwt';
|
30 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
/**
|
32 |
+
* HTML template to render
|
33 |
+
*
|
34 |
+
* @version 6.0.0
|
35 |
+
*/
|
36 |
+
const TEMPLATE = 'service/jwt.phtml';
|
37 |
+
|
38 |
+
/**
|
39 |
+
* Get list of tokens
|
40 |
+
*
|
41 |
+
* @return string
|
42 |
+
*
|
43 |
+
* @access public
|
44 |
+
* @version 6.0.0
|
45 |
*/
|
46 |
+
public function getTable()
|
47 |
+
{
|
48 |
return wp_json_encode($this->retrieveList());
|
49 |
}
|
50 |
|
51 |
/**
|
52 |
+
* Generate JWT token
|
53 |
+
*
|
54 |
+
* @return string
|
55 |
+
*
|
56 |
+
* @access public
|
57 |
+
* @version 6.0.0
|
58 |
*/
|
59 |
+
public function generate()
|
60 |
+
{
|
61 |
+
$user = AAM_Backend_Subject::getInstance();
|
62 |
+
$result = array('status' => 'failure');
|
63 |
+
|
64 |
+
if (current_user_can('aam_manage_jwt')) {
|
65 |
+
$expires = $this->getFromPost('expires');
|
66 |
+
$refresh = $this->getFromPost('refreshable', FILTER_VALIDATE_BOOLEAN);
|
67 |
+
$trigger = $this->getFromPost('trigger', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
|
68 |
|
69 |
+
// Determine maximum user level
|
70 |
$max = AAM::getUser()->getMaxLevel();
|
71 |
+
|
72 |
+
// Prepare the list of claims
|
73 |
+
$claims = array(
|
74 |
+
'userId' => $user->ID,
|
75 |
+
'revocable' => true,
|
76 |
+
'refreshable' => ($refresh === true)
|
77 |
+
);
|
78 |
+
|
79 |
+
// If token also should contains the trigger action when it is expires,
|
80 |
+
// then add it to the list of claims
|
81 |
+
if (!empty($trigger)) {
|
82 |
+
$claims['trigger'] = $trigger;
|
83 |
+
}
|
84 |
+
|
85 |
+
try {
|
86 |
+
if ($max >= AAM_Core_API::maxLevel($user->allcaps)) {
|
87 |
+
$jwt = AAM_Core_Jwt_Issuer::getInstance()->issueToken(
|
88 |
+
$claims, $expires
|
89 |
+
);
|
90 |
+
AAM_Service_Jwt::getInstance()->registerToken($user->ID, $jwt->token);
|
91 |
+
$result = array('status' => 'success', 'jwt' => $jwt->token);
|
92 |
+
} else {
|
93 |
+
$result['reason'] = 'You are not allowed to generate JWT for this user';
|
94 |
+
}
|
95 |
+
} catch (Exception $ex) {
|
96 |
+
$result['reason'] = $ex->getMessage();
|
97 |
}
|
98 |
+
} else {
|
99 |
+
$result['reason'] = 'You are not allowed to manage JWT tokens';
|
100 |
}
|
101 |
+
|
102 |
return wp_json_encode($result);
|
103 |
}
|
104 |
|
105 |
/**
|
106 |
+
* Save/register new JWT token
|
107 |
+
*
|
108 |
+
* @return string
|
109 |
+
*
|
110 |
+
* @access public
|
111 |
+
* @version 6.0.0
|
112 |
*/
|
113 |
+
public function save()
|
114 |
+
{
|
115 |
+
$user = AAM_Backend_Subject::getInstance();
|
116 |
$token = filter_input(INPUT_POST, 'token');
|
117 |
+
$result = AAM_Service_Jwt::getInstance()->registerToken($user->ID, $token);
|
|
|
|
|
|
|
|
|
|
|
118 |
|
119 |
if ($result) {
|
120 |
$response = array('status' => 'success');
|
121 |
} else {
|
122 |
$response = array(
|
123 |
+
'status' => 'failure',
|
124 |
'reason' => __('Failed to register JWT token', AAM_KEY)
|
125 |
);
|
126 |
}
|
127 |
|
128 |
return wp_json_encode($response);
|
129 |
}
|
130 |
+
|
131 |
/**
|
132 |
+
* Delete existing JWT token
|
133 |
+
*
|
134 |
+
* @return string
|
135 |
+
*
|
136 |
+
* @access public
|
137 |
+
* @version 6.0.0
|
138 |
*/
|
139 |
+
public function delete()
|
140 |
+
{
|
141 |
+
$user = AAM_Backend_Subject::getInstance();
|
142 |
+
$token = filter_input(INPUT_POST, 'token');
|
143 |
+
$result = AAM_Service_Jwt::getInstance()->revokeToken($user->ID, $token);
|
144 |
|
145 |
if ($result) {
|
146 |
$response = array('status' => 'success');
|
147 |
} else {
|
148 |
$response = array(
|
149 |
+
'status' => 'failure',
|
150 |
'reason' => __('Failed to revoke JWT token', AAM_KEY)
|
151 |
);
|
152 |
}
|
153 |
|
154 |
+
return wp_json_encode($response);
|
155 |
}
|
156 |
|
157 |
/**
|
158 |
+
* Retrieve list of registered JWT tokens
|
159 |
+
*
|
160 |
+
* @return array
|
161 |
+
*
|
162 |
+
* @access protected
|
163 |
+
* @version 6.0.0
|
|
|
|
|
|
|
164 |
*/
|
165 |
+
protected function retrieveList()
|
166 |
+
{
|
167 |
+
$tokens = AAM_Service_Jwt::getInstance()->getTokenRegistry(
|
168 |
+
AAM_Backend_Subject::getInstance()->ID
|
169 |
);
|
170 |
|
171 |
$response = array(
|
175 |
'data' => array(),
|
176 |
);
|
177 |
|
178 |
+
$issuer = AAM_Core_Jwt_Issuer::getInstance();
|
179 |
+
|
180 |
+
foreach ($tokens as $token) {
|
181 |
+
$claims = $issuer->validateToken($token);
|
182 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
183 |
$response['data'][] = array(
|
184 |
$token,
|
185 |
add_query_arg('aam-jwt', $token, site_url()),
|
186 |
+
$claims->isValid,
|
187 |
$claims->exp,
|
188 |
'view,delete'
|
189 |
);
|
190 |
}
|
191 |
+
|
192 |
return $response;
|
193 |
}
|
194 |
|
195 |
/**
|
196 |
+
* Register JWT service UI
|
197 |
+
*
|
198 |
* @return void
|
199 |
+
*
|
200 |
* @access public
|
201 |
+
* @version 6.0.0
|
202 |
*/
|
203 |
+
public static function register()
|
204 |
+
{
|
205 |
AAM_Backend_Feature::registerFeature((object) array(
|
206 |
'uid' => 'jwt',
|
207 |
'position' => 65,
|
208 |
+
'title' => __('JWT Tokens', AAM_KEY),
|
209 |
+
'capability' => self::ACCESS_CAPABILITY,
|
210 |
'type' => 'main',
|
211 |
'subjects' => array(
|
212 |
AAM_Core_Subject_User::UID
|
213 |
),
|
|
|
214 |
'view' => __CLASS__
|
215 |
));
|
216 |
}
|
application/Backend/Feature/Main/LoginRedirect.php
CHANGED
@@ -5,113 +5,79 @@
|
|
5 |
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
* file 'license.txt', which is part of this source code package. *
|
7 |
* ======================================================================
|
|
|
|
|
8 |
*/
|
9 |
|
10 |
/**
|
11 |
* Login redirect
|
12 |
-
*
|
13 |
* @package AAM
|
14 |
-
* @
|
15 |
*/
|
16 |
-
class AAM_Backend_Feature_Main_LoginRedirect
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
*/
|
21 |
-
public function __construct() {
|
22 |
-
parent::__construct();
|
23 |
-
|
24 |
-
$allowed = AAM_Backend_Subject::getInstance()->isAllowedToManage();
|
25 |
-
if (!$allowed || !current_user_can('aam_manage_login_redirect')) {
|
26 |
-
AAM::api()->denyAccess(array('reason' => 'aam_manage_login_redirect'));
|
27 |
-
}
|
28 |
-
}
|
29 |
-
|
30 |
/**
|
31 |
-
*
|
32 |
*
|
33 |
-
* @
|
34 |
*/
|
35 |
-
|
36 |
-
$param = AAM_Core_Request::post('param');
|
37 |
-
$value = AAM_Core_Request::post('value');
|
38 |
-
|
39 |
-
$object = AAM_Backend_Subject::getInstance()->getObject('loginRedirect');
|
40 |
-
|
41 |
-
$object->save($param, $value);
|
42 |
|
43 |
-
return wp_json_encode(array('status' => 'success'));
|
44 |
-
}
|
45 |
-
|
46 |
-
/**
|
47 |
-
*
|
48 |
-
* @return type
|
49 |
-
*/
|
50 |
-
public function reset() {
|
51 |
-
return AAM_Backend_Subject::getInstance()->resetObject('loginRedirect');
|
52 |
-
}
|
53 |
-
|
54 |
-
/**
|
55 |
-
*
|
56 |
-
* @return type
|
57 |
-
*/
|
58 |
-
public function isDefault() {
|
59 |
-
$subject = AAM_Backend_Subject::getInstance()->getUID();
|
60 |
-
|
61 |
-
return ($subject === AAM_Core_Subject_Default::UID);
|
62 |
-
}
|
63 |
-
|
64 |
/**
|
65 |
-
*
|
66 |
-
*
|
67 |
-
*
|
68 |
-
*
|
69 |
-
* @return boolean
|
70 |
-
*
|
71 |
-
* @access protected
|
72 |
*/
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
return $object->isOverwritten();
|
77 |
-
}
|
78 |
-
|
79 |
/**
|
80 |
-
*
|
81 |
-
*
|
82 |
-
* @
|
83 |
*/
|
84 |
-
|
85 |
-
|
86 |
-
$value = $object->get($option);
|
87 |
-
|
88 |
-
return (!is_null($value) ? $value : $default);
|
89 |
-
}
|
90 |
-
|
91 |
/**
|
92 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
*/
|
94 |
-
public
|
95 |
-
|
|
|
|
|
|
|
|
|
96 |
}
|
97 |
-
|
98 |
/**
|
99 |
-
* Register
|
100 |
-
*
|
101 |
* @return void
|
102 |
-
*
|
103 |
* @access public
|
|
|
104 |
*/
|
105 |
-
public static function register()
|
|
|
106 |
AAM_Backend_Feature::registerFeature((object) array(
|
107 |
'uid' => 'login_redirect',
|
108 |
'position' => 40,
|
109 |
'title' => __('Login Redirect', AAM_KEY),
|
110 |
-
'capability' =>
|
111 |
'type' => 'main',
|
112 |
'subjects' => array(
|
113 |
-
AAM_Core_Subject_Role::UID,
|
114 |
-
AAM_Core_Subject_User::UID,
|
115 |
AAM_Core_Subject_Default::UID
|
116 |
),
|
117 |
'view' => __CLASS__
|
5 |
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
* file 'license.txt', which is part of this source code package. *
|
7 |
* ======================================================================
|
8 |
+
*
|
9 |
+
* @version 6.0.0
|
10 |
*/
|
11 |
|
12 |
/**
|
13 |
* Login redirect
|
14 |
+
*
|
15 |
* @package AAM
|
16 |
+
* @version 6.0.0
|
17 |
*/
|
18 |
+
class AAM_Backend_Feature_Main_LoginRedirect
|
19 |
+
extends AAM_Backend_Feature_Abstract implements AAM_Backend_Feature_ISubjectAware
|
20 |
+
{
|
21 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
/**
|
23 |
+
* Default access capability to the service
|
24 |
*
|
25 |
+
* @version 6.0.0
|
26 |
*/
|
27 |
+
const ACCESS_CAPABILITY = 'aam_manage_login_redirect';
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
/**
|
30 |
+
* Type of AAM core object
|
31 |
+
*
|
32 |
+
* @version 6.0.0
|
|
|
|
|
|
|
|
|
33 |
*/
|
34 |
+
const OBJECT_TYPE = AAM_Core_Object_LoginRedirect::OBJECT_TYPE;
|
35 |
+
|
|
|
|
|
|
|
|
|
36 |
/**
|
37 |
+
* HTML template to render
|
38 |
+
*
|
39 |
+
* @version 6.0.0
|
40 |
*/
|
41 |
+
const TEMPLATE = 'service/login-redirect.phtml';
|
42 |
+
|
|
|
|
|
|
|
|
|
|
|
43 |
/**
|
44 |
+
* Get option value
|
45 |
+
*
|
46 |
+
* @param string $name
|
47 |
+
* @param mixed $default
|
48 |
+
*
|
49 |
+
* @return mixed
|
50 |
+
*
|
51 |
+
* @access public
|
52 |
+
* @version 6.0.0
|
53 |
*/
|
54 |
+
public function getOption($name, $default = null)
|
55 |
+
{
|
56 |
+
$object = $this->getSubject()->getObject(self::OBJECT_TYPE);
|
57 |
+
$option = $object->getOption();
|
58 |
+
|
59 |
+
return (!empty($option[$name]) ? $option[$name] : $default);
|
60 |
}
|
61 |
+
|
62 |
/**
|
63 |
+
* Register login redirect feature
|
64 |
+
*
|
65 |
* @return void
|
66 |
+
*
|
67 |
* @access public
|
68 |
+
* @version 6.0.0
|
69 |
*/
|
70 |
+
public static function register()
|
71 |
+
{
|
72 |
AAM_Backend_Feature::registerFeature((object) array(
|
73 |
'uid' => 'login_redirect',
|
74 |
'position' => 40,
|
75 |
'title' => __('Login Redirect', AAM_KEY),
|
76 |
+
'capability' => self::ACCESS_CAPABILITY,
|
77 |
'type' => 'main',
|
78 |
'subjects' => array(
|
79 |
+
AAM_Core_Subject_Role::UID,
|
80 |
+
AAM_Core_Subject_User::UID,
|
81 |
AAM_Core_Subject_Default::UID
|
82 |
),
|
83 |
'view' => __CLASS__
|
application/Backend/Feature/Main/LogoutRedirect.php
CHANGED
@@ -5,113 +5,79 @@
|
|
5 |
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
* file 'license.txt', which is part of this source code package. *
|
7 |
* ======================================================================
|
|
|
|
|
8 |
*/
|
9 |
|
10 |
/**
|
11 |
-
* Logout redirect
|
12 |
-
*
|
13 |
* @package AAM
|
14 |
-
* @
|
15 |
*/
|
16 |
-
class AAM_Backend_Feature_Main_LogoutRedirect
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
*/
|
21 |
-
public function __construct() {
|
22 |
-
parent::__construct();
|
23 |
-
|
24 |
-
$allowed = AAM_Backend_Subject::getInstance()->isAllowedToManage();
|
25 |
-
if (!$allowed || !current_user_can('aam_manage_logout_redirect')) {
|
26 |
-
AAM::api()->denyAccess(array('reason' => 'aam_manage_logout_redirect'));
|
27 |
-
}
|
28 |
-
}
|
29 |
-
|
30 |
/**
|
31 |
-
*
|
32 |
*
|
33 |
-
* @
|
34 |
*/
|
35 |
-
|
36 |
-
$param = AAM_Core_Request::post('param');
|
37 |
-
$value = AAM_Core_Request::post('value');
|
38 |
-
|
39 |
-
$object = AAM_Backend_Subject::getInstance()->getObject('logoutRedirect');
|
40 |
-
|
41 |
-
$object->save($param, $value);
|
42 |
|
43 |
-
return wp_json_encode(array('status' => 'success'));
|
44 |
-
}
|
45 |
-
|
46 |
-
/**
|
47 |
-
*
|
48 |
-
* @return type
|
49 |
-
*/
|
50 |
-
public function reset() {
|
51 |
-
return AAM_Backend_Subject::getInstance()->resetObject('logoutRedirect');
|
52 |
-
}
|
53 |
-
|
54 |
-
/**
|
55 |
-
*
|
56 |
-
* @return type
|
57 |
-
*/
|
58 |
-
public function isDefault() {
|
59 |
-
$subject = AAM_Backend_Subject::getInstance();
|
60 |
-
|
61 |
-
return ($subject->getUID() === 'default');
|
62 |
-
}
|
63 |
-
|
64 |
/**
|
65 |
-
*
|
66 |
-
*
|
67 |
-
*
|
68 |
-
*
|
69 |
-
* @return boolean
|
70 |
-
*
|
71 |
-
* @access protected
|
72 |
*/
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
return $object->isOverwritten();
|
77 |
-
}
|
78 |
-
|
79 |
/**
|
80 |
-
*
|
81 |
-
*
|
82 |
-
* @
|
83 |
*/
|
84 |
-
|
85 |
-
|
86 |
-
$value = $object->get($option);
|
87 |
-
|
88 |
-
return (!is_null($value) ? $value : $default);
|
89 |
-
}
|
90 |
-
|
91 |
/**
|
92 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
*/
|
94 |
-
public
|
95 |
-
|
|
|
|
|
|
|
|
|
96 |
}
|
97 |
-
|
98 |
/**
|
99 |
-
* Register
|
100 |
-
*
|
101 |
* @return void
|
102 |
-
*
|
103 |
* @access public
|
|
|
104 |
*/
|
105 |
-
public static function register()
|
|
|
106 |
AAM_Backend_Feature::registerFeature((object) array(
|
107 |
'uid' => 'logout_redirect',
|
108 |
'position' => 41,
|
109 |
'title' => __('Logout Redirect', AAM_KEY),
|
110 |
-
'capability' =>
|
111 |
'type' => 'main',
|
112 |
'subjects' => array(
|
113 |
-
AAM_Core_Subject_Role::UID,
|
114 |
-
AAM_Core_Subject_User::UID,
|
115 |
AAM_Core_Subject_Default::UID
|
116 |
),
|
117 |
'view' => __CLASS__
|
5 |
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
* file 'license.txt', which is part of this source code package. *
|
7 |
* ======================================================================
|
8 |
+
*
|
9 |
+
* @version 6.0.0
|
10 |
*/
|
11 |
|
12 |
/**
|
13 |
+
* Logout redirect service
|
14 |
+
*
|
15 |
* @package AAM
|
16 |
+
* @version 6.0.0
|
17 |
*/
|
18 |
+
class AAM_Backend_Feature_Main_LogoutRedirect
|
19 |
+
extends AAM_Backend_Feature_Abstract implements AAM_Backend_Feature_ISubjectAware
|
20 |
+
{
|
21 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
/**
|
23 |
+
* Default access capability to the service
|
24 |
*
|
25 |
+
* @version 6.0.0
|
26 |
*/
|
27 |
+
const ACCESS_CAPABILITY = 'aam_manage_logout_redirect';
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
/**
|
30 |
+
* Type of AAM core object
|
31 |
+
*
|
32 |
+
* @version 6.0.0
|
|
|
|
|
|
|
|
|
33 |
*/
|
34 |
+
const OBJECT_TYPE = AAM_Core_Object_LogoutRedirect::OBJECT_TYPE;
|
35 |
+
|
|
|
|
|
|
|
|
|
36 |
/**
|
37 |
+
* HTML template to render
|
38 |
+
*
|
39 |
+
* @version 6.0.0
|
40 |
*/
|
41 |
+
const TEMPLATE = 'service/logout-redirect.phtml';
|
42 |
+
|
|
|
|
|
|
|
|
|
|
|
43 |
/**
|
44 |
+
* Get option value
|
45 |
+
*
|
46 |
+
* @param string $name
|
47 |
+
* @param mixed $default
|
48 |
+
*
|
49 |
+
* @return mixed
|
50 |
+
*
|
51 |
+
* @access public
|
52 |
+
* @version 6.0.0
|
53 |
*/
|
54 |
+
public function getOption($name, $default = null)
|
55 |
+
{
|
56 |
+
$object = $this->getSubject()->getObject(self::OBJECT_TYPE);
|
57 |
+
$option = $object->getOption();
|
58 |
+
|
59 |
+
return (!empty($option[$name]) ? $option[$name] : $default);
|
60 |
}
|
61 |
+
|
62 |
/**
|
63 |
+
* Register logout redirect feature
|
64 |
+
*
|
65 |
* @return void
|
66 |
+
*
|
67 |
* @access public
|
68 |
+
* @version 6.0.0
|
69 |
*/
|
70 |
+
public static function register()
|
71 |
+
{
|
72 |
AAM_Backend_Feature::registerFeature((object) array(
|
73 |
'uid' => 'logout_redirect',
|
74 |
'position' => 41,
|
75 |
'title' => __('Logout Redirect', AAM_KEY),
|
76 |
+
'capability' => self::ACCESS_CAPABILITY,
|
77 |
'type' => 'main',
|
78 |
'subjects' => array(
|
79 |
+
AAM_Core_Subject_Role::UID,
|
80 |
+
AAM_Core_Subject_User::UID,
|
81 |
AAM_Core_Subject_Default::UID
|
82 |
),
|
83 |
'view' => __CLASS__
|
application/Backend/Feature/Main/Menu.php
CHANGED
@@ -5,153 +5,156 @@
|
|
5 |
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
* file 'license.txt', which is part of this source code package. *
|
7 |
* ======================================================================
|
|
|
|
|
8 |
*/
|
9 |
|
10 |
/**
|
11 |
* Backend menu manager
|
12 |
-
*
|
13 |
* @package AAM
|
14 |
-
* @
|
15 |
*/
|
16 |
-
class AAM_Backend_Feature_Main_Menu
|
17 |
-
|
|
|
|
|
18 |
/**
|
19 |
-
*
|
|
|
|
|
20 |
*/
|
21 |
-
|
22 |
-
parent::__construct();
|
23 |
-
|
24 |
-
$allowed = AAM_Backend_Subject::getInstance()->isAllowedToManage();
|
25 |
-
if (!$allowed || !current_user_can('aam_manage_admin_menu')) {
|
26 |
-
AAM::api()->denyAccess(array('reason' => 'aam_manage_admin_menu'));
|
27 |
-
}
|
28 |
-
}
|
29 |
|
30 |
/**
|
31 |
-
*
|
32 |
*
|
33 |
-
* @
|
34 |
*/
|
35 |
-
|
36 |
-
$items = AAM_Core_Request::post('items', array());
|
37 |
-
$status = AAM_Core_Request::post('status');
|
38 |
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
$object->save();
|
46 |
|
47 |
-
return wp_json_encode(array('status' => 'success'));
|
48 |
-
}
|
49 |
-
|
50 |
/**
|
51 |
-
*
|
52 |
-
*
|
|
|
|
|
|
|
|
|
53 |
*/
|
54 |
-
public function
|
55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
}
|
57 |
|
58 |
/**
|
59 |
-
* Get
|
60 |
-
*
|
61 |
* Based on the list of capabilities that current subject has, prepare
|
62 |
* complete menu list and return it.
|
63 |
-
*
|
64 |
* @return array
|
65 |
-
*
|
66 |
* @access public
|
67 |
-
* @
|
68 |
*/
|
69 |
-
public function getMenu()
|
70 |
-
|
71 |
-
|
72 |
$response = array();
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
|
|
|
|
|
|
|
|
78 |
if (preg_match('/^separator/', $item[2])) {
|
79 |
continue; //skip separator
|
80 |
}
|
81 |
|
82 |
-
$
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
'crc32' => crc32('menu-' . $item[2]),
|
94 |
-
);
|
95 |
-
$menuItem['checked'] = $object->has($menuItem['id']) || $object->has($menuItem['crc32']);
|
96 |
-
$response[] = $menuItem;
|
97 |
-
}
|
98 |
}
|
99 |
}
|
100 |
|
101 |
return $response;
|
102 |
}
|
103 |
-
|
104 |
/**
|
105 |
-
*
|
106 |
-
*
|
107 |
-
* @
|
|
|
|
|
|
|
|
|
|
|
108 |
*/
|
109 |
-
protected function normalizeItem($menu)
|
|
|
110 |
if (strpos($menu, 'customize.php') === 0) {
|
111 |
$menu = 'customize.php';
|
112 |
}
|
113 |
-
|
114 |
return $menu;
|
115 |
}
|
116 |
-
|
117 |
-
/**
|
118 |
-
* @inheritdoc
|
119 |
-
*/
|
120 |
-
public static function getTemplate() {
|
121 |
-
return 'main/menu.phtml';
|
122 |
-
}
|
123 |
|
124 |
/**
|
125 |
* Prepare filtered submenu
|
126 |
-
*
|
127 |
* @param string $menu
|
128 |
-
*
|
129 |
* @return array
|
130 |
-
*
|
131 |
* @access protected
|
132 |
-
* @
|
133 |
*/
|
134 |
-
protected function getSubmenu($menu)
|
135 |
-
|
136 |
-
$
|
137 |
-
|
138 |
-
$
|
139 |
-
|
140 |
-
$isDefault = ($subject->getUID() === AAM_Core_Subject_Default::UID);
|
141 |
-
|
142 |
if (array_key_exists($menu, $submenu) && is_array($submenu[$menu])) {
|
143 |
foreach ($submenu[$menu] as $item) {
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
)
|
152 |
-
|
153 |
-
$response[] = $menuItem;
|
154 |
-
}
|
155 |
}
|
156 |
}
|
157 |
|
@@ -159,94 +162,93 @@ class AAM_Backend_Feature_Main_Menu extends AAM_Backend_Feature_Abstract {
|
|
159 |
}
|
160 |
|
161 |
/**
|
162 |
-
*
|
163 |
*
|
164 |
-
* @param
|
165 |
-
*
|
|
|
|
|
|
|
|
|
166 |
*/
|
167 |
-
protected function
|
168 |
-
|
169 |
-
$
|
|
|
170 |
|
171 |
-
return
|
172 |
}
|
173 |
-
|
174 |
/**
|
175 |
* Filter menu name
|
176 |
-
*
|
177 |
* Strip any HTML tags from the menu name and also remove the trailing
|
178 |
* numbers in case of Plugin or Comments menu name.
|
179 |
-
*
|
180 |
* @param string $name
|
181 |
-
*
|
182 |
* @return string
|
183 |
-
*
|
184 |
* @access protected
|
|
|
185 |
*/
|
186 |
-
protected function filterMenuName($name)
|
|
|
187 |
$filtered = trim(wp_strip_all_tags(
|
188 |
-
preg_replace('@<(span)[^>]*?>.*?</\\1>@si', '', $name),
|
189 |
true
|
190 |
));
|
191 |
-
|
192 |
return preg_replace('/([\d]+)$/', '', $filtered);
|
193 |
}
|
194 |
|
195 |
/**
|
196 |
-
*
|
197 |
-
*
|
|
|
|
|
198 |
* @return boolean
|
|
|
|
|
|
|
199 |
*/
|
200 |
-
protected function hasSubmenuChecked($subs)
|
|
|
201 |
$has = false;
|
202 |
-
|
203 |
if (!empty($subs)) {
|
204 |
-
foreach($subs as $submenu) {
|
205 |
if ($submenu['checked']) {
|
206 |
$has = true;
|
207 |
break;
|
208 |
}
|
209 |
}
|
210 |
}
|
211 |
-
|
212 |
return $has;
|
213 |
}
|
214 |
-
|
215 |
-
/**
|
216 |
-
* Check inheritance status
|
217 |
-
*
|
218 |
-
* Check if menu settings are overwritten
|
219 |
-
*
|
220 |
-
* @return boolean
|
221 |
-
*
|
222 |
-
* @access protected
|
223 |
-
*/
|
224 |
-
protected function isOverwritten() {
|
225 |
-
$object = AAM_Backend_Subject::getInstance()->getObject('menu');
|
226 |
-
|
227 |
-
return $object->isOverwritten();
|
228 |
-
}
|
229 |
|
230 |
/**
|
231 |
-
* Register Menu feature
|
232 |
-
*
|
233 |
* @return void
|
234 |
-
*
|
235 |
* @access public
|
|
|
236 |
*/
|
237 |
-
public static function register()
|
|
|
238 |
AAM_Backend_Feature::registerFeature((object) array(
|
239 |
'uid' => 'admin_menu',
|
240 |
'position' => 5,
|
241 |
'title' => __('Backend Menu', AAM_KEY),
|
242 |
-
'capability' =>
|
243 |
'type' => 'main',
|
244 |
'subjects' => array(
|
245 |
-
AAM_Core_Subject_Role::UID,
|
246 |
AAM_Core_Subject_User::UID,
|
247 |
AAM_Core_Subject_Default::UID
|
248 |
),
|
249 |
-
'option' => 'core.settings.backendAccessControl',
|
250 |
'view' => __CLASS__
|
251 |
));
|
252 |
}
|
5 |
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
* file 'license.txt', which is part of this source code package. *
|
7 |
* ======================================================================
|
8 |
+
*
|
9 |
+
* @version 6.0.0
|
10 |
*/
|
11 |
|
12 |
/**
|
13 |
* Backend menu manager
|
14 |
+
*
|
15 |
* @package AAM
|
16 |
+
* @version 6.0.0
|
17 |
*/
|
18 |
+
class AAM_Backend_Feature_Main_Menu
|
19 |
+
extends AAM_Backend_Feature_Abstract implements AAM_Backend_Feature_ISubjectAware
|
20 |
+
{
|
21 |
+
|
22 |
/**
|
23 |
+
* Default access capability to the service
|
24 |
+
*
|
25 |
+
* @version 6.0.0
|
26 |
*/
|
27 |
+
const ACCESS_CAPABILITY = 'aam_manage_admin_menu';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
/**
|
30 |
+
* Type of AAM core object
|
31 |
*
|
32 |
+
* @version 6.0.0
|
33 |
*/
|
34 |
+
const OBJECT_TYPE = AAM_Core_Object_Menu::OBJECT_TYPE;
|
|
|
|
|
35 |
|
36 |
+
/**
|
37 |
+
* HTML template to render
|
38 |
+
*
|
39 |
+
* @version 6.0.0
|
40 |
+
*/
|
41 |
+
const TEMPLATE = 'service/menu.phtml';
|
|
|
42 |
|
|
|
|
|
|
|
43 |
/**
|
44 |
+
* Save menu settings
|
45 |
+
*
|
46 |
+
* @return string
|
47 |
+
*
|
48 |
+
* @access public
|
49 |
+
* @version 6.0.0
|
50 |
*/
|
51 |
+
public function save()
|
52 |
+
{
|
53 |
+
$status = AAM_Core_Request::post('status');
|
54 |
+
|
55 |
+
$object = AAM_Backend_Subject::getInstance()->getObject(
|
56 |
+
self::OBJECT_TYPE, null, true
|
57 |
+
);
|
58 |
+
|
59 |
+
foreach (AAM_Core_Request::post('items', array()) as $item) {
|
60 |
+
$object->updateOptionItem($item, !empty($status));
|
61 |
+
}
|
62 |
+
|
63 |
+
$result = $object->save();
|
64 |
+
|
65 |
+
return wp_json_encode(array('status' => ($result ? 'success' : 'failure')));
|
66 |
}
|
67 |
|
68 |
/**
|
69 |
+
* Get admin menu
|
70 |
+
*
|
71 |
* Based on the list of capabilities that current subject has, prepare
|
72 |
* complete menu list and return it.
|
73 |
+
*
|
74 |
* @return array
|
75 |
+
*
|
76 |
* @access public
|
77 |
+
* @version 6.0.0
|
78 |
*/
|
79 |
+
public function getMenu()
|
80 |
+
{
|
|
|
81 |
$response = array();
|
82 |
+
|
83 |
+
$cache = AAM_Service_AdminMenu::getInstance()->getMenuCache();
|
84 |
+
$subject = AAM_Backend_Subject::getInstance();
|
85 |
+
|
86 |
+
// Create menu list with submenus
|
87 |
+
if (!empty($cache)) {
|
88 |
+
$object = $subject->getObject(self::OBJECT_TYPE);
|
89 |
+
|
90 |
+
foreach ($cache['menu'] as $item) {
|
91 |
if (preg_match('/^separator/', $item[2])) {
|
92 |
continue; //skip separator
|
93 |
}
|
94 |
|
95 |
+
$response[] = array(
|
96 |
+
// Add menu- prefix to define that this is the top level menu.
|
97 |
+
// WordPress by default gives the same menu id to the first
|
98 |
+
// submenu
|
99 |
+
'id' => 'menu-' . $item[2],
|
100 |
+
'uri' => $this->prepareAdminURI($item[2]),
|
101 |
+
'name' => $this->filterMenuName($item[0]),
|
102 |
+
'submenu' => $this->getSubmenu($item[2], $cache['submenu']),
|
103 |
+
'capability' => $item[1],
|
104 |
+
'checked' => $object->isRestricted('menu-' . $item[2])
|
105 |
+
);
|
|
|
|
|
|
|
|
|
|
|
106 |
}
|
107 |
}
|
108 |
|
109 |
return $response;
|
110 |
}
|
111 |
+
|
112 |
/**
|
113 |
+
* Normalize menu item
|
114 |
+
*
|
115 |
+
* @param string $menu
|
116 |
+
*
|
117 |
+
* @return string
|
118 |
+
*
|
119 |
+
* @access protected
|
120 |
+
* @version 6.0.0
|
121 |
*/
|
122 |
+
protected function normalizeItem($menu)
|
123 |
+
{
|
124 |
if (strpos($menu, 'customize.php') === 0) {
|
125 |
$menu = 'customize.php';
|
126 |
}
|
127 |
+
|
128 |
return $menu;
|
129 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
|
131 |
/**
|
132 |
* Prepare filtered submenu
|
133 |
+
*
|
134 |
* @param string $menu
|
135 |
+
*
|
136 |
* @return array
|
137 |
+
*
|
138 |
* @access protected
|
139 |
+
* @version 6.0.0
|
140 |
*/
|
141 |
+
protected function getSubmenu($menu, $submenu)
|
142 |
+
{
|
143 |
+
$response = array();
|
144 |
+
|
145 |
+
$object = AAM_Backend_Subject::getInstance()->getObject(self::OBJECT_TYPE);
|
146 |
+
|
|
|
|
|
147 |
if (array_key_exists($menu, $submenu) && is_array($submenu[$menu])) {
|
148 |
foreach ($submenu[$menu] as $item) {
|
149 |
+
$id = $this->normalizeItem($item[2]);
|
150 |
+
|
151 |
+
$response[] = array(
|
152 |
+
'id' => $id,
|
153 |
+
'uri' => $this->prepareAdminURI($item[2]),
|
154 |
+
'name' => $this->filterMenuName($item[0]),
|
155 |
+
'capability' => $item[1],
|
156 |
+
'checked' => $object->isRestricted($id)
|
157 |
+
);
|
|
|
|
|
158 |
}
|
159 |
}
|
160 |
|
162 |
}
|
163 |
|
164 |
/**
|
165 |
+
* Prepare admin URI for the menu item
|
166 |
*
|
167 |
+
* @param string $resource
|
168 |
+
*
|
169 |
+
* @return string
|
170 |
+
*
|
171 |
+
* @access protected
|
172 |
+
* @version 6.0.0
|
173 |
*/
|
174 |
+
protected function prepareAdminURI($resource)
|
175 |
+
{
|
176 |
+
$hook = get_plugin_page_hook($resource, 'admin.php');
|
177 |
+
$uri = (!empty($hook) ? 'admin.php?page=' . $resource : $resource);
|
178 |
|
179 |
+
return '/wp-admin/' . $uri;
|
180 |
}
|
181 |
+
|
182 |
/**
|
183 |
* Filter menu name
|
184 |
+
*
|
185 |
* Strip any HTML tags from the menu name and also remove the trailing
|
186 |
* numbers in case of Plugin or Comments menu name.
|
187 |
+
*
|
188 |
* @param string $name
|
189 |
+
*
|
190 |
* @return string
|
191 |
+
*
|
192 |
* @access protected
|
193 |
+
* @version 6.0.0
|
194 |
*/
|
195 |
+
protected function filterMenuName($name)
|
196 |
+
{
|
197 |
$filtered = trim(wp_strip_all_tags(
|
198 |
+
preg_replace('@<(span)[^>]*?>.*?</\\1>@si', '', $name),
|
199 |
true
|
200 |
));
|
201 |
+
|
202 |
return preg_replace('/([\d]+)$/', '', $filtered);
|
203 |
}
|
204 |
|
205 |
/**
|
206 |
+
* Check if there is at least one submenu restricted
|
207 |
+
*
|
208 |
+
* @param array $subs
|
209 |
+
*
|
210 |
* @return boolean
|
211 |
+
*
|
212 |
+
* @access protected
|
213 |
+
* @version 6.0.0
|
214 |
*/
|
215 |
+
protected function hasSubmenuChecked($subs)
|
216 |
+
{
|
217 |
$has = false;
|
218 |
+
|
219 |
if (!empty($subs)) {
|
220 |
+
foreach ($subs as $submenu) {
|
221 |
if ($submenu['checked']) {
|
222 |
$has = true;
|
223 |
break;
|
224 |
}
|
225 |
}
|
226 |
}
|
227 |
+
|
228 |
return $has;
|
229 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
230 |
|
231 |
/**
|
232 |
+
* Register Admin Menu feature
|
233 |
+
*
|
234 |
* @return void
|
235 |
+
*
|
236 |
* @access public
|
237 |
+
* @version 6.0.0
|
238 |
*/
|
239 |
+
public static function register()
|
240 |
+
{
|
241 |
AAM_Backend_Feature::registerFeature((object) array(
|
242 |
'uid' => 'admin_menu',
|
243 |
'position' => 5,
|
244 |
'title' => __('Backend Menu', AAM_KEY),
|
245 |
+
'capability' => self::ACCESS_CAPABILITY,
|
246 |
'type' => 'main',
|
247 |
'subjects' => array(
|
248 |
+
AAM_Core_Subject_Role::UID,
|
249 |
AAM_Core_Subject_User::UID,
|
250 |
AAM_Core_Subject_Default::UID
|
251 |
),
|
|
|
252 |
'view' => __CLASS__
|
253 |
));
|
254 |
}
|
application/Backend/Feature/Main/Metabox.php
CHANGED
@@ -5,183 +5,203 @@
|
|
5 |
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
* file 'license.txt', which is part of this source code package. *
|
7 |
* ======================================================================
|
|
|
|
|
8 |
*/
|
9 |
|
10 |
/**
|
11 |
* Backend metaboxes & widgets manager
|
12 |
-
*
|
13 |
* @package AAM
|
14 |
-
* @
|
15 |
*/
|
16 |
-
class AAM_Backend_Feature_Main_Metabox
|
|
|
|
|
17 |
|
18 |
/**
|
19 |
-
*
|
|
|
|
|
20 |
*/
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
$allowed = AAM_Backend_Subject::getInstance()->isAllowedToManage();
|
25 |
-
if (!$allowed || !current_user_can('aam_manage_metaboxes')) {
|
26 |
-
AAM::api()->denyAccess(array('reason' => 'aam_manage_metaboxes'));
|
27 |
-
}
|
28 |
-
}
|
29 |
-
|
30 |
/**
|
31 |
-
*
|
32 |
*
|
33 |
-
* @
|
34 |
*/
|
35 |
-
|
36 |
-
$items = AAM_Core_Request::post('items', array());
|
37 |
-
$status = AAM_Core_Request::post('status');
|
38 |
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
-
foreach($items as $item) {
|
42 |
-
$object->save($item, $status);
|
43 |
-
}
|
44 |
-
|
45 |
-
return wp_json_encode(array('status' => 'success'));
|
46 |
-
}
|
47 |
-
|
48 |
/**
|
49 |
-
*
|
50 |
-
*
|
|
|
51 |
*/
|
52 |
-
|
53 |
-
|
54 |
-
}
|
55 |
-
|
56 |
/**
|
57 |
-
*
|
|
|
|
|
|
|
|
|
|
|
58 |
*/
|
59 |
-
public
|
60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
}
|
62 |
-
|
63 |
/**
|
64 |
-
*
|
65 |
-
*
|
66 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
*/
|
68 |
-
public function prepareInitialization()
|
|
|
69 |
global $wp_post_types;
|
70 |
|
71 |
-
AAM_Core_API::deleteOption(
|
72 |
-
|
73 |
-
$endpoints = array(
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
|
|
|
|
|
|
79 |
$endpoints[] = add_query_arg(
|
80 |
'init', 'metabox', admin_url('post-new.php?post_type=' . $type)
|
81 |
);
|
82 |
}
|
83 |
}
|
84 |
-
|
85 |
return wp_json_encode(
|
86 |
-
array(
|
87 |
-
'status' => 'success',
|
88 |
-
'endpoints' => $endpoints
|
89 |
-
)
|
90 |
);
|
91 |
}
|
92 |
-
|
93 |
/**
|
94 |
* Initialize metabox list
|
95 |
-
*
|
96 |
* @param string $post_type
|
97 |
-
*
|
98 |
* @return void
|
99 |
-
*
|
100 |
* @access public
|
|
|
101 |
*/
|
102 |
-
public function initialize($post_type)
|
|
|
103 |
$cache = $this->getMetaboxList();
|
104 |
-
|
105 |
if ($post_type === 'dashboard') {
|
106 |
$this->collectWidgets($cache);
|
107 |
} else {
|
108 |
$this->collectMetaboxes($post_type, $cache);
|
109 |
}
|
110 |
-
|
111 |
-
AAM_Core_API::updateOption(
|
112 |
}
|
113 |
|
114 |
/**
|
115 |
* Collect dashboard widgets
|
116 |
-
*
|
117 |
* @global type $wp_registered_widgets
|
118 |
-
*
|
119 |
* @return void
|
120 |
-
*
|
121 |
* @access protected
|
|
|
122 |
*/
|
123 |
-
protected function collectWidgets(&$cache)
|
|
|
124 |
global $wp_registered_widgets;
|
125 |
|
126 |
if (!isset($cache['widgets'])) {
|
127 |
$cache['widgets'] = array();
|
128 |
}
|
129 |
|
130 |
-
//
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
}
|
140 |
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
}
|
147 |
}
|
148 |
}
|
149 |
|
150 |
-
//
|
151 |
$this->collectMetaboxes('dashboard', $cache);
|
152 |
}
|
153 |
-
|
154 |
/**
|
155 |
* Collect metaboxes
|
156 |
-
*
|
157 |
* @param type $post_type
|
158 |
* @param type $cache
|
159 |
-
*
|
160 |
* @return void
|
161 |
-
*
|
162 |
* @access protected
|
163 |
* @global array $wp_meta_boxes
|
|
|
164 |
*/
|
165 |
-
protected function collectMetaboxes($post_type, &$cache)
|
|
|
166 |
global $wp_meta_boxes;
|
167 |
|
168 |
if (!isset($cache[$post_type])) {
|
169 |
$cache[$post_type] = array();
|
170 |
}
|
171 |
-
|
172 |
-
if (isset($wp_meta_boxes[$post_type])
|
173 |
-
foreach ($wp_meta_boxes[$post_type] as $levels) {
|
174 |
-
|
175 |
-
foreach ($
|
176 |
-
if (
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
'title' => wp_strip_all_tags($data['title'])
|
182 |
-
);
|
183 |
-
}
|
184 |
-
}
|
185 |
}
|
186 |
}
|
187 |
}
|
@@ -190,17 +210,21 @@ class AAM_Backend_Feature_Main_Metabox extends AAM_Backend_Feature_Abstract {
|
|
190 |
}
|
191 |
|
192 |
/**
|
193 |
-
*
|
194 |
-
*
|
|
|
|
|
|
|
|
|
195 |
*/
|
196 |
-
public function getMetaboxList()
|
|
|
197 |
global $wp_post_types;
|
198 |
-
|
199 |
-
$cache
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
if ($subject->getUID() === AAM_Core_Subject_Visitor::UID) {
|
204 |
if (!empty($cache['widgets'])) {
|
205 |
$response = array('widgets' => $cache['widgets']);
|
206 |
} else {
|
@@ -209,41 +233,35 @@ class AAM_Backend_Feature_Main_Metabox extends AAM_Backend_Feature_Abstract {
|
|
209 |
} else {
|
210 |
$response = $cache;
|
211 |
}
|
212 |
-
|
213 |
-
//
|
214 |
-
foreach(array_keys($response) as $id) {
|
215 |
-
if (
|
216 |
-
|
|
|
|
|
217 |
unset($response[$id]);
|
218 |
}
|
219 |
}
|
220 |
-
|
221 |
return $response;
|
222 |
}
|
223 |
-
|
224 |
-
/**
|
225 |
-
*
|
226 |
-
* @return type
|
227 |
-
*/
|
228 |
-
protected function isOverwritten() {
|
229 |
-
$object = AAM_Backend_Subject::getInstance()->getObject('metabox');
|
230 |
-
|
231 |
-
return $object->isOverwritten();
|
232 |
-
}
|
233 |
|
234 |
/**
|
235 |
-
* Register metabox
|
236 |
-
*
|
237 |
* @return void
|
238 |
-
*
|
239 |
* @access public
|
|
|
240 |
*/
|
241 |
-
public static function register()
|
242 |
-
|
|
|
243 |
'uid' => 'metabox',
|
244 |
'position' => 10,
|
245 |
'title' => __('Metaboxes & Widgets', AAM_KEY),
|
246 |
-
'capability' =>
|
247 |
'type' => 'main',
|
248 |
'subjects' => array(
|
249 |
AAM_Core_Subject_Role::UID,
|
@@ -251,7 +269,6 @@ class AAM_Backend_Feature_Main_Metabox extends AAM_Backend_Feature_Abstract {
|
|
251 |
AAM_Core_Subject_Visitor::UID,
|
252 |
AAM_Core_Subject_Default::UID
|
253 |
),
|
254 |
-
'option' => 'core.settings.backendAccessControl',
|
255 |
'view' => __CLASS__
|
256 |
));
|
257 |
}
|
5 |
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
* file 'license.txt', which is part of this source code package. *
|
7 |
* ======================================================================
|
8 |
+
*
|
9 |
+
* @version 6.0.0
|
10 |
*/
|
11 |
|
12 |
/**
|
13 |
* Backend metaboxes & widgets manager
|
14 |
+
*
|
15 |
* @package AAM
|
16 |
+
* @version 6.0.0
|
17 |
*/
|
18 |
+
class AAM_Backend_Feature_Main_Metabox
|
19 |
+
extends AAM_Backend_Feature_Abstract implements AAM_Backend_Feature_ISubjectAware
|
20 |
+
{
|
21 |
|
22 |
/**
|
23 |
+
* DB cache option
|
24 |
+
*
|
25 |
+
* @version 6.0.0
|
26 |
*/
|
27 |
+
const DB_CACHE_OPTION = 'aam_metabox_cache';
|
28 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
/**
|
30 |
+
* Default access capability to the service
|
31 |
*
|
32 |
+
* @version 6.0.0
|
33 |
*/
|
34 |
+
const ACCESS_CAPABILITY = 'aam_manage_metaboxes';
|
|
|
|
|
35 |
|
36 |
+
/**
|
37 |
+
* Type of AAM core object
|
38 |
+
*
|
39 |
+
* @version 6.0.0
|
40 |
+
*/
|
41 |
+
const OBJECT_TYPE = AAM_Core_Object_Metabox::OBJECT_TYPE;
|
42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
/**
|
44 |
+
* HTML template to render
|
45 |
+
*
|
46 |
+
* @version 6.0.0
|
47 |
*/
|
48 |
+
const TEMPLATE = 'service/metabox.phtml';
|
49 |
+
|
|
|
|
|
50 |
/**
|
51 |
+
* Save metabox access settings
|
52 |
+
*
|
53 |
+
* @return string
|
54 |
+
*
|
55 |
+
* @access public
|
56 |
+
* @version 6.0.0
|
57 |
*/
|
58 |
+
public function save()
|
59 |
+
{
|
60 |
+
$items = AAM_Core_Request::post('items', array());
|
61 |
+
$status = AAM_Core_Request::post('status');
|
62 |
+
|
63 |
+
$object = AAM_Backend_Subject::getInstance()->getObject(
|
64 |
+
self::OBJECT_TYPE, null, true
|
65 |
+
);
|
66 |
+
|
67 |
+
foreach ($items as $item) {
|
68 |
+
$object->updateOptionItem($item, $status);
|
69 |
+
}
|
70 |
+
|
71 |
+
return wp_json_encode(
|
72 |
+
array('status' => ($object->save() ? 'success' : 'failure'))
|
73 |
+
);
|
74 |
}
|
75 |
+
|
76 |
/**
|
77 |
+
* Prepare the Metabox & Widgets initialization process
|
78 |
+
*
|
79 |
+
* This method is invoked when user clicks "Refresh" button on the AAM UI
|
80 |
+
*
|
81 |
+
* @return string
|
82 |
+
*
|
83 |
+
* @access public
|
84 |
+
* @global array $wp_post_types
|
85 |
+
* @version 6.0.0
|
86 |
*/
|
87 |
+
public function prepareInitialization()
|
88 |
+
{
|
89 |
global $wp_post_types;
|
90 |
|
91 |
+
AAM_Core_API::deleteOption(self::DB_CACHE_OPTION);
|
92 |
+
|
93 |
+
$endpoints = array(add_query_arg(
|
94 |
+
'init', 'metabox', admin_url('index.php')
|
95 |
+
));
|
96 |
+
|
97 |
+
foreach (array_keys($wp_post_types) as $type) {
|
98 |
+
$isVisible = $wp_post_types[$type]->show_ui;
|
99 |
+
$isClassic = empty($wp_post_types[$type]->show_in_rest);
|
100 |
+
|
101 |
+
if ($isVisible && $isClassic) {
|
102 |
$endpoints[] = add_query_arg(
|
103 |
'init', 'metabox', admin_url('post-new.php?post_type=' . $type)
|
104 |
);
|
105 |
}
|
106 |
}
|
107 |
+
|
108 |
return wp_json_encode(
|
109 |
+
array('status' => 'success', 'endpoints' => $endpoints)
|
|
|
|
|
|
|
110 |
);
|
111 |
}
|
112 |
+
|
113 |
/**
|
114 |
* Initialize metabox list
|
115 |
+
*
|
116 |
* @param string $post_type
|
117 |
+
*
|
118 |
* @return void
|
119 |
+
*
|
120 |
* @access public
|
121 |
+
* @version 6.0.0
|
122 |
*/
|
123 |
+
public function initialize($post_type)
|
124 |
+
{
|
125 |
$cache = $this->getMetaboxList();
|
126 |
+
|
127 |
if ($post_type === 'dashboard') {
|
128 |
$this->collectWidgets($cache);
|
129 |
} else {
|
130 |
$this->collectMetaboxes($post_type, $cache);
|
131 |
}
|
132 |
+
|
133 |
+
AAM_Core_API::updateOption(self::DB_CACHE_OPTION, $cache);
|
134 |
}
|
135 |
|
136 |
/**
|
137 |
* Collect dashboard widgets
|
138 |
+
*
|
139 |
* @global type $wp_registered_widgets
|
140 |
+
*
|
141 |
* @return void
|
142 |
+
*
|
143 |
* @access protected
|
144 |
+
* @version 6.0.0
|
145 |
*/
|
146 |
+
protected function collectWidgets(&$cache)
|
147 |
+
{
|
148 |
global $wp_registered_widgets;
|
149 |
|
150 |
if (!isset($cache['widgets'])) {
|
151 |
$cache['widgets'] = array();
|
152 |
}
|
153 |
|
154 |
+
// Get frontend widgets
|
155 |
+
foreach ((array)$wp_registered_widgets as $data) {
|
156 |
+
if (is_object($data['callback'][0])) {
|
157 |
+
$callback = get_class($data['callback'][0]);
|
158 |
+
} elseif (is_string($data['callback'][0])) {
|
159 |
+
$callback = $data['callback'][0];
|
160 |
+
} else {
|
161 |
+
$callback = isset($data['classname']) ? $data['classname'] : null;
|
162 |
+
}
|
|
|
163 |
|
164 |
+
if (!is_null($callback)) { //exclude any junk
|
165 |
+
$cache['widgets'][$callback] = array(
|
166 |
+
'title' => wp_strip_all_tags($data['name']),
|
167 |
+
'id' => $callback
|
168 |
+
);
|
|
|
169 |
}
|
170 |
}
|
171 |
|
172 |
+
// Now collect Admin Dashboard Widgets
|
173 |
$this->collectMetaboxes('dashboard', $cache);
|
174 |
}
|
175 |
+
|
176 |
/**
|
177 |
* Collect metaboxes
|
178 |
+
*
|
179 |
* @param type $post_type
|
180 |
* @param type $cache
|
181 |
+
*
|
182 |
* @return void
|
183 |
+
*
|
184 |
* @access protected
|
185 |
* @global array $wp_meta_boxes
|
186 |
+
* @version 6.0.0
|
187 |
*/
|
188 |
+
protected function collectMetaboxes($post_type, &$cache)
|
189 |
+
{
|
190 |
global $wp_meta_boxes;
|
191 |
|
192 |
if (!isset($cache[$post_type])) {
|
193 |
$cache[$post_type] = array();
|
194 |
}
|
195 |
+
|
196 |
+
if (isset($wp_meta_boxes[$post_type])) {
|
197 |
+
foreach ((array) $wp_meta_boxes[$post_type] as $levels) {
|
198 |
+
foreach ((array) $levels as $boxes) {
|
199 |
+
foreach ((array) $boxes as $data) {
|
200 |
+
if (trim($data['id'])) { //exclude any junk
|
201 |
+
$cache[$post_type][$data['id']] = array(
|
202 |
+
'id' => $data['id'],
|
203 |
+
'title' => wp_strip_all_tags($data['title'])
|
204 |
+
);
|
|
|
|
|
|
|
|
|
205 |
}
|
206 |
}
|
207 |
}
|
210 |
}
|
211 |
|
212 |
/**
|
213 |
+
* Get list of metaboxes & widgets
|
214 |
+
*
|
215 |
+
* @return array
|
216 |
+
*
|
217 |
+
* @access public
|
218 |
+
* @version 6.0.0
|
219 |
*/
|
220 |
+
public function getMetaboxList()
|
221 |
+
{
|
222 |
global $wp_post_types;
|
223 |
+
|
224 |
+
$cache = AAM_Core_API::getOption(self::DB_CACHE_OPTION, array());
|
225 |
+
|
226 |
+
// If visitor, return only frontend widgets
|
227 |
+
if (AAM_Backend_Subject::getInstance()->isVisitor()) {
|
|
|
228 |
if (!empty($cache['widgets'])) {
|
229 |
$response = array('widgets' => $cache['widgets']);
|
230 |
} else {
|
233 |
} else {
|
234 |
$response = $cache;
|
235 |
}
|
236 |
+
|
237 |
+
// Filter non-existing metaboxes
|
238 |
+
foreach (array_keys($response) as $id) {
|
239 |
+
if (
|
240 |
+
!in_array($id, array('dashboard', 'widgets'), true)
|
241 |
+
&& empty($wp_post_types[$id])
|
242 |
+
) {
|
243 |
unset($response[$id]);
|
244 |
}
|
245 |
}
|
246 |
+
|
247 |
return $response;
|
248 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
249 |
|
250 |
/**
|
251 |
+
* Register metabox service UI
|
252 |
+
*
|
253 |
* @return void
|
254 |
+
*
|
255 |
* @access public
|
256 |
+
* @version 6.0.0
|
257 |
*/
|
258 |
+
public static function register()
|
259 |
+
{
|
260 |
+
AAM_Backend_Feature::registerFeature((object)array(
|
261 |
'uid' => 'metabox',
|
262 |
'position' => 10,
|
263 |
'title' => __('Metaboxes & Widgets', AAM_KEY),
|
264 |
+
'capability' => self::ACCESS_CAPABILITY,
|
265 |
'type' => 'main',
|
266 |
'subjects' => array(
|
267 |
AAM_Core_Subject_Role::UID,
|
269 |
AAM_Core_Subject_Visitor::UID,
|
270 |
AAM_Core_Subject_Default::UID
|
271 |
),
|
|
|
272 |
'view' => __CLASS__
|
273 |
));
|
274 |
}
|
application/Backend/Feature/Main/Policy.php
CHANGED
@@ -13,28 +13,23 @@
|
|
13 |
* @package AAM
|
14 |
* @author Vasyl Martyniuk <vasyl@vasyltech.com>
|
15 |
*/
|
16 |
-
class AAM_Backend_Feature_Main_Policy extends AAM_Backend_Feature_Abstract
|
17 |
-
|
|
|
18 |
/**
|
19 |
-
*
|
20 |
*/
|
21 |
-
|
22 |
-
parent::__construct();
|
23 |
-
|
24 |
-
$allowed = AAM_Backend_Subject::getInstance()->isAllowedToManage();
|
25 |
-
if (!$allowed || !current_user_can('aam_manage_policy')) {
|
26 |
-
AAM::api()->denyAccess(array('reason' => 'aam_manage_policy'));
|
27 |
-
}
|
28 |
-
}
|
29 |
|
30 |
/**
|
31 |
*
|
32 |
* @return type
|
33 |
*/
|
34 |
-
public function getTable()
|
|
|
35 |
return wp_json_encode($this->retrievePolicies());
|
36 |
}
|
37 |
-
|
38 |
/**
|
39 |
* Install policy
|
40 |
*
|
@@ -43,12 +38,13 @@ class AAM_Backend_Feature_Main_Policy extends AAM_Backend_Feature_Abstract {
|
|
43 |
* @access public
|
44 |
* @since v5.7.3
|
45 |
*/
|
46 |
-
public function install()
|
47 |
-
|
48 |
-
|
|
|
49 |
if (!empty($package->content)) {
|
50 |
$json = base64_decode($package->content);
|
51 |
-
|
52 |
$result = wp_insert_post(array(
|
53 |
'post_author' => get_current_user_id(),
|
54 |
'post_content' => $json,
|
@@ -57,7 +53,7 @@ class AAM_Backend_Feature_Main_Policy extends AAM_Backend_Feature_Abstract {
|
|
57 |
'post_status' => 'publish',
|
58 |
'post_type' => 'aam_policy'
|
59 |
));
|
60 |
-
|
61 |
if (!is_wp_error($result)) {
|
62 |
$response = array('status' => 'success');
|
63 |
} else {
|
@@ -67,11 +63,11 @@ class AAM_Backend_Feature_Main_Policy extends AAM_Backend_Feature_Abstract {
|
|
67 |
}
|
68 |
} else {
|
69 |
$response = array(
|
70 |
-
'status' => 'failure',
|
71 |
'reason' => __('Failed to fetch policy. Please try again.', AAM_KEY)
|
72 |
);
|
73 |
}
|
74 |
-
|
75 |
return wp_json_encode($response);
|
76 |
}
|
77 |
|
@@ -82,16 +78,18 @@ class AAM_Backend_Feature_Main_Policy extends AAM_Backend_Feature_Abstract {
|
|
82 |
*
|
83 |
* @access public
|
84 |
*/
|
85 |
-
public function save()
|
|
|
86 |
$subject = AAM_Backend_Subject::getInstance();
|
87 |
$id = AAM_Core_Request::post('id');
|
88 |
$effect = AAM_Core_Request::post('effect');
|
89 |
-
|
90 |
$action = (!empty($effect) ? 'attach' : 'detach');
|
91 |
-
|
92 |
// Verify that current user can perform following action
|
93 |
if (AAM_Core_Policy_Factory::get()->canTogglePolicy($id, $action)) {
|
94 |
-
$
|
|
|
95 |
} else {
|
96 |
$result = false;
|
97 |
}
|
@@ -100,22 +98,26 @@ class AAM_Backend_Feature_Main_Policy extends AAM_Backend_Feature_Abstract {
|
|
100 |
'status' => ($result ? 'success' : 'failure')
|
101 |
));
|
102 |
}
|
103 |
-
|
104 |
/**
|
105 |
*
|
106 |
* @return type
|
107 |
*/
|
108 |
-
public function reset()
|
109 |
-
|
|
|
|
|
|
|
110 |
}
|
111 |
-
|
112 |
/**
|
113 |
* @inheritdoc
|
114 |
*/
|
115 |
-
public static function getTemplate()
|
116 |
-
|
|
|
117 |
}
|
118 |
-
|
119 |
/**
|
120 |
* Check inheritance status
|
121 |
*
|
@@ -125,33 +127,35 @@ class AAM_Backend_Feature_Main_Policy extends AAM_Backend_Feature_Abstract {
|
|
125 |
*
|
126 |
* @access protected
|
127 |
*/
|
128 |
-
protected function isOverwritten()
|
|
|
129 |
$object = AAM_Backend_Subject::getInstance()->getObject('policy');
|
130 |
-
|
131 |
return $object->isOverwritten();
|
132 |
}
|
133 |
-
|
134 |
/**
|
135 |
*
|
136 |
* @return type
|
137 |
*/
|
138 |
-
protected function retrievePolicies()
|
|
|
139 |
$list = get_posts(array(
|
140 |
'post_type' => 'aam_policy',
|
141 |
'numberposts' => -1,
|
142 |
'post_status' => 'publish'
|
143 |
));
|
144 |
-
|
145 |
$response = array(
|
146 |
'recordsTotal' => count($list),
|
147 |
'recordsFiltered' => count($list),
|
148 |
'draw' => AAM_Core_Request::request('draw'),
|
149 |
'data' => array(),
|
150 |
);
|
151 |
-
|
152 |
-
foreach($list as $record) {
|
153 |
$policy = json_decode($record->post_content);
|
154 |
-
|
155 |
if ($policy) {
|
156 |
$response['data'][] = array(
|
157 |
$record->ID,
|
@@ -161,45 +165,47 @@ class AAM_Backend_Feature_Main_Policy extends AAM_Backend_Feature_Abstract {
|
|
161 |
);
|
162 |
}
|
163 |
}
|
164 |
-
|
165 |
return $response;
|
166 |
}
|
167 |
-
|
168 |
/**
|
169 |
*
|
170 |
* @param type $record
|
171 |
* @return string
|
172 |
*/
|
173 |
-
protected function buildTitle($record)
|
|
|
174 |
$title = (!empty($record->post_title) ? $record->post_title : __('(no title)'));
|
175 |
$title .= '<br/>';
|
176 |
-
|
177 |
if (isset($record->post_excerpt)) {
|
178 |
$title .= '<small>' . esc_js($record->post_excerpt) . '</small>';
|
179 |
}
|
180 |
-
|
181 |
return $title;
|
182 |
}
|
183 |
-
|
184 |
/**
|
185 |
*
|
186 |
* @param type $record
|
187 |
* @return type
|
188 |
*/
|
189 |
-
protected function buildActionList($record)
|
|
|
190 |
//'assign,edit,clone,delete'
|
191 |
$subject = AAM_Backend_Subject::getInstance();
|
192 |
$policy = $subject->getObject('policy');
|
193 |
$post = $subject->getObject('post', $record->ID);
|
194 |
-
|
195 |
$action = $policy->has($record->ID) ? 'detach' : 'attach';
|
196 |
$prefix = AAM_Core_Policy_Factory::get()->canTogglePolicy($record->ID, $action) ? '' : 'no-';
|
197 |
-
|
198 |
$actions = array(
|
199 |
$policy->has($record->ID) ? "{$prefix}detach" : "{$prefix}attach",
|
200 |
-
$post->
|
201 |
);
|
202 |
-
|
203 |
return implode(',', $actions);
|
204 |
}
|
205 |
|
@@ -210,15 +216,16 @@ class AAM_Backend_Feature_Main_Policy extends AAM_Backend_Feature_Abstract {
|
|
210 |
*
|
211 |
* @access public
|
212 |
*/
|
213 |
-
public static function register()
|
214 |
-
|
|
|
215 |
'uid' => 'policy',
|
216 |
'position' => 2,
|
217 |
-
'title' => __('Access Policies', AAM_KEY)
|
218 |
-
'capability' =>
|
219 |
'type' => 'main',
|
220 |
'subjects' => array(
|
221 |
-
AAM_Core_Subject_Role::UID,
|
222 |
AAM_Core_Subject_User::UID,
|
223 |
AAM_Core_Subject_Visitor::UID,
|
224 |
AAM_Core_Subject_Default::UID
|
@@ -226,5 +233,4 @@ class AAM_Backend_Feature_Main_Policy extends AAM_Backend_Feature_Abstract {
|
|
226 |
'view' => __CLASS__
|
227 |
));
|
228 |
}
|
229 |
-
|
230 |
-
}
|
13 |
* @package AAM
|
14 |
* @author Vasyl Martyniuk <vasyl@vasyltech.com>
|
15 |
*/
|
16 |
+
class AAM_Backend_Feature_Main_Policy extends AAM_Backend_Feature_Abstract implements AAM_Backend_Feature_ISubjectAware
|
17 |
+
{
|
18 |
+
|
19 |
/**
|
20 |
+
* Default access capability to the feature
|
21 |
*/
|
22 |
+
const ACCESS_CAPABILITY = 'aam_manage_policy';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
/**
|
25 |
*
|
26 |
* @return type
|
27 |
*/
|
28 |
+
public function getTable()
|
29 |
+
{
|
30 |
return wp_json_encode($this->retrievePolicies());
|
31 |
}
|
32 |
+
|
33 |
/**
|
34 |
* Install policy
|
35 |
*
|
38 |
* @access public
|
39 |
* @since v5.7.3
|
40 |
*/
|
41 |
+
public function install()
|
42 |
+
{
|
43 |
+
$package = (object)AAM_Core_Request::post('package');
|
44 |
+
|
45 |
if (!empty($package->content)) {
|
46 |
$json = base64_decode($package->content);
|
47 |
+
|
48 |
$result = wp_insert_post(array(
|
49 |
'post_author' => get_current_user_id(),
|
50 |
'post_content' => $json,
|
53 |
'post_status' => 'publish',
|
54 |
'post_type' => 'aam_policy'
|
55 |
));
|
56 |
+
|
57 |
if (!is_wp_error($result)) {
|
58 |
$response = array('status' => 'success');
|
59 |
} else {
|
63 |
}
|
64 |
} else {
|
65 |
$response = array(
|
66 |
+
'status' => 'failure',
|
67 |
'reason' => __('Failed to fetch policy. Please try again.', AAM_KEY)
|
68 |
);
|
69 |
}
|
70 |
+
|
71 |
return wp_json_encode($response);
|
72 |
}
|
73 |
|
78 |
*
|
79 |
* @access public
|
80 |
*/
|
81 |
+
public function save()
|
82 |
+
{
|
83 |
$subject = AAM_Backend_Subject::getInstance();
|
84 |
$id = AAM_Core_Request::post('id');
|
85 |
$effect = AAM_Core_Request::post('effect');
|
86 |
+
|
87 |
$action = (!empty($effect) ? 'attach' : 'detach');
|
88 |
+
|
89 |
// Verify that current user can perform following action
|
90 |
if (AAM_Core_Policy_Factory::get()->canTogglePolicy($id, $action)) {
|
91 |
+
$object = $subject->getObject('policy', null, true);
|
92 |
+
$result = $object->updateOptionItem($id, $effect)->save();
|
93 |
} else {
|
94 |
$result = false;
|
95 |
}
|
98 |
'status' => ($result ? 'success' : 'failure')
|
99 |
));
|
100 |
}
|
101 |
+
|
102 |
/**
|
103 |
*
|
104 |
* @return type
|
105 |
*/
|
106 |
+
public function reset()
|
107 |
+
{
|
108 |
+
$object = AAM_Backend_Subject::getInstance()->getObject('policy');
|
109 |
+
|
110 |
+
return $object->reset();
|
111 |
}
|
112 |
+
|
113 |
/**
|
114 |
* @inheritdoc
|
115 |
*/
|
116 |
+
public static function getTemplate()
|
117 |
+
{
|
118 |
+
return 'service/policy.phtml';
|
119 |
}
|
120 |
+
|
121 |
/**
|
122 |
* Check inheritance status
|
123 |
*
|
127 |
*
|
128 |
* @access protected
|
129 |
*/
|
130 |
+
protected function isOverwritten()
|
131 |
+
{
|
132 |
$object = AAM_Backend_Subject::getInstance()->getObject('policy');
|
133 |
+
|
134 |
return $object->isOverwritten();
|
135 |
}
|
136 |
+
|
137 |
/**
|
138 |
*
|
139 |
* @return type
|
140 |
*/
|
141 |
+
protected function retrievePolicies()
|
142 |
+
{
|
143 |
$list = get_posts(array(
|
144 |
'post_type' => 'aam_policy',
|
145 |
'numberposts' => -1,
|
146 |
'post_status' => 'publish'
|
147 |
));
|
148 |
+
|
149 |
$response = array(
|
150 |
'recordsTotal' => count($list),
|
151 |
'recordsFiltered' => count($list),
|
152 |
'draw' => AAM_Core_Request::request('draw'),
|
153 |
'data' => array(),
|
154 |
);
|
155 |
+
|
156 |
+
foreach ($list as $record) {
|
157 |
$policy = json_decode($record->post_content);
|
158 |
+
|
159 |
if ($policy) {
|
160 |
$response['data'][] = array(
|
161 |
$record->ID,
|
165 |
);
|
166 |
}
|
167 |
}
|
168 |
+
|
169 |
return $response;
|
170 |
}
|
171 |
+
|
172 |
/**
|
173 |
*
|
174 |
* @param type $record
|
175 |
* @return string
|
176 |
*/
|
177 |
+
protected function buildTitle($record)
|
178 |
+
{
|
179 |
$title = (!empty($record->post_title) ? $record->post_title : __('(no title)'));
|
180 |
$title .= '<br/>';
|
181 |
+
|
182 |
if (isset($record->post_excerpt)) {
|
183 |
$title .= '<small>' . esc_js($record->post_excerpt) . '</small>';
|
184 |
}
|
185 |
+
|
186 |
return $title;
|
187 |
}
|
188 |
+
|
189 |
/**
|
190 |
*
|
191 |
* @param type $record
|
192 |
* @return type
|
193 |
*/
|
194 |
+
protected function buildActionList($record)
|
195 |
+
{
|
196 |
//'assign,edit,clone,delete'
|
197 |
$subject = AAM_Backend_Subject::getInstance();
|
198 |
$policy = $subject->getObject('policy');
|
199 |
$post = $subject->getObject('post', $record->ID);
|
200 |
+
|
201 |
$action = $policy->has($record->ID) ? 'detach' : 'attach';
|
202 |
$prefix = AAM_Core_Policy_Factory::get()->canTogglePolicy($record->ID, $action) ? '' : 'no-';
|
203 |
+
|
204 |
$actions = array(
|
205 |
$policy->has($record->ID) ? "{$prefix}detach" : "{$prefix}attach",
|
206 |
+
$post->isAllowedTo('edit') ? 'edit' : 'no-edit'
|
207 |
);
|
208 |
+
|
209 |
return implode(',', $actions);
|
210 |
}
|
211 |
|
216 |
*
|
217 |
* @access public
|
218 |
*/
|
219 |
+
public static function register()
|
220 |
+
{
|
221 |
+
AAM_Backend_Feature::registerFeature((object)array(
|
222 |
'uid' => 'policy',
|
223 |
'position' => 2,
|
224 |
+
'title' => __('Access Policies', AAM_KEY),
|
225 |
+
'capability' => self::ACCESS_CAPABILITY,
|
226 |
'type' => 'main',
|
227 |
'subjects' => array(
|
228 |
+
AAM_Core_Subject_Role::UID,
|
229 |
AAM_Core_Subject_User::UID,
|
230 |
AAM_Core_Subject_Visitor::UID,
|
231 |
AAM_Core_Subject_Default::UID
|
233 |
'view' => __CLASS__
|
234 |
));
|
235 |
}
|
236 |
+
}
|
|
application/Backend/Feature/Main/Post.php
CHANGED
@@ -5,169 +5,676 @@
|
|
5 |
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
* file 'license.txt', which is part of this source code package. *
|
7 |
* ======================================================================
|
|
|
|
|
8 |
*/
|
9 |
|
10 |
/**
|
11 |
-
* Backend posts &
|
12 |
-
*
|
13 |
* @package AAM
|
14 |
-
* @
|
15 |
*/
|
16 |
-
class AAM_Backend_Feature_Main_Post
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
/**
|
19 |
-
*
|
|
|
|
|
20 |
*/
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
}
|
29 |
-
|
30 |
/**
|
31 |
-
* Get
|
32 |
-
*
|
|
|
|
|
|
|
33 |
* @return string
|
34 |
-
*
|
35 |
* @access public
|
|
|
36 |
*/
|
37 |
-
public function
|
38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
}
|
45 |
|
46 |
-
return $
|
47 |
}
|
48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
/**
|
50 |
-
*
|
51 |
-
*
|
52 |
* @return array
|
53 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
* @access protected
|
|
|
55 |
*/
|
56 |
-
protected function
|
57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
$response = array(
|
59 |
-
'data' => array(),
|
60 |
-
'recordsTotal' => $list->total,
|
61 |
'recordsFiltered' => $list->filtered
|
62 |
);
|
63 |
-
|
64 |
foreach ($list->records as $type) {
|
65 |
-
$
|
66 |
-
$
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
}
|
80 |
-
|
81 |
return $response;
|
82 |
}
|
83 |
-
|
84 |
/**
|
85 |
-
*
|
86 |
-
*
|
|
|
|
|
|
|
|
|
87 |
*/
|
88 |
-
protected function
|
89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
$filtered = array();
|
91 |
-
|
92 |
-
//filters
|
93 |
$s = AAM_Core_Request::post('search.value');
|
94 |
$length = AAM_Core_Request::post('length');
|
95 |
$start = AAM_Core_Request::post('start');
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
&& (empty($s) || stripos($type->labels->name, $s) !== false)) {
|
101 |
-
$filtered[$type->label] = $type;
|
102 |
}
|
103 |
}
|
104 |
-
|
105 |
$this->getOrderDirection() === 'ASC' ? ksort($filtered) : krsort($filtered);
|
106 |
-
|
107 |
return (object) array(
|
108 |
'total' => count($list),
|
109 |
'filtered' => count($filtered),
|
110 |
'records' => array_slice($filtered, $start, $length)
|
111 |
);
|
112 |
}
|
113 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
/**
|
115 |
-
*
|
116 |
-
*
|
|
|
|
|
|
|
|
|
117 |
*/
|
118 |
-
protected function getOrderDirection()
|
|
|
119 |
$dir = 'asc';
|
120 |
$order = AAM_Core_Request::post('order.0');
|
121 |
-
|
122 |
if (!empty($order['column']) && ($order['column'] === '3')) {
|
123 |
$dir = !empty($order['dir']) ? $order['dir'] : 'asc';
|
124 |
}
|
125 |
-
|
126 |
return strtoupper($dir);
|
127 |
}
|
128 |
|
129 |
/**
|
130 |
-
* Get post type children
|
131 |
-
*
|
132 |
* Retrieve list of all posts and terms that belong to specified post type
|
133 |
-
*
|
134 |
* @param string $type
|
135 |
-
*
|
136 |
* @return array
|
137 |
-
*
|
138 |
* @access protected
|
|
|
139 |
*/
|
140 |
-
protected function
|
141 |
-
|
142 |
-
$
|
|
|
143 |
$response = array(
|
144 |
-
'data' => array(),
|
145 |
-
'recordsTotal' => $list->total,
|
146 |
'recordsFiltered' => $list->filtered
|
147 |
);
|
148 |
-
|
149 |
-
foreach($list->records as $record) {
|
150 |
-
if (isset($record->ID)) { //this is post
|
151 |
$link = get_edit_post_link($record->ID, 'link');
|
152 |
-
|
153 |
$parent = '';
|
154 |
-
|
155 |
if (!empty($record->post_parent)) {
|
156 |
$p = get_post($record->post_parent);
|
157 |
$parent = (is_a($p, 'WP_Post') ? $p->post_title : '');
|
158 |
}
|
159 |
-
|
160 |
if (empty($parent)) {
|
161 |
$taxonomies = get_object_taxonomies($record);
|
162 |
|
163 |
if (!empty($taxonomies)) {
|
164 |
$terms = wp_get_object_terms(
|
165 |
-
|
|
|
|
|
166 |
);
|
167 |
$parent = implode(', ', $terms);
|
168 |
}
|
169 |
}
|
170 |
-
|
171 |
$response['data'][] = array(
|
172 |
$record->ID,
|
173 |
$link,
|
@@ -175,37 +682,66 @@ class AAM_Backend_Feature_Main_Post extends AAM_Backend_Feature_Abstract {
|
|
175 |
get_the_title($record),
|
176 |
'manage' . ($link ? ',edit' : ',no-edit'),
|
177 |
$parent,
|
178 |
-
$subject->getObject('post', $record->ID)->isOverwritten()
|
179 |
-
);
|
180 |
-
} else { //term
|
181 |
-
$response['data'][] = array(
|
182 |
-
$record->term_id . '|' . $record->taxonomy . '|' . $type,
|
183 |
-
get_edit_term_link($record->term_id, $record->taxonomy),
|
184 |
-
(is_taxonomy_hierarchical($record->taxonomy) ? 'cat' : 'tag'),
|
185 |
-
$record->name,
|
186 |
-
implode(',', apply_filters('aam-term-row-actions', array('manage', 'edit'), $subject, $record, $type)),
|
187 |
-
is_taxonomy_hierarchical($record->taxonomy) ? rtrim($this->getParentTermList($record), '/') : '',
|
188 |
-
apply_filters(
|
189 |
-
'aam-term-override-status',
|
190 |
-
false,
|
191 |
-
$record->term_id . '|' . $record->taxonomy,
|
192 |
-
$subject
|
193 |
-
)
|
194 |
);
|
|
|
|
|
195 |
}
|
196 |
}
|
197 |
|
198 |
return $response;
|
199 |
}
|
200 |
-
|
201 |
/**
|
202 |
-
*
|
203 |
-
*
|
204 |
-
* @param
|
205 |
-
* @
|
206 |
-
*
|
|
|
|
|
|
|
|
|
207 |
*/
|
208 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
209 |
global $wp_version;
|
210 |
|
211 |
$list = '';
|
@@ -244,77 +780,92 @@ class AAM_Backend_Feature_Main_Post extends AAM_Backend_Feature_Abstract {
|
|
244 |
}
|
245 |
|
246 |
/**
|
247 |
-
*
|
248 |
*
|
249 |
* @param string $type
|
250 |
-
*
|
251 |
-
* @return
|
|
|
|
|
|
|
252 |
*/
|
253 |
-
protected function
|
|
|
254 |
$list = array();
|
255 |
-
|
|
|
256 |
$s = AAM_Core_Request::post('search.value');
|
257 |
$length = AAM_Core_Request::post('length');
|
258 |
$start = AAM_Core_Request::post('start');
|
259 |
-
|
260 |
-
//
|
261 |
$paging = $this->getFetchPagination($type, $s, $start, $length);
|
262 |
-
|
263 |
-
//
|
264 |
if ($paging['terms']) {
|
265 |
$list = $this->retrieveTermList(
|
266 |
-
get_object_taxonomies($type),
|
267 |
-
$s,
|
268 |
-
$paging['term_offset'],
|
269 |
$paging['terms']
|
270 |
);
|
271 |
}
|
272 |
-
|
273 |
-
//
|
274 |
if ($paging['posts']) {
|
275 |
$list = array_merge(
|
276 |
-
$list,
|
277 |
$this->retrievePostList(
|
278 |
-
$type,
|
|
|
|
|
|
|
279 |
)
|
280 |
);
|
281 |
}
|
282 |
-
|
283 |
return (object) array(
|
284 |
'total' => $paging['total'],
|
285 |
'filtered' => $paging['total'],
|
286 |
'records' => $list
|
287 |
);
|
288 |
}
|
289 |
-
|
290 |
/**
|
291 |
-
*
|
292 |
-
*
|
293 |
-
* @param
|
294 |
-
* @param
|
295 |
-
* @param
|
296 |
-
* @
|
|
|
|
|
|
|
|
|
|
|
297 |
*/
|
298 |
-
protected function getFetchPagination($type, $search, $offset, $limit)
|
|
|
299 |
$result = array('terms' => 0, 'posts' => 0, 'term_offset' => $offset);
|
300 |
-
|
301 |
//get terms count
|
302 |
$taxonomy = get_object_taxonomies($type);
|
303 |
-
|
304 |
if (!empty($taxonomy)) {
|
305 |
$terms = get_terms(array(
|
306 |
-
'fields'
|
307 |
-
'search'
|
308 |
-
'hide_empty'
|
309 |
-
'
|
|
|
310 |
));
|
311 |
} else {
|
312 |
$terms = 0;
|
313 |
}
|
314 |
-
|
315 |
//get posts count
|
316 |
$posts = $this->getPostCount($type, $search);
|
317 |
-
|
318 |
if ($offset < $terms) {
|
319 |
if ($terms - $limit >= $offset) {
|
320 |
$result['terms'] = $limit;
|
@@ -325,324 +876,119 @@ class AAM_Backend_Feature_Main_Post extends AAM_Backend_Feature_Abstract {
|
|
325 |
} else {
|
326 |
$result['posts'] = $limit;
|
327 |
}
|
328 |
-
|
329 |
$result['total'] = $terms + $posts;
|
330 |
$result['post_offset'] = ($offset ? $offset - $terms : 0);
|
331 |
-
|
332 |
return $result;
|
333 |
}
|
334 |
-
|
335 |
/**
|
336 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
337 |
* @global type $wpdb
|
338 |
-
* @
|
339 |
-
* @param type $search
|
340 |
-
* @return type
|
341 |
*/
|
342 |
-
protected function getPostCount($type, $search)
|
|
|
343 |
global $wpdb;
|
344 |
-
|
345 |
$query = "SELECT COUNT(*) AS total FROM {$wpdb->posts} ";
|
346 |
-
$query .= "WHERE (post_type = %s) AND (post_title LIKE %s
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
|
|
351 |
$query .= " AND ({$wpdb->posts}.post_status <> %s)";
|
352 |
$args[] = $status;
|
353 |
}
|
354 |
-
|
355 |
return $wpdb->get_var($wpdb->prepare($query, $args));
|
356 |
}
|
357 |
-
|
358 |
/**
|
359 |
* Retrieve term list
|
360 |
-
*
|
361 |
-
* @param array
|
362 |
-
*
|
|
|
|
|
|
|
363 |
* @return array
|
364 |
-
*
|
365 |
* @access protected
|
|
|
366 |
*/
|
367 |
-
protected function retrieveTermList($taxonomies, $search, $offset, $limit)
|
|
|
368 |
$args = array(
|
369 |
-
'fields'
|
370 |
-
'hide_empty'
|
371 |
-
'search'
|
372 |
-
'
|
373 |
-
'
|
374 |
-
'
|
375 |
-
'
|
|
|
376 |
);
|
377 |
|
378 |
return get_terms($args);
|
379 |
}
|
380 |
-
|
381 |
/**
|
382 |
-
*
|
|
|
383 |
* @param string $type
|
384 |
* @param string $search
|
385 |
* @param int $offset
|
386 |
* @param int $limit
|
387 |
-
*
|
388 |
* @return array
|
|
|
|
|
|
|
389 |
*/
|
390 |
-
protected function retrievePostList($type, $search, $offset, $limit)
|
|
|
391 |
return get_posts(array(
|
392 |
-
'post_type' => $type,
|
393 |
-
'category' => 0,
|
394 |
's' => $search,
|
395 |
'suppress_filters' => true,
|
396 |
'offset' => $offset,
|
397 |
'numberposts' => $limit,
|
398 |
'orderby' => 'title',
|
399 |
'order' => $this->getOrderDirection(),
|
400 |
-
'post_status' => 'any',
|
401 |
'fields' => 'all'
|
402 |
));
|
403 |
}
|
404 |
|
405 |
/**
|
406 |
-
*
|
407 |
-
*
|
408 |
-
* @param array $response
|
409 |
-
*
|
410 |
-
* @return string
|
411 |
-
*
|
412 |
-
* @access protected
|
413 |
-
*/
|
414 |
-
protected function wrapTable($response) {
|
415 |
-
$response['draw'] = AAM_Core_Request::request('draw');
|
416 |
-
|
417 |
-
return wp_json_encode($response);
|
418 |
-
}
|
419 |
-
|
420 |
-
/**
|
421 |
-
* Get Post or Term access
|
422 |
*
|
423 |
-
* @return string
|
424 |
-
*
|
425 |
-
* @access public
|
426 |
-
*/
|
427 |
-
public function getAccess() {
|
428 |
-
$type = trim(AAM_Core_Request::post('type'));
|
429 |
-
$id = AAM_Core_Request::post('id');
|
430 |
-
$access = $metadata = array();
|
431 |
-
$object = AAM_Backend_Subject::getInstance()->getObject($type, $id);
|
432 |
-
|
433 |
-
//prepare the response object
|
434 |
-
$bValues = array(1, '1', 0, '0', false, "false", true, "true");
|
435 |
-
if (is_a($object, 'AAM_Core_Object')) {
|
436 |
-
foreach($object->getOption() as $key => $value) {
|
437 |
-
if (in_array($value, $bValues, true)) {
|
438 |
-
$access[$key] = !empty($value);
|
439 |
-
} else {
|
440 |
-
$access[$key] = $value;
|
441 |
-
}
|
442 |
-
}
|
443 |
-
$metadata = array('overwritten' => $object->isOverwritten());
|
444 |
-
$access = apply_filters('aam-get-post-access-filter', $access, $object);
|
445 |
-
}
|
446 |
-
|
447 |
-
return wp_json_encode(array(
|
448 |
-
'access' => $access,
|
449 |
-
'meta' => $metadata,
|
450 |
-
'preview' => $this->preparePreviewValues($access)
|
451 |
-
));
|
452 |
-
}
|
453 |
-
|
454 |
-
/**
|
455 |
-
*
|
456 |
-
* @param type $options
|
457 |
-
* @return type
|
458 |
-
*/
|
459 |
-
protected function preparePreviewValues($options) {
|
460 |
-
$previews = array();
|
461 |
-
|
462 |
-
foreach($options as $option => $value) {
|
463 |
-
$previews[$option] = $this->getPreviewValue($option, $value);
|
464 |
-
}
|
465 |
-
|
466 |
-
return $previews;
|
467 |
-
}
|
468 |
-
|
469 |
-
/**
|
470 |
-
*
|
471 |
-
* @param type $option
|
472 |
-
* @param type $val
|
473 |
-
* @return type
|
474 |
-
*/
|
475 |
-
protected function getPreviewValue($option, $val) {
|
476 |
-
switch($option) {
|
477 |
-
case 'frontend.teaser':
|
478 |
-
$str = wp_strip_all_tags($val);
|
479 |
-
if (function_exists('mb_strlen')) {
|
480 |
-
$preview = (mb_strlen($str) > 25 ? mb_substr($str, 0, 22) . '...' : $str);
|
481 |
-
} else {
|
482 |
-
$preview = (strlen($str) > 25 ? substr($str, 0, 22) . '...' : $str);
|
483 |
-
}
|
484 |
-
break;
|
485 |
-
|
486 |
-
case 'frontend.location':
|
487 |
-
if (!empty($val)) {
|
488 |
-
$chunks = explode('|', $val);
|
489 |
-
if ($chunks[0] === 'page') {
|
490 |
-
$preview = __('Existing Page', AAM_KEY);
|
491 |
-
} elseif ($chunks[0] === 'url') {
|
492 |
-
$preview = __('Valid URL', AAM_KEY);
|
493 |
-
} elseif ($chunks[0] === 'callback') {
|
494 |
-
$preview = __('Custom Callback', AAM_KEY);
|
495 |
-
} elseif ($chunks[0] === 'login') {
|
496 |
-
$preview = __('Redirect To Login Page', AAM_KEY);
|
497 |
-
}
|
498 |
-
}
|
499 |
-
break;
|
500 |
-
|
501 |
-
default:
|
502 |
-
$preview = apply_filters(
|
503 |
-
'aam-post-option-preview-filter', $val, $option
|
504 |
-
);
|
505 |
-
break;
|
506 |
-
}
|
507 |
-
|
508 |
-
return $preview;
|
509 |
-
}
|
510 |
-
|
511 |
-
/**
|
512 |
-
* Save post properties
|
513 |
-
*
|
514 |
-
* @return string
|
515 |
-
*
|
516 |
-
* @access public
|
517 |
-
*/
|
518 |
-
public function save() {
|
519 |
-
$subject = AAM_Backend_Subject::getInstance();
|
520 |
-
|
521 |
-
$object = trim(AAM_Core_Request::post('object'));
|
522 |
-
$id = AAM_Core_Request::post('objectId', null);
|
523 |
-
|
524 |
-
$param = AAM_Core_Request::post('param');
|
525 |
-
$value = filter_input(INPUT_POST, 'value');
|
526 |
-
|
527 |
-
$result = $subject->save($param, $value, $object, $id);
|
528 |
-
|
529 |
-
return wp_json_encode(array(
|
530 |
-
'status' => ($result ? 'success' : 'failure'),
|
531 |
-
'value' => $value,
|
532 |
-
'preview' => $this->getPreviewValue($param, $value)
|
533 |
-
));
|
534 |
-
}
|
535 |
-
|
536 |
-
/**
|
537 |
-
* Reset the object settings
|
538 |
-
*
|
539 |
-
* @return string
|
540 |
-
*
|
541 |
-
* @access public
|
542 |
-
*/
|
543 |
-
public function reset() {
|
544 |
-
$type = trim(AAM_Core_Request::post('type'));
|
545 |
-
$id = AAM_Core_Request::post('id', 0);
|
546 |
-
|
547 |
-
$object = AAM_Backend_Subject::getInstance()->getObject($type, $id);
|
548 |
-
if ($object instanceof AAM_Core_Object) {
|
549 |
-
$result = $object->reset();
|
550 |
-
} else {
|
551 |
-
$result = false;
|
552 |
-
}
|
553 |
-
|
554 |
-
return wp_json_encode(array('status' => ($result ? 'success' : 'failure')));
|
555 |
-
}
|
556 |
-
|
557 |
-
/**
|
558 |
-
* @inheritdoc
|
559 |
-
*/
|
560 |
-
public static function getTemplate() {
|
561 |
-
return 'main/post.phtml';
|
562 |
-
}
|
563 |
-
|
564 |
-
/**
|
565 |
-
*
|
566 |
-
* @param type $area
|
567 |
-
* @return type
|
568 |
-
*/
|
569 |
-
public static function getAccessOptionList($area) {
|
570 |
-
static $cache = null;
|
571 |
-
|
572 |
-
if (is_null($cache)) {
|
573 |
-
$cache = AAM_Backend_View_PostOptionList::get();
|
574 |
-
}
|
575 |
-
|
576 |
-
$subject = AAM_Backend_Subject::getInstance()->getUID();
|
577 |
-
$list = apply_filters(
|
578 |
-
'aam-post-access-options-filter', $cache[$area], $area
|
579 |
-
);
|
580 |
-
|
581 |
-
$filtered = array();
|
582 |
-
foreach($list as $option => $data) {
|
583 |
-
$add = empty($data['exclude']) || !in_array($subject, $data['exclude'], true);
|
584 |
-
|
585 |
-
if ($add) {
|
586 |
-
$add = empty($data['config']) || AAM_Core_Config::get($data['config'], true);
|
587 |
-
}
|
588 |
-
|
589 |
-
if ($add) {
|
590 |
-
$filtered[$option] = $data;
|
591 |
-
}
|
592 |
-
}
|
593 |
-
|
594 |
-
return $filtered;
|
595 |
-
}
|
596 |
-
|
597 |
-
/**
|
598 |
-
*
|
599 |
-
* @param type $renderBackButton
|
600 |
-
* @param type $extraClass
|
601 |
-
*/
|
602 |
-
public static function renderAccessForm() {
|
603 |
-
ob_start();
|
604 |
-
require_once AAM_BASEDIR . '/application/Backend/phtml/partial/post-access-form.phtml';
|
605 |
-
$content = ob_get_contents();
|
606 |
-
ob_end_clean();
|
607 |
-
|
608 |
-
return $content;
|
609 |
-
}
|
610 |
-
|
611 |
-
/**
|
612 |
-
*
|
613 |
-
* @return type
|
614 |
-
*/
|
615 |
-
public static function getCurrentObject() {
|
616 |
-
$object = (object) array(
|
617 |
-
'id' => urldecode(AAM_Core_Request::request('oid')),
|
618 |
-
'type' => AAM_Core_Request::request('otype')
|
619 |
-
);
|
620 |
-
|
621 |
-
if ($object->id) {
|
622 |
-
if (strpos($object->id, '|') !== false) { //term
|
623 |
-
$part = explode('|', $object->id);
|
624 |
-
$object->term = get_term($part[0], $part[1]);
|
625 |
-
} else {
|
626 |
-
$object->post = get_post($object->id);
|
627 |
-
}
|
628 |
-
}
|
629 |
-
|
630 |
-
return $object;
|
631 |
-
}
|
632 |
-
|
633 |
-
/**
|
634 |
-
* Register Posts & Pages feature
|
635 |
-
*
|
636 |
* @return void
|
637 |
-
*
|
638 |
* @access public
|
|
|
639 |
*/
|
640 |
-
public static function register()
|
|
|
641 |
AAM_Backend_Feature::registerFeature((object) array(
|
642 |
'uid' => 'post',
|
643 |
'position' => 20,
|
644 |
'title' => __('Posts & Terms', AAM_KEY),
|
645 |
-
'capability' =>
|
646 |
'type' => 'main',
|
647 |
'subjects' => array(
|
648 |
AAM_Core_Subject_Role::UID,
|
@@ -650,7 +996,6 @@ class AAM_Backend_Feature_Main_Post extends AAM_Backend_Feature_Abstract {
|
|
650 |
AAM_Core_Subject_Visitor::UID,
|
651 |
AAM_Core_Subject_Default::UID
|
652 |
),
|
653 |
-
'option' => 'core.settings.backendAccessControl,core.settings.frontendAccessControl,core.settings.apiAccessControl',
|
654 |
'view' => __CLASS__
|
655 |
));
|
656 |
}
|
5 |
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
* file 'license.txt', which is part of this source code package. *
|
7 |
* ======================================================================
|
8 |
+
*
|
9 |
+
* @version 6.0.0
|
10 |
*/
|
11 |
|
12 |
/**
|
13 |
+
* Backend posts & terms service UI
|
14 |
+
*
|
15 |
* @package AAM
|
16 |
+
* @version 6.0.0
|
17 |
*/
|
18 |
+
class AAM_Backend_Feature_Main_Post
|
19 |
+
extends AAM_Backend_Feature_Abstract implements AAM_Backend_Feature_ISubjectAware
|
20 |
+
{
|
21 |
+
|
22 |
+
use AAM_Core_Contract_ServiceTrait,
|
23 |
+
AAM_Core_Contract_RequestTrait;
|
24 |
+
|
25 |
+
/**
|
26 |
+
* Default access capability to the service
|
27 |
+
*
|
28 |
+
* @version 6.0.0
|
29 |
+
*/
|
30 |
+
const ACCESS_CAPABILITY = 'aam_manage_posts';
|
31 |
+
|
32 |
/**
|
33 |
+
* Type of AAM core object
|
34 |
+
*
|
35 |
+
* @version 6.0.0
|
36 |
*/
|
37 |
+
const OBJECT_TYPE = AAM_Core_Object_Post::OBJECT_TYPE;
|
38 |
+
|
39 |
+
/**
|
40 |
+
* HTML template to render
|
41 |
+
*
|
42 |
+
* @version 6.0.0
|
43 |
+
*/
|
44 |
+
const TEMPLATE = 'service/post.phtml';
|
45 |
+
|
46 |
+
/**
|
47 |
+
* Get posts & terms list
|
48 |
+
*
|
49 |
+
* @return string
|
50 |
+
*
|
51 |
+
* @access public
|
52 |
+
* @version 6.0.0
|
53 |
+
*/
|
54 |
+
public function getTable()
|
55 |
+
{
|
56 |
+
$id = $this->getFromPost('typeId');
|
57 |
+
|
58 |
+
switch($this->getFromPost('type')) {
|
59 |
+
case 'taxonomy':
|
60 |
+
$response = $this->retrieveTaxonomyTerms($id);
|
61 |
+
break;
|
62 |
+
|
63 |
+
case 'type':
|
64 |
+
$response = $this->retrievePostTypeObjects($id);
|
65 |
+
break;
|
66 |
+
|
67 |
+
default:
|
68 |
+
$response = $this->retrieveRootLevelList();
|
69 |
+
break;
|
70 |
}
|
71 |
+
|
72 |
+
// Extend the response with some required props and return JSON
|
73 |
+
// response.
|
74 |
+
$response['draw'] = AAM_Core_Request::request('draw');
|
75 |
+
|
76 |
+
return wp_json_encode($response);
|
77 |
}
|
78 |
+
|
79 |
/**
|
80 |
+
* Get access form with pre-populated data
|
81 |
+
*
|
82 |
+
* @param mixed $id
|
83 |
+
* @param string $type
|
84 |
+
*
|
85 |
* @return string
|
86 |
+
*
|
87 |
* @access public
|
88 |
+
* @version 6.0.0
|
89 |
*/
|
90 |
+
public function getAccessForm($id, $type)
|
91 |
+
{
|
92 |
+
$object = $this->getSubject()->getObject($type, $id);
|
93 |
+
$view = AAM_Backend_View::getInstance();
|
94 |
+
$args = array(
|
95 |
+
'object' => $object,
|
96 |
+
'type' => $type,
|
97 |
+
'id' => $id,
|
98 |
+
'subject' => $this->getSubject(),
|
99 |
+
'httpCodes' => $this->getRedirectHttpCodes(),
|
100 |
+
'previews' => $this->preparePreviewValues(
|
101 |
+
apply_filters(
|
102 |
+
'aam_post_preview_options_filter',
|
103 |
+
($object ? $object->getOption() : array()),
|
104 |
+
$object
|
105 |
+
)
|
106 |
+
)
|
107 |
+
);
|
108 |
|
109 |
+
// Prepare HTML response
|
110 |
+
switch ($type) {
|
111 |
+
case 'term':
|
112 |
+
$chunks = explode('|', $id);
|
113 |
+
$args['term'] = get_term($chunks[0], $chunks[1]);
|
114 |
+
$args['postType'] = (isset($chunks[2]) ? $chunks[2] : null);
|
115 |
+
|
116 |
+
$response = apply_filters(
|
117 |
+
'aam_term_access_form_filter',
|
118 |
+
$view->loadPartial('term-access-form', $args),
|
119 |
+
(object) $args
|
120 |
+
);
|
121 |
+
break;
|
122 |
+
|
123 |
+
case 'taxonomy':
|
124 |
+
$args['taxonomy'] = get_taxonomy($id);
|
125 |
+
|
126 |
+
$response = apply_filters(
|
127 |
+
'aam_taxonomy_access_form_filter',
|
128 |
+
$view->loadPartial('taxonomy-access-form', $args),
|
129 |
+
(object) $args
|
130 |
+
);
|
131 |
+
break;
|
132 |
+
|
133 |
+
case 'type':
|
134 |
+
$args['postType'] = get_post_type_object($id);
|
135 |
+
|
136 |
+
$response = apply_filters(
|
137 |
+
'aam_type_access_form_filter',
|
138 |
+
$view->loadPartial('type-access-form', $args),
|
139 |
+
(object) $args
|
140 |
+
);
|
141 |
+
break;
|
142 |
+
|
143 |
+
case 'post':
|
144 |
+
$args['postType'] = get_post_type_object($object->post_type);
|
145 |
+
$args['options'] = $this->getAccessOptionList();
|
146 |
+
|
147 |
+
$response = $view->loadPartial('post-access-form', $args);
|
148 |
+
break;
|
149 |
+
|
150 |
+
default:
|
151 |
+
$response = null;
|
152 |
+
break;
|
153 |
+
}
|
154 |
+
|
155 |
+
return $response;
|
156 |
+
}
|
157 |
+
|
158 |
+
/**
|
159 |
+
* Decorate additional view elements for access settings
|
160 |
+
*
|
161 |
+
* This method is necessary to prepare some preview information for access
|
162 |
+
* options like LIMIT or REDIRECT.
|
163 |
+
*
|
164 |
+
* @param array $options
|
165 |
+
*
|
166 |
+
* @return array
|
167 |
+
*
|
168 |
+
* @access protected
|
169 |
+
* @version 6.0.0
|
170 |
+
*/
|
171 |
+
protected function preparePreviewValues($options)
|
172 |
+
{
|
173 |
+
$previews = array();
|
174 |
+
|
175 |
+
foreach ($options as $option => $value) {
|
176 |
+
$previews[$option] = $this->getPreviewValue($option, $value);
|
177 |
}
|
178 |
|
179 |
+
return $previews;
|
180 |
}
|
181 |
+
|
182 |
+
/**
|
183 |
+
* Get post object access options
|
184 |
+
*
|
185 |
+
* @return array
|
186 |
+
*
|
187 |
+
* @access protected
|
188 |
+
* @version 6.0.0
|
189 |
+
*/
|
190 |
+
protected function getAccessOptionList()
|
191 |
+
{
|
192 |
+
$list = apply_filters(
|
193 |
+
'aam_post_access_options_filter', AAM_Backend_View_PostOptionList::get()
|
194 |
+
);
|
195 |
+
|
196 |
+
return array_filter($list, function ($opt) {
|
197 |
+
$type = $this->getSubject()->getSubjectType();
|
198 |
+
|
199 |
+
return empty($opt['exclude']) || !in_array($type, $opt['exclude'], true);
|
200 |
+
});
|
201 |
+
}
|
202 |
+
|
203 |
/**
|
204 |
+
* Get list of HTTP redirect types
|
205 |
+
*
|
206 |
* @return array
|
207 |
+
*
|
208 |
+
* @access protected
|
209 |
+
* @version 6.0.0
|
210 |
+
*/
|
211 |
+
protected function getRedirectHttpCodes()
|
212 |
+
{
|
213 |
+
return apply_filters('aam_content_redirect_http_codes', array(
|
214 |
+
'307' => __('307 - Temporary Redirect (Default)', AAM_KEY),
|
215 |
+
'301' => __('301 - Moved Permanently', AAM_KEY),
|
216 |
+
'303' => __('303 - See Other', AAM_KEY)
|
217 |
+
));
|
218 |
+
}
|
219 |
+
|
220 |
+
/**
|
221 |
+
* Prepare readable preview value
|
222 |
+
*
|
223 |
+
* @param string $option
|
224 |
+
* @param mixed $value
|
225 |
+
*
|
226 |
+
* @return string
|
227 |
+
*
|
228 |
+
* @access protected
|
229 |
+
* @version 6.0.0
|
230 |
+
*/
|
231 |
+
protected function getPreviewValue($option, $value)
|
232 |
+
{
|
233 |
+
switch ($option) {
|
234 |
+
case 'teaser':
|
235 |
+
$preview = $this->prepareTeaserPreview($value);
|
236 |
+
break;
|
237 |
+
|
238 |
+
case 'limited':
|
239 |
+
$preview = $this->prepareLimitedPreview($value);
|
240 |
+
break;
|
241 |
+
|
242 |
+
case 'redirected':
|
243 |
+
$preview = $this->prepareRedirectPreview($value);
|
244 |
+
break;
|
245 |
+
|
246 |
+
case 'protected':
|
247 |
+
$preview = $this->prepareProtectedPreview($value);
|
248 |
+
break;
|
249 |
+
|
250 |
+
case 'ceased':
|
251 |
+
$preview = $this->prepareCeasePreview($value);
|
252 |
+
break;
|
253 |
+
|
254 |
+
default:
|
255 |
+
$preview = apply_filters(
|
256 |
+
'aam_post_option_preview_filter',
|
257 |
+
'',
|
258 |
+
$value,
|
259 |
+
$option
|
260 |
+
);
|
261 |
+
break;
|
262 |
+
}
|
263 |
+
|
264 |
+
return $preview;
|
265 |
+
}
|
266 |
+
|
267 |
+
/**
|
268 |
+
* Prepare teaser message preview
|
269 |
+
*
|
270 |
+
* @param array $teaser
|
271 |
+
*
|
272 |
+
* @return string
|
273 |
+
*
|
274 |
+
* @access protected
|
275 |
+
* @version 6.0.0
|
276 |
+
*/
|
277 |
+
protected function prepareTeaserPreview($teaser)
|
278 |
+
{
|
279 |
+
$preview = null;
|
280 |
+
|
281 |
+
if (!empty($teaser['message'])) {
|
282 |
+
// Remove all HTML tags first
|
283 |
+
$str = wp_strip_all_tags($teaser['message']);
|
284 |
+
|
285 |
+
// Take in consideration UTF-8 encoding
|
286 |
+
if (function_exists('mb_strlen')) {
|
287 |
+
$preview = (mb_strlen($str) > 25 ? mb_substr($str, 0, 22) . '...' : $str);
|
288 |
+
} else {
|
289 |
+
$preview = (strlen($str) > 25 ? substr($str, 0, 22) . '...' : $str);
|
290 |
+
}
|
291 |
+
}
|
292 |
+
|
293 |
+
return $preview;
|
294 |
+
}
|
295 |
+
|
296 |
+
/**
|
297 |
+
* Prepare limited option preview
|
298 |
+
*
|
299 |
+
* @param array $limited
|
300 |
+
*
|
301 |
+
* @return string
|
302 |
+
*
|
303 |
+
* @access protected
|
304 |
+
* @version 6.0.0
|
305 |
+
*/
|
306 |
+
protected function prepareLimitedPreview($limited)
|
307 |
+
{
|
308 |
+
$preview = null;
|
309 |
+
|
310 |
+
if (!empty($limited['threshold'])) {
|
311 |
+
$preview = sprintf(__('%d times', AAM_KEY), $limited['threshold']);
|
312 |
+
}
|
313 |
+
|
314 |
+
return $preview;
|
315 |
+
}
|
316 |
+
|
317 |
+
/**
|
318 |
+
* Prepare redirect option preview
|
319 |
+
*
|
320 |
+
* @param array $redirect
|
321 |
+
*
|
322 |
+
* @return string
|
323 |
+
*
|
324 |
+
* @access protected
|
325 |
+
* @version 6.0.0
|
326 |
+
*/
|
327 |
+
protected function prepareRedirectPreview($redirect)
|
328 |
+
{
|
329 |
+
switch (isset($redirect['type']) ? $redirect['type'] : null) {
|
330 |
+
case 'page':
|
331 |
+
$page = get_post($redirect['destination']);
|
332 |
+
$preview = sprintf(
|
333 |
+
__('"%s" page', AAM_KEY),
|
334 |
+
(is_a($page, 'WP_Post') ? $page->post_title : '')
|
335 |
+
);
|
336 |
+
break;
|
337 |
+
|
338 |
+
case 'url':
|
339 |
+
$preview = sprintf(__('%s URL', AAM_KEY), $redirect['destination']);
|
340 |
+
break;
|
341 |
+
|
342 |
+
case 'login':
|
343 |
+
$preview = __('Login page', AAM_KEY);
|
344 |
+
break;
|
345 |
+
|
346 |
+
case 'callback':
|
347 |
+
$preview = $redirect['destination'];
|
348 |
+
break;
|
349 |
+
|
350 |
+
default:
|
351 |
+
$preview = null;
|
352 |
+
break;
|
353 |
+
}
|
354 |
+
|
355 |
+
return $preview;
|
356 |
+
}
|
357 |
+
|
358 |
+
/**
|
359 |
+
* Prepare password protected option preview
|
360 |
+
*
|
361 |
+
* @param array $protected
|
362 |
+
*
|
363 |
+
* @return string
|
364 |
+
*
|
365 |
* @access protected
|
366 |
+
* @version 6.0.0
|
367 |
*/
|
368 |
+
protected function prepareProtectedPreview($protected)
|
369 |
+
{
|
370 |
+
return AAM_Core_API::crypt($protected['password'], 'decrypt');
|
371 |
+
}
|
372 |
+
|
373 |
+
/**
|
374 |
+
* Prepare ceased option preview
|
375 |
+
*
|
376 |
+
* @param array $cease
|
377 |
+
*
|
378 |
+
* @return string
|
379 |
+
*
|
380 |
+
* @access protected
|
381 |
+
* @version 6.0.0
|
382 |
+
*/
|
383 |
+
protected function prepareCeasePreview($cease)
|
384 |
+
{
|
385 |
+
return (!empty($cease['after']) ? $cease['after'] : null);
|
386 |
+
}
|
387 |
+
|
388 |
+
/**
|
389 |
+
* Save Posts & Terms access properties
|
390 |
+
*
|
391 |
+
* @return string
|
392 |
+
*
|
393 |
+
* @access public
|
394 |
+
* @version 6.0.0
|
395 |
+
*/
|
396 |
+
public function save()
|
397 |
+
{
|
398 |
+
$type = $this->getFromPost('object');
|
399 |
+
$id = $this->getFromPost('objectId');
|
400 |
+
$param = $this->getFromPost('param');
|
401 |
+
$value = $this->sanitizeOption($param, AAM_Core_Request::post('value'));
|
402 |
+
|
403 |
+
$object = $this->getSubject()->getObject($type, $id, true);
|
404 |
+
$result = $object->updateOptionItem($param, $value)->save();
|
405 |
+
|
406 |
+
return wp_json_encode(array(
|
407 |
+
'status' => ($result ? 'success' : 'failure')
|
408 |
+
));
|
409 |
+
}
|
410 |
+
|
411 |
+
/**
|
412 |
+
* Reset the object access settings
|
413 |
+
*
|
414 |
+
* @return string
|
415 |
+
*
|
416 |
+
* @access public
|
417 |
+
* @version 6.0.0
|
418 |
+
*/
|
419 |
+
public function reset()
|
420 |
+
{
|
421 |
+
$type = $this->getFromPost('type');
|
422 |
+
$id = $this->getFromPost('id');
|
423 |
+
$result = $this->getSubject()->getObject($type, $id)->reset();
|
424 |
+
|
425 |
+
return wp_json_encode(array('status' => ($result ? 'success' : 'failure')));
|
426 |
+
}
|
427 |
+
|
428 |
+
/**
|
429 |
+
* Sanitize and normalize the access settings
|
430 |
+
*
|
431 |
+
* Depending on the type of access, normalize and sanitize the incoming data
|
432 |
+
*
|
433 |
+
* @param string $option
|
434 |
+
* @param mixed $value
|
435 |
+
*
|
436 |
+
* @return mixed
|
437 |
+
*
|
438 |
+
* @access protected
|
439 |
+
* @version 6.0.0
|
440 |
+
*/
|
441 |
+
protected function sanitizeOption($option, $value)
|
442 |
+
{
|
443 |
+
if ($option === 'protected') {
|
444 |
+
$value['password'] = AAM_Core_API::crypt($value['password']);
|
445 |
+
}
|
446 |
+
|
447 |
+
if (is_array($value)) {
|
448 |
+
$value['enabled'] = filter_var($value['enabled'], FILTER_VALIDATE_BOOLEAN);
|
449 |
+
} else { // Any scalar value has to be boolean
|
450 |
+
$value = filter_var($value, FILTER_VALIDATE_BOOLEAN);
|
451 |
+
}
|
452 |
+
|
453 |
+
return $value;
|
454 |
+
}
|
455 |
+
|
456 |
+
/**
|
457 |
+
* Check if post can be managed for current subject
|
458 |
+
*
|
459 |
+
* @return boolean
|
460 |
+
*
|
461 |
+
* @access protected
|
462 |
+
* @version 6.0.0
|
463 |
+
*/
|
464 |
+
protected function isAllowedToManageCurrentSubject()
|
465 |
+
{
|
466 |
+
return apply_filters(
|
467 |
+
'aam_posts_terms_manage_subject_filter',
|
468 |
+
!$this->getSubject()->isDefault(),
|
469 |
+
$this->getSubject()->getSubject()
|
470 |
+
);
|
471 |
+
}
|
472 |
+
|
473 |
+
/**
|
474 |
+
* Retrieve list of registered post types & taxonomies
|
475 |
+
*
|
476 |
+
* The Root level contains the list of all registered post types that are public
|
477 |
+
* as well as all the registered taxonomies
|
478 |
+
*
|
479 |
+
* @return array
|
480 |
+
*
|
481 |
+
* @access protected
|
482 |
+
* @version 6.0.0
|
483 |
+
*/
|
484 |
+
protected function retrieveRootLevelList()
|
485 |
+
{
|
486 |
+
$list = $this->prepareRootLevelList();
|
487 |
$response = array(
|
488 |
+
'data' => array(),
|
489 |
+
'recordsTotal' => $list->total,
|
490 |
'recordsFiltered' => $list->filtered
|
491 |
);
|
492 |
+
|
493 |
foreach ($list->records as $type) {
|
494 |
+
if (is_a($type, 'WP_Post_Type')) {
|
495 |
+
$response['data'][] = array(
|
496 |
+
$type->name,
|
497 |
+
null,
|
498 |
+
'type',
|
499 |
+
$type->labels->name,
|
500 |
+
'drilldown,manage',
|
501 |
+
null,
|
502 |
+
apply_filters(
|
503 |
+
'aam_type_settings_override_status_filter',
|
504 |
+
false,
|
505 |
+
$type->name,
|
506 |
+
$this->getSubject()
|
507 |
+
)
|
508 |
+
);
|
509 |
+
} elseif(is_a($type, 'WP_Taxonomy')) {
|
510 |
+
$response['data'][] = array(
|
511 |
+
$type->name,
|
512 |
+
null,
|
513 |
+
'taxonomy-' . ($type->hierarchical ? 'category' : 'tag'),
|
514 |
+
$type->labels->name,
|
515 |
+
'drilldown,manage',
|
516 |
+
null,
|
517 |
+
apply_filters(
|
518 |
+
'aam_taxonomy_settings_override_status_filter',
|
519 |
+
false,
|
520 |
+
$type->name,
|
521 |
+
$this->getSubject()
|
522 |
+
)
|
523 |
+
);
|
524 |
+
}
|
525 |
}
|
526 |
+
|
527 |
return $response;
|
528 |
}
|
529 |
+
|
530 |
/**
|
531 |
+
* Prepare the list of root level objects
|
532 |
+
*
|
533 |
+
* @return object
|
534 |
+
*
|
535 |
+
* @access protected
|
536 |
+
* @version 6.0.0
|
537 |
*/
|
538 |
+
protected function prepareRootLevelList()
|
539 |
+
{
|
540 |
+
$args = array('public' => true);
|
541 |
+
$list = array_merge(
|
542 |
+
get_post_types($args, 'objects'), // Get all registered post types
|
543 |
+
get_taxonomies($args, 'objects') // Get all registered taxonomies
|
544 |
+
);
|
545 |
+
|
546 |
$filtered = array();
|
547 |
+
|
548 |
+
// Apply filters
|
549 |
$s = AAM_Core_Request::post('search.value');
|
550 |
$length = AAM_Core_Request::post('length');
|
551 |
$start = AAM_Core_Request::post('start');
|
552 |
+
|
553 |
+
foreach ($list as $type) {
|
554 |
+
if (empty($s) || stripos($type->labels->name, $s) !== false) {
|
555 |
+
$filtered[get_class($type) . '_' . $type->name] = $type;
|
|
|
|
|
556 |
}
|
557 |
}
|
558 |
+
|
559 |
$this->getOrderDirection() === 'ASC' ? ksort($filtered) : krsort($filtered);
|
560 |
+
|
561 |
return (object) array(
|
562 |
'total' => count($list),
|
563 |
'filtered' => count($filtered),
|
564 |
'records' => array_slice($filtered, $start, $length)
|
565 |
);
|
566 |
}
|
567 |
+
|
568 |
+
/**
|
569 |
+
* Retrieve list of all terms that belong to specific taxonomy
|
570 |
+
*
|
571 |
+
* @param string $taxonomy
|
572 |
+
*
|
573 |
+
* @return array
|
574 |
+
*
|
575 |
+
* @access protected
|
576 |
+
* @version 6.0.0
|
577 |
+
*/
|
578 |
+
protected function retrieveTaxonomyTerms($taxonomy)
|
579 |
+
{
|
580 |
+
$list = $this->retrieveTermList(
|
581 |
+
$taxonomy,
|
582 |
+
AAM_Core_Request::post('search.value'),
|
583 |
+
$this->getFromPost('start'),
|
584 |
+
$this->getFromPost('length')
|
585 |
+
);
|
586 |
+
|
587 |
+
$countFiltered = get_terms(array(
|
588 |
+
'fields' => 'count',
|
589 |
+
'search' => AAM_Core_Request::post('search.value'),
|
590 |
+
'hide_empty' => false,
|
591 |
+
'suppress_filter' => true,
|
592 |
+
'taxonomy' => $taxonomy
|
593 |
+
));
|
594 |
+
$count = get_terms(array(
|
595 |
+
'fields' => 'count',
|
596 |
+
'hide_empty' => false,
|
597 |
+
'suppress_filter' => true,
|
598 |
+
'taxonomy' => $taxonomy
|
599 |
+
));
|
600 |
+
|
601 |
+
$response = array(
|
602 |
+
'data' => array(),
|
603 |
+
'recordsTotal' => $count,
|
604 |
+
'recordsFiltered' => $countFiltered
|
605 |
+
);
|
606 |
+
|
607 |
+
foreach ($list as $term) {
|
608 |
+
$response['data'][] = $this->_prepareTermRow($term);
|
609 |
+
}
|
610 |
+
|
611 |
+
return $response;
|
612 |
+
}
|
613 |
+
|
614 |
/**
|
615 |
+
* Get correct table order
|
616 |
+
*
|
617 |
+
* @return string
|
618 |
+
*
|
619 |
+
* @access protected
|
620 |
+
* @version 6.0.0
|
621 |
*/
|
622 |
+
protected function getOrderDirection()
|
623 |
+
{
|
624 |
$dir = 'asc';
|
625 |
$order = AAM_Core_Request::post('order.0');
|
626 |
+
|
627 |
if (!empty($order['column']) && ($order['column'] === '3')) {
|
628 |
$dir = !empty($order['dir']) ? $order['dir'] : 'asc';
|
629 |
}
|
630 |
+
|
631 |
return strtoupper($dir);
|
632 |
}
|
633 |
|
634 |
/**
|
|
|
|
|
635 |
* Retrieve list of all posts and terms that belong to specified post type
|
636 |
+
*
|
637 |
* @param string $type
|
638 |
+
*
|
639 |
* @return array
|
640 |
+
*
|
641 |
* @access protected
|
642 |
+
* @version 6.0.0
|
643 |
*/
|
644 |
+
protected function retrievePostTypeObjects($type)
|
645 |
+
{
|
646 |
+
$list = $this->preparePostTermList($type);
|
647 |
+
$subject = $this->getSubject();
|
648 |
$response = array(
|
649 |
+
'data' => array(),
|
650 |
+
'recordsTotal' => $list->total,
|
651 |
'recordsFiltered' => $list->filtered
|
652 |
);
|
653 |
+
|
654 |
+
foreach ($list->records as $record) {
|
655 |
+
if (isset($record->ID)) { // this is a post
|
656 |
$link = get_edit_post_link($record->ID, 'link');
|
657 |
+
|
658 |
$parent = '';
|
659 |
+
|
660 |
if (!empty($record->post_parent)) {
|
661 |
$p = get_post($record->post_parent);
|
662 |
$parent = (is_a($p, 'WP_Post') ? $p->post_title : '');
|
663 |
}
|
664 |
+
|
665 |
if (empty($parent)) {
|
666 |
$taxonomies = get_object_taxonomies($record);
|
667 |
|
668 |
if (!empty($taxonomies)) {
|
669 |
$terms = wp_get_object_terms(
|
670 |
+
$record->ID,
|
671 |
+
$taxonomies,
|
672 |
+
array('fields' => 'names', 'suppress_filter' => true)
|
673 |
);
|
674 |
$parent = implode(', ', $terms);
|
675 |
}
|
676 |
}
|
677 |
+
|
678 |
$response['data'][] = array(
|
679 |
$record->ID,
|
680 |
$link,
|
682 |
get_the_title($record),
|
683 |
'manage' . ($link ? ',edit' : ',no-edit'),
|
684 |
$parent,
|
685 |
+
$subject->getObject('post', $record->ID, true)->isOverwritten()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
686 |
);
|
687 |
+
} else { // this is a term
|
688 |
+
$response['data'][] = $this->_prepareTermRow($record, $type);
|
689 |
}
|
690 |
}
|
691 |
|
692 |
return $response;
|
693 |
}
|
694 |
+
|
695 |
/**
|
696 |
+
* Prepare the term row for the table view
|
697 |
+
*
|
698 |
+
* @param WP_Term $term
|
699 |
+
* @param string $type
|
700 |
+
*
|
701 |
+
* @return array
|
702 |
+
*
|
703 |
+
* @access private
|
704 |
+
* @version 6.0.0
|
705 |
*/
|
706 |
+
private function _prepareTermRow($term, $type = null)
|
707 |
+
{
|
708 |
+
// Prepare list of actions
|
709 |
+
$actions = apply_filters(
|
710 |
+
'aam_term_row_actions', array('manage', 'edit'), $this->getSubject(), $term
|
711 |
+
);
|
712 |
+
|
713 |
+
// Prepare row id
|
714 |
+
$id = $term->term_id . '|' . $term->taxonomy . ($type ? '|' . $type : '');
|
715 |
+
|
716 |
+
$is_cat = is_taxonomy_hierarchical($term->taxonomy);
|
717 |
+
$path = ($is_cat ? rtrim($this->getParentTermList($term), '/') : '');
|
718 |
+
|
719 |
+
return array(
|
720 |
+
$id,
|
721 |
+
get_edit_term_link($term->term_id, $term->taxonomy),
|
722 |
+
($is_cat ? 'cat' : 'tag'),
|
723 |
+
$term->name,
|
724 |
+
implode(',', $actions),
|
725 |
+
$path,
|
726 |
+
apply_filters(
|
727 |
+
'aam_term_settings_override_status_filter', false, $id, $this->getSubject()
|
728 |
+
)
|
729 |
+
);
|
730 |
+
}
|
731 |
+
|
732 |
+
/**
|
733 |
+
* Get list of parent terms
|
734 |
+
*
|
735 |
+
* @param WP_Term $term
|
736 |
+
*
|
737 |
+
* @return string
|
738 |
+
*
|
739 |
+
* @access protected
|
740 |
+
* @global string $wp_version
|
741 |
+
* @version 6.0.0
|
742 |
+
*/
|
743 |
+
protected function getParentTermList($term)
|
744 |
+
{
|
745 |
global $wp_version;
|
746 |
|
747 |
$list = '';
|
780 |
}
|
781 |
|
782 |
/**
|
783 |
+
* Prepare the list of posts and terms that are related to specific post type
|
784 |
*
|
785 |
* @param string $type
|
786 |
+
*
|
787 |
+
* @return array
|
788 |
+
*
|
789 |
+
* @access protected
|
790 |
+
* @version 6.0.0
|
791 |
*/
|
792 |
+
protected function preparePostTermList($type)
|
793 |
+
{
|
794 |
$list = array();
|
795 |
+
|
796 |
+
// Retrieve filters
|
797 |
$s = AAM_Core_Request::post('search.value');
|
798 |
$length = AAM_Core_Request::post('length');
|
799 |
$start = AAM_Core_Request::post('start');
|
800 |
+
|
801 |
+
// Calculate how many term and/or posts we need to fetch
|
802 |
$paging = $this->getFetchPagination($type, $s, $start, $length);
|
803 |
+
|
804 |
+
// First retrieve all terms that belong to Post Type
|
805 |
if ($paging['terms']) {
|
806 |
$list = $this->retrieveTermList(
|
807 |
+
get_object_taxonomies($type),
|
808 |
+
$s,
|
809 |
+
$paging['term_offset'],
|
810 |
$paging['terms']
|
811 |
);
|
812 |
}
|
813 |
+
|
814 |
+
// Retrieve all posts
|
815 |
if ($paging['posts']) {
|
816 |
$list = array_merge(
|
817 |
+
$list,
|
818 |
$this->retrievePostList(
|
819 |
+
$type,
|
820 |
+
$s,
|
821 |
+
$paging['post_offset'],
|
822 |
+
$paging['posts']
|
823 |
)
|
824 |
);
|
825 |
}
|
826 |
+
|
827 |
return (object) array(
|
828 |
'total' => $paging['total'],
|
829 |
'filtered' => $paging['total'],
|
830 |
'records' => $list
|
831 |
);
|
832 |
}
|
833 |
+
|
834 |
/**
|
835 |
+
* Compute information for the pagination
|
836 |
+
*
|
837 |
+
* @param string $type
|
838 |
+
* @param string $search
|
839 |
+
* @param int $offset
|
840 |
+
* @param int $limit
|
841 |
+
*
|
842 |
+
* @return array
|
843 |
+
*
|
844 |
+
* @access protected
|
845 |
+
* @version 6.0.0
|
846 |
*/
|
847 |
+
protected function getFetchPagination($type, $search, $offset, $limit)
|
848 |
+
{
|
849 |
$result = array('terms' => 0, 'posts' => 0, 'term_offset' => $offset);
|
850 |
+
|
851 |
//get terms count
|
852 |
$taxonomy = get_object_taxonomies($type);
|
853 |
+
|
854 |
if (!empty($taxonomy)) {
|
855 |
$terms = get_terms(array(
|
856 |
+
'fields' => 'count',
|
857 |
+
'search' => $search,
|
858 |
+
'hide_empty' => false,
|
859 |
+
'suppress_filter' => true,
|
860 |
+
'taxonomy' => $taxonomy
|
861 |
));
|
862 |
} else {
|
863 |
$terms = 0;
|
864 |
}
|
865 |
+
|
866 |
//get posts count
|
867 |
$posts = $this->getPostCount($type, $search);
|
868 |
+
|
869 |
if ($offset < $terms) {
|
870 |
if ($terms - $limit >= $offset) {
|
871 |
$result['terms'] = $limit;
|
876 |
} else {
|
877 |
$result['posts'] = $limit;
|
878 |
}
|
879 |
+
|
880 |
$result['total'] = $terms + $posts;
|
881 |
$result['post_offset'] = ($offset ? $offset - $terms : 0);
|
882 |
+
|
883 |
return $result;
|
884 |
}
|
885 |
+
|
886 |
/**
|
887 |
+
* Get list of posts
|
888 |
+
*
|
889 |
+
* Perform separate computation for the list of posts based on type and search
|
890 |
+
* criteria
|
891 |
+
*
|
892 |
+
* @param string $type
|
893 |
+
* @param string $search
|
894 |
+
*
|
895 |
+
* @return int
|
896 |
+
*
|
897 |
+
* @access protected
|
898 |
* @global type $wpdb
|
899 |
+
* @version 6.0.0
|
|
|
|
|
900 |
*/
|
901 |
+
protected function getPostCount($type, $search)
|
902 |
+
{
|
903 |
global $wpdb;
|
904 |
+
|
905 |
$query = "SELECT COUNT(*) AS total FROM {$wpdb->posts} ";
|
906 |
+
$query .= "WHERE (post_type = %s) AND (post_title LIKE %s || ";
|
907 |
+
$query .= "post_excerpt LIKE %s || post_content LIKE %s)";
|
908 |
+
|
909 |
+
$args = array($type, "%{$search}%", "%{$search}%", "%{$search}%");
|
910 |
+
|
911 |
+
foreach (get_post_stati(array('show_in_admin_all_list' => false)) as $status) {
|
912 |
$query .= " AND ({$wpdb->posts}.post_status <> %s)";
|
913 |
$args[] = $status;
|
914 |
}
|
915 |
+
|
916 |
return $wpdb->get_var($wpdb->prepare($query, $args));
|
917 |
}
|
918 |
+
|
919 |
/**
|
920 |
* Retrieve term list
|
921 |
+
*
|
922 |
+
* @param array $taxonomies
|
923 |
+
* @param string $search
|
924 |
+
* @param int $offset
|
925 |
+
* @param int $limit
|
926 |
+
*
|
927 |
* @return array
|
928 |
+
*
|
929 |
* @access protected
|
930 |
+
* @version 6.0.0
|
931 |
*/
|
932 |
+
protected function retrieveTermList($taxonomies, $search, $offset, $limit)
|
933 |
+
{
|
934 |
$args = array(
|
935 |
+
'fields' => 'all',
|
936 |
+
'hide_empty' => false,
|
937 |
+
'search' => $search,
|
938 |
+
'suppress_filter' => true,
|
939 |
+
'taxonomy' => $taxonomies,
|
940 |
+
'offset' => $offset,
|
941 |
+
'number' => $limit,
|
942 |
+
'order' => $this->getOrderDirection()
|
943 |
);
|
944 |
|
945 |
return get_terms($args);
|
946 |
}
|
947 |
+
|
948 |
/**
|
949 |
+
* Get list of posts for specific post type
|
950 |
+
*
|
951 |
* @param string $type
|
952 |
* @param string $search
|
953 |
* @param int $offset
|
954 |
* @param int $limit
|
955 |
+
*
|
956 |
* @return array
|
957 |
+
*
|
958 |
+
* @access protected
|
959 |
+
* @version 6.0.0
|
960 |
*/
|
961 |
+
protected function retrievePostList($type, $search, $offset, $limit)
|
962 |
+
{
|
963 |
return get_posts(array(
|
964 |
+
'post_type' => $type,
|
965 |
+
'category' => 0,
|
966 |
's' => $search,
|
967 |
'suppress_filters' => true,
|
968 |
'offset' => $offset,
|
969 |
'numberposts' => $limit,
|
970 |
'orderby' => 'title',
|
971 |
'order' => $this->getOrderDirection(),
|
972 |
+
'post_status' => 'any',
|
973 |
'fields' => 'all'
|
974 |
));
|
975 |
}
|
976 |
|
977 |
/**
|
978 |
+
* Register Posts & Pages service UI
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
979 |
*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
980 |
* @return void
|
981 |
+
*
|
982 |
* @access public
|
983 |
+
* @version 6.0.0
|
984 |
*/
|
985 |
+
public static function register()
|
986 |
+
{
|
987 |
AAM_Backend_Feature::registerFeature((object) array(
|
988 |
'uid' => 'post',
|
989 |
'position' => 20,
|
990 |
'title' => __('Posts & Terms', AAM_KEY),
|
991 |
+
'capability' => self::ACCESS_CAPABILITY,
|
992 |
'type' => 'main',
|
993 |
'subjects' => array(
|
994 |
AAM_Core_Subject_Role::UID,
|
996 |
AAM_Core_Subject_Visitor::UID,
|
997 |
AAM_Core_Subject_Default::UID
|
998 |
),
|
|
|
999 |
'view' => __CLASS__
|
1000 |
));
|
1001 |
}
|
application/Backend/Feature/Main/Redirect.php
CHANGED
@@ -5,127 +5,82 @@
|
|
5 |
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
* file 'license.txt', which is part of this source code package. *
|
7 |
* ======================================================================
|
|
|
|
|
8 |
*/
|
9 |
|
10 |
/**
|
11 |
-
* Redirect manager
|
12 |
-
*
|
13 |
* @package AAM
|
14 |
-
* @
|
15 |
*/
|
16 |
-
class AAM_Backend_Feature_Main_Redirect
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
*/
|
21 |
-
public function __construct() {
|
22 |
-
parent::__construct();
|
23 |
-
|
24 |
-
$allowed = AAM_Backend_Subject::getInstance()->isAllowedToManage();
|
25 |
-
if (!$allowed || !current_user_can('aam_manage_access_denied_redirect')) {
|
26 |
-
AAM::api()->denyAccess(array('reason' => 'aam_manage_access_denied_redirect'));
|
27 |
-
}
|
28 |
-
}
|
29 |
-
|
30 |
/**
|
31 |
-
*
|
32 |
*
|
33 |
-
* @
|
34 |
*/
|
35 |
-
|
36 |
-
$param = AAM_Core_Request::post('param');
|
37 |
-
$value = AAM_Core_Request::post('value');
|
38 |
-
|
39 |
-
$object = AAM_Backend_Subject::getInstance()->getObject('redirect');
|
40 |
|
41 |
-
$object->save($param, $value);
|
42 |
-
|
43 |
-
return wp_json_encode(array('status' => 'success'));
|
44 |
-
}
|
45 |
-
|
46 |
/**
|
47 |
-
*
|
48 |
-
*
|
49 |
-
|
50 |
-
public function reset() {
|
51 |
-
return AAM_Backend_Subject::getInstance()->resetObject('redirect');
|
52 |
-
}
|
53 |
-
|
54 |
-
/**
|
55 |
-
*
|
56 |
-
* @return type
|
57 |
-
*/
|
58 |
-
public function isDefault() {
|
59 |
-
$subject = AAM_Backend_Subject::getInstance();
|
60 |
-
|
61 |
-
return $subject->getUID() === AAM_Core_Subject_Default::UID;
|
62 |
-
}
|
63 |
-
|
64 |
-
/**
|
65 |
-
*
|
66 |
-
* @return type
|
67 |
*/
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
return $subject->getUID() === AAM_Core_Subject_Visitor::UID;
|
72 |
-
}
|
73 |
-
|
74 |
/**
|
75 |
-
*
|
76 |
-
*
|
77 |
-
*
|
78 |
-
*
|
79 |
-
* @return boolean
|
80 |
-
*
|
81 |
-
* @access protected
|
82 |
*/
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
return $object->isOverwritten();
|
87 |
-
}
|
88 |
-
|
89 |
/**
|
90 |
-
*
|
91 |
-
*
|
92 |
-
* @
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
*/
|
94 |
-
public function getOption($option, $default = null)
|
95 |
-
|
|
|
96 |
$value = $object->get($option);
|
97 |
-
|
98 |
return (!is_null($value) ? $value : $default);
|
99 |
}
|
100 |
-
|
101 |
-
/**
|
102 |
-
* @inheritdoc
|
103 |
-
*/
|
104 |
-
public static function getTemplate() {
|
105 |
-
return 'main/redirect.phtml';
|
106 |
-
}
|
107 |
-
|
108 |
/**
|
109 |
-
* Register
|
110 |
-
*
|
111 |
* @return void
|
112 |
-
*
|
113 |
* @access public
|
|
|
114 |
*/
|
115 |
-
public static function register()
|
|
|
116 |
AAM_Backend_Feature::registerFeature((object) array(
|
117 |
'uid' => 'redirect',
|
118 |
'position' => 30,
|
119 |
'title' => __('Access Denied Redirect', AAM_KEY),
|
120 |
-
'capability' =>
|
121 |
'type' => 'main',
|
122 |
'subjects' => array(
|
123 |
-
AAM_Core_Subject_Role::UID,
|
124 |
-
AAM_Core_Subject_User::UID,
|
125 |
AAM_Core_Subject_Visitor::UID,
|
126 |
AAM_Core_Subject_Default::UID
|
127 |
),
|
128 |
-
'option' => 'core.settings.backendAccessControl,core.settings.frontendAccessControl',
|
129 |
'view' => __CLASS__
|
130 |
));
|
131 |
}
|
5 |
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
* file 'license.txt', which is part of this source code package. *
|
7 |
* ======================================================================
|
8 |
+
*
|
9 |
+
* @version 6.0.0
|
10 |
*/
|
11 |
|
12 |
/**
|
13 |
+
* Access Denied Redirect manager
|
14 |
+
*
|
15 |
* @package AAM
|
16 |
+
* @version 6.0.0
|
17 |
*/
|
18 |
+
class AAM_Backend_Feature_Main_Redirect
|
19 |
+
extends AAM_Backend_Feature_Abstract implements AAM_Backend_Feature_ISubjectAware
|
20 |
+
{
|
21 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
/**
|
23 |
+
* Default access capability to the service
|
24 |
*
|
25 |
+
* @version 6.0.0
|
26 |
*/
|
27 |
+
const ACCESS_CAPABILITY = 'aam_manage_access_denied_redirect';
|
|
|
|
|
|
|
|
|
28 |
|
|
|
|
|
|
|
|
|
|
|
29 |
/**
|
30 |
+
* Type of AAM core object
|
31 |
+
*
|
32 |
+
* @version 6.0.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
*/
|
34 |
+
const OBJECT_TYPE = AAM_Core_Object_Redirect::OBJECT_TYPE;
|
35 |
+
|
|
|
|
|
|
|
|
|
36 |
/**
|
37 |
+
* HTML template to render
|
38 |
+
*
|
39 |
+
* @version 6.0.0
|
|
|
|
|
|
|
|
|
40 |
*/
|
41 |
+
const TEMPLATE = 'service/redirect.phtml';
|
42 |
+
|
|
|
|
|
|
|
|
|
43 |
/**
|
44 |
+
* Get access denied redirect option
|
45 |
+
*
|
46 |
+
* @param string $option
|
47 |
+
* @param mixed $default
|
48 |
+
*
|
49 |
+
* @return mixed
|
50 |
+
*
|
51 |
+
* @access public
|
52 |
+
* @version 6.0.0
|
53 |
*/
|
54 |
+
public function getOption($option, $default = null)
|
55 |
+
{
|
56 |
+
$object = AAM_Backend_Subject::getInstance()->getObject(self::OBJECT_TYPE);
|
57 |
$value = $object->get($option);
|
58 |
+
|
59 |
return (!is_null($value) ? $value : $default);
|
60 |
}
|
61 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
/**
|
63 |
+
* Register Access Denied Redirect UI feature
|
64 |
+
*
|
65 |
* @return void
|
66 |
+
*
|
67 |
* @access public
|
68 |
+
* @version 6.0.0
|
69 |
*/
|
70 |
+
public static function register()
|
71 |
+
{
|
72 |
AAM_Backend_Feature::registerFeature((object) array(
|
73 |
'uid' => 'redirect',
|
74 |
'position' => 30,
|
75 |
'title' => __('Access Denied Redirect', AAM_KEY),
|
76 |
+
'capability' => self::ACCESS_CAPABILITY,
|
77 |
'type' => 'main',
|
78 |
'subjects' => array(
|
79 |
+
AAM_Core_Subject_Role::UID,
|
80 |
+
AAM_Core_Subject_User::UID,
|
81 |
AAM_Core_Subject_Visitor::UID,
|
82 |
AAM_Core_Subject_Default::UID
|
83 |
),
|
|
|
84 |
'view' => __CLASS__
|
85 |
));
|
86 |
}
|
application/Backend/Feature/Main/Route.php
CHANGED
@@ -5,150 +5,125 @@
|
|
5 |
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
* file 'license.txt', which is part of this source code package. *
|
7 |
* ======================================================================
|
|
|
|
|
8 |
*/
|
9 |
|
10 |
/**
|
11 |
* WordPress API manager
|
12 |
-
*
|
13 |
* @package AAM
|
14 |
-
* @
|
15 |
*/
|
16 |
-
class AAM_Backend_Feature_Main_Route
|
17 |
-
|
18 |
-
|
19 |
-
* Construct
|
20 |
-
*/
|
21 |
-
public function __construct() {
|
22 |
-
parent::__construct();
|
23 |
-
|
24 |
-
$allowed = AAM_Backend_Subject::getInstance()->isAllowedToManage();
|
25 |
-
if (!$allowed || !current_user_can('aam_manage_api_routes')) {
|
26 |
-
AAM::api()->denyAccess(array('reason' => 'aam_manage_api_routes'));
|
27 |
-
}
|
28 |
-
}
|
29 |
-
|
30 |
-
/**
|
31 |
-
*
|
32 |
-
* @return type
|
33 |
-
*/
|
34 |
-
public function getTable() {
|
35 |
-
$response = array('data' => $this->retrieveAllRoutes());
|
36 |
|
37 |
-
|
38 |
-
}
|
39 |
|
40 |
/**
|
41 |
-
*
|
42 |
-
*
|
|
|
43 |
*/
|
44 |
-
|
45 |
-
$type = filter_input(INPUT_POST, 'type');
|
46 |
-
$route = filter_input(INPUT_POST, 'route');
|
47 |
-
$method = filter_input(INPUT_POST, 'method');
|
48 |
-
$value = filter_input(INPUT_POST, 'value');
|
49 |
-
|
50 |
-
$object = AAM_Backend_Subject::getInstance()->getObject('route');
|
51 |
-
|
52 |
-
$object->save($type, $route, $method, $value);
|
53 |
|
54 |
-
return wp_json_encode(array('status' => 'success'));
|
55 |
-
}
|
56 |
-
|
57 |
/**
|
58 |
-
*
|
59 |
-
*
|
|
|
60 |
*/
|
61 |
-
|
62 |
-
return AAM_Backend_Subject::getInstance()->resetObject('route');
|
63 |
-
}
|
64 |
|
65 |
/**
|
66 |
-
*
|
|
|
|
|
67 |
*/
|
68 |
-
|
69 |
-
|
70 |
-
}
|
71 |
-
|
72 |
/**
|
73 |
-
*
|
74 |
-
*
|
|
|
|
|
|
|
|
|
75 |
*/
|
76 |
-
|
77 |
-
|
78 |
-
$
|
79 |
-
|
80 |
-
|
|
|
81 |
if (AAM::api()->getConfig('core.settings.restful', true)) {
|
82 |
foreach (rest_get_server()->get_routes() as $route => $handlers) {
|
83 |
$methods = array();
|
84 |
-
foreach($handlers as $handler) {
|
85 |
$methods = array_merge($methods, array_keys($handler['methods']));
|
86 |
}
|
87 |
|
88 |
-
foreach(array_unique($methods) as $method) {
|
89 |
-
$
|
|
|
90 |
$route,
|
91 |
'restful',
|
92 |
$method,
|
93 |
htmlspecialchars($route),
|
94 |
-
$
|
95 |
);
|
96 |
}
|
97 |
}
|
98 |
}
|
99 |
-
|
100 |
-
|
101 |
-
if (AAM::api()->getConfig('core.settings.xmlrpc', true)) {
|
102 |
-
foreach(array_keys(AAM_Core_API::getXMLRPCServer()->methods) as $route) {
|
103 |
-
$response[] = array(
|
104 |
-
$route,
|
105 |
-
'xmlrpc',
|
106 |
-
'POST',
|
107 |
-
htmlspecialchars($route),
|
108 |
-
$object->has('xmlrpc', $route) ? 'checked' : 'unchecked'
|
109 |
-
);
|
110 |
-
}
|
111 |
-
}
|
112 |
-
|
113 |
-
return $response;
|
114 |
}
|
115 |
|
116 |
/**
|
117 |
-
*
|
118 |
-
*
|
119 |
-
*
|
120 |
-
*
|
121 |
-
* @
|
122 |
-
*
|
123 |
-
* @access protected
|
124 |
*/
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
129 |
}
|
130 |
|
131 |
/**
|
132 |
-
* Register
|
133 |
-
*
|
134 |
* @return void
|
135 |
-
*
|
136 |
* @access public
|
|
|
137 |
*/
|
138 |
-
public static function register()
|
139 |
-
|
|
|
140 |
'uid' => 'route',
|
141 |
'position' => 50,
|
142 |
'title' => __('API Routes', AAM_KEY),
|
143 |
-
'capability' =>
|
144 |
'type' => 'main',
|
145 |
'subjects' => array(
|
146 |
-
AAM_Core_Subject_Role::UID,
|
147 |
AAM_Core_Subject_User::UID,
|
148 |
AAM_Core_Subject_Visitor::UID,
|
149 |
AAM_Core_Subject_Default::UID
|
150 |
),
|
151 |
-
'option' => 'core.settings.apiAccessControl',
|
152 |
'view' => __CLASS__
|
153 |
));
|
154 |
}
|
5 |
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
* file 'license.txt', which is part of this source code package. *
|
7 |
* ======================================================================
|
8 |
+
*
|
9 |
+
* @version 6.0.0
|
10 |
*/
|
11 |
|
12 |
/**
|
13 |
* WordPress API manager
|
14 |
+
*
|
15 |
* @package AAM
|
16 |
+
* @version 6.0.0
|
17 |
*/
|
18 |
+
class AAM_Backend_Feature_Main_Route
|
19 |
+
extends AAM_Backend_Feature_Abstract implements AAM_Backend_Feature_ISubjectAware
|
20 |
+
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
+
use AAM_Core_Contract_RequestTrait;
|
|
|
23 |
|
24 |
/**
|
25 |
+
* Default access capability to the service
|
26 |
+
*
|
27 |
+
* @version 6.0.0
|
28 |
*/
|
29 |
+
const ACCESS_CAPABILITY = 'aam_manage_api_routes';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
|
|
|
|
|
|
31 |
/**
|
32 |
+
* Type of AAM core object
|
33 |
+
*
|
34 |
+
* @version 6.0.0
|
35 |
*/
|
36 |
+
const OBJECT_TYPE = AAM_Core_Object_Route::OBJECT_TYPE;
|
|
|
|
|
37 |
|
38 |
/**
|
39 |
+
* HTML template to render
|
40 |
+
*
|
41 |
+
* @version 6.0.0
|
42 |
*/
|
43 |
+
const TEMPLATE = 'service/route.phtml';
|
44 |
+
|
|
|
|
|
45 |
/**
|
46 |
+
* Get list of API routes
|
47 |
+
*
|
48 |
+
* @return string
|
49 |
+
*
|
50 |
+
* @access public
|
51 |
+
* @version 6.0.0
|
52 |
*/
|
53 |
+
public function getTable()
|
54 |
+
{
|
55 |
+
$list = array();
|
56 |
+
$object = AAM_Backend_Subject::getInstance()->getObject(self::OBJECT_TYPE);
|
57 |
+
|
58 |
+
// Build all RESTful routes
|
59 |
if (AAM::api()->getConfig('core.settings.restful', true)) {
|
60 |
foreach (rest_get_server()->get_routes() as $route => $handlers) {
|
61 |
$methods = array();
|
62 |
+
foreach ($handlers as $handler) {
|
63 |
$methods = array_merge($methods, array_keys($handler['methods']));
|
64 |
}
|
65 |
|
66 |
+
foreach (array_unique($methods) as $method) {
|
67 |
+
$isRestricted = $object->isRestricted('restful', $route, $method);
|
68 |
+
$list[] = array(
|
69 |
$route,
|
70 |
'restful',
|
71 |
$method,
|
72 |
htmlspecialchars($route),
|
73 |
+
$isRestricted ? 'checked' : 'unchecked'
|
74 |
);
|
75 |
}
|
76 |
}
|
77 |
}
|
78 |
+
|
79 |
+
return wp_json_encode(array('data' => $list));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
}
|
81 |
|
82 |
/**
|
83 |
+
* Save route access settings
|
84 |
+
*
|
85 |
+
* @return string
|
86 |
+
*
|
87 |
+
* @access public
|
88 |
+
* @version 6.0.0
|
|
|
89 |
*/
|
90 |
+
public function save()
|
91 |
+
{
|
92 |
+
$type = $this->getFromPost('type');
|
93 |
+
$route = $this->getFromPost('route');
|
94 |
+
$method = $this->getFromPost('method');
|
95 |
+
$value = $this->getFromPost('value');
|
96 |
+
|
97 |
+
$object = AAM_Backend_Subject::getInstance()->getObject(self::OBJECT_TYPE);
|
98 |
+
$id = strtolower("{$type}|{$route}|{$method}");
|
99 |
+
|
100 |
+
$result = $object->updateOptionItem($id, $value)->save();
|
101 |
+
|
102 |
+
return wp_json_encode(array('status' => ($result ? 'success' : 'failure')));
|
103 |
}
|
104 |
|
105 |
/**
|
106 |
+
* Register API Routes service
|
107 |
+
*
|
108 |
* @return void
|
109 |
+
*
|
110 |
* @access public
|
111 |
+
* @version 6.0.0
|
112 |
*/
|
113 |
+
public static function register()
|
114 |
+
{
|
115 |
+
AAM_Backend_Feature::registerFeature((object)array(
|
116 |
'uid' => 'route',
|
117 |
'position' => 50,
|
118 |
'title' => __('API Routes', AAM_KEY),
|
119 |
+
'capability' => self::ACCESS_CAPABILITY,
|
120 |
'type' => 'main',
|
121 |
'subjects' => array(
|
122 |
+
AAM_Core_Subject_Role::UID,
|
123 |
AAM_Core_Subject_User::UID,
|
124 |
AAM_Core_Subject_Visitor::UID,
|
125 |
AAM_Core_Subject_Default::UID
|
126 |
),
|
|
|
127 |
'view' => __CLASS__
|
128 |
));
|
129 |
}
|
application/Backend/Feature/Main/Toolbar.php
CHANGED
@@ -5,150 +5,146 @@
|
|
5 |
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
* file 'license.txt', which is part of this source code package. *
|
7 |
* ======================================================================
|
|
|
|
|
8 |
*/
|
9 |
|
10 |
/**
|
11 |
-
*
|
12 |
-
*
|
13 |
* @package AAM
|
14 |
-
* @
|
15 |
*/
|
16 |
-
class AAM_Backend_Feature_Main_Toolbar
|
17 |
-
|
|
|
|
|
|
|
|
|
18 |
/**
|
19 |
-
*
|
|
|
|
|
20 |
*/
|
21 |
-
|
22 |
-
parent::__construct();
|
23 |
-
|
24 |
-
$allowed = AAM_Backend_Subject::getInstance()->isAllowedToManage();
|
25 |
-
if (!$allowed || !current_user_can('aam_manage_admin_toolbar')) {
|
26 |
-
AAM::api()->denyAccess(array('reason' => 'aam_manage_admin_toolbar'));
|
27 |
-
}
|
28 |
-
}
|
29 |
|
30 |
/**
|
31 |
-
*
|
32 |
*
|
33 |
-
* @
|
34 |
*/
|
35 |
-
|
36 |
-
$items = AAM_Core_Request::post('items', array());
|
37 |
-
$status = AAM_Core_Request::post('status');
|
38 |
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
$object->save();
|
46 |
|
47 |
-
return wp_json_encode(array('status' => 'success'));
|
48 |
-
}
|
49 |
-
|
50 |
/**
|
51 |
-
*
|
52 |
-
*
|
|
|
|
|
|
|
|
|
53 |
*/
|
54 |
-
public function
|
55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
}
|
57 |
|
58 |
/**
|
59 |
-
* Get
|
60 |
-
*
|
61 |
-
* Based on the list of capabilities that current subject has, prepare
|
62 |
-
* complete menu list and return it.
|
63 |
-
*
|
64 |
* @return array
|
65 |
-
*
|
66 |
* @access public
|
67 |
-
* @
|
68 |
*/
|
69 |
-
public function getToolbar()
|
70 |
-
|
|
|
71 |
}
|
72 |
-
|
73 |
/**
|
74 |
-
*
|
75 |
-
*
|
76 |
-
* @
|
|
|
|
|
|
|
|
|
|
|
77 |
*/
|
78 |
-
public function getAllChildren($branch)
|
|
|
79 |
$children = array();
|
80 |
-
|
81 |
-
|
82 |
-
|
|
|
83 |
$children[] = $child;
|
84 |
}
|
85 |
-
if(!empty($child->children)) {
|
86 |
$children = array_merge($children, $this->getAllChildren($child));
|
87 |
}
|
88 |
}
|
89 |
-
|
90 |
return $children;
|
91 |
}
|
92 |
-
|
93 |
-
/**
|
94 |
-
*
|
95 |
-
* @param type $node
|
96 |
-
* @return type
|
97 |
-
*/
|
98 |
-
public function normalizeTitle($node) {
|
99 |
-
return ucwords(
|
100 |
-
trim(
|
101 |
-
preg_replace(
|
102 |
-
'/[\d]/',
|
103 |
-
'',
|
104 |
-
wp_strip_all_tags(!empty($node->title) ? $node->title : $node->id)
|
105 |
-
)
|
106 |
-
)
|
107 |
-
);
|
108 |
-
}
|
109 |
-
|
110 |
-
/**
|
111 |
-
* @inheritdoc
|
112 |
-
*/
|
113 |
-
public static function getTemplate() {
|
114 |
-
return 'main/toolbar.phtml';
|
115 |
-
}
|
116 |
|
117 |
/**
|
118 |
-
*
|
119 |
-
*
|
120 |
-
*
|
121 |
-
*
|
122 |
-
* @return
|
123 |
-
*
|
124 |
* @access protected
|
|
|
125 |
*/
|
126 |
-
protected function
|
127 |
-
|
128 |
-
|
129 |
-
|
|
|
130 |
}
|
131 |
|
132 |
/**
|
133 |
* Register Menu feature
|
134 |
-
*
|
135 |
* @return void
|
136 |
-
*
|
137 |
* @access public
|
|
|
138 |
*/
|
139 |
-
public static function register()
|
|
|
140 |
AAM_Backend_Feature::registerFeature((object) array(
|
141 |
'uid' => 'toolbar',
|
142 |
'position' => 6,
|
143 |
'title' => __('Admin Toolbar', AAM_KEY),
|
144 |
-
'capability' =>
|
145 |
'type' => 'main',
|
146 |
'subjects' => array(
|
147 |
-
AAM_Core_Subject_Role::UID,
|
148 |
AAM_Core_Subject_User::UID,
|
149 |
AAM_Core_Subject_Default::UID
|
150 |
),
|
151 |
-
'option' => 'core.settings.backendAccessControl,core.settings.frontendAccessControl',
|
152 |
'view' => __CLASS__
|
153 |
));
|
154 |
}
|
5 |
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
* file 'license.txt', which is part of this source code package. *
|
7 |
* ======================================================================
|
8 |
+
*
|
9 |
+
* @version 6.0.0
|
10 |
*/
|
11 |
|
12 |
/**
|
13 |
+
* Admin toolbar manager
|
14 |
+
*
|
15 |
* @package AAM
|
16 |
+
* @version 6.0.0
|
17 |
*/
|
18 |
+
class AAM_Backend_Feature_Main_Toolbar
|
19 |
+
extends AAM_Backend_Feature_Abstract implements AAM_Backend_Feature_ISubjectAware
|
20 |
+
{
|
21 |
+
|
22 |
+
use AAM_Core_Contract_RequestTrait;
|
23 |
+
|
24 |
/**
|
25 |
+
* Default access capability to the service
|
26 |
+
*
|
27 |
+
* @version 6.0.0
|
28 |
*/
|
29 |
+
const ACCESS_CAPABILITY = 'aam_manage_admin_toolbar';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
/**
|
32 |
+
* Type of AAM core object
|
33 |
*
|
34 |
+
* @version 6.0.0
|
35 |
*/
|
36 |
+
const OBJECT_TYPE = AAM_Core_Object_Toolbar::OBJECT_TYPE;
|
|
|
|
|
37 |
|
38 |
+
/**
|
39 |
+
* HTML template to render
|
40 |
+
*
|
41 |
+
* @version 6.0.0
|
42 |
+
*/
|
43 |
+
const TEMPLATE = 'service/toolbar.phtml';
|
|
|
44 |
|
|
|
|
|
|
|
45 |
/**
|
46 |
+
* Save toolbar settings
|
47 |
+
*
|
48 |
+
* @return string
|
49 |
+
*
|
50 |
+
* @access public
|
51 |
+
* @version 6.0.0
|
52 |
*/
|
53 |
+
public function save()
|
54 |
+
{
|
55 |
+
$status = $this->getFromPost('status');
|
56 |
+
$items = $this->getFromPost('items', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
|
57 |
+
|
58 |
+
$subject = AAM_Backend_Subject::getInstance();
|
59 |
+
$object = $subject->getObject(self::OBJECT_TYPE, null, true);
|
60 |
+
|
61 |
+
foreach ($items as $item) {
|
62 |
+
$object->updateOptionItem($item, !empty($status));
|
63 |
+
}
|
64 |
+
|
65 |
+
return wp_json_encode(
|
66 |
+
array('status' => ($object->save() ? 'success' : 'failure'))
|
67 |
+
);
|
68 |
}
|
69 |
|
70 |
/**
|
71 |
+
* Get toolbar
|
72 |
+
*
|
|
|
|
|
|
|
73 |
* @return array
|
74 |
+
*
|
75 |
* @access public
|
76 |
+
* @version 6.0.0
|
77 |
*/
|
78 |
+
public function getToolbar()
|
79 |
+
{
|
80 |
+
return AAM_Service_Toolbar::getInstance()->getToolbarCache();
|
81 |
}
|
82 |
+
|
83 |
/**
|
84 |
+
* Get list of child items
|
85 |
+
*
|
86 |
+
* @param object $branch
|
87 |
+
*
|
88 |
+
* @return array
|
89 |
+
*
|
90 |
+
* @access public
|
91 |
+
* @version 6.0.0
|
92 |
*/
|
93 |
+
public function getAllChildren($branch)
|
94 |
+
{
|
95 |
$children = array();
|
96 |
+
$types = array('container', 'group');
|
97 |
+
|
98 |
+
foreach ($branch->children as $child) {
|
99 |
+
if (empty($child->type) || !in_array($child->type, $types, true)) {
|
100 |
$children[] = $child;
|
101 |
}
|
102 |
+
if (!empty($child->children)) {
|
103 |
$children = array_merge($children, $this->getAllChildren($child));
|
104 |
}
|
105 |
}
|
106 |
+
|
107 |
return $children;
|
108 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
|
110 |
/**
|
111 |
+
* Normalize the item title
|
112 |
+
*
|
113 |
+
* @param object $node
|
114 |
+
*
|
115 |
+
* @return string
|
116 |
+
*
|
117 |
* @access protected
|
118 |
+
* @version 6.0.0
|
119 |
*/
|
120 |
+
protected function normalizeTitle($node)
|
121 |
+
{
|
122 |
+
$title = wp_strip_all_tags(!empty($node->title) ? $node->title : $node->id);
|
123 |
+
|
124 |
+
return ucwords(trim(preg_replace('/[\d]/', '', $title)));
|
125 |
}
|
126 |
|
127 |
/**
|
128 |
* Register Menu feature
|
129 |
+
*
|
130 |
* @return void
|
131 |
+
*
|
132 |
* @access public
|
133 |
+
* @version 6.0.0
|
134 |
*/
|
135 |
+
public static function register()
|
136 |
+
{
|
137 |
AAM_Backend_Feature::registerFeature((object) array(
|
138 |
'uid' => 'toolbar',
|
139 |
'position' => 6,
|
140 |
'title' => __('Admin Toolbar', AAM_KEY),
|
141 |
+
'capability' => self::ACCESS_CAPABILITY,
|
142 |
'type' => 'main',
|
143 |
'subjects' => array(
|
144 |
+
AAM_Core_Subject_Role::UID,
|
145 |
AAM_Core_Subject_User::UID,
|
146 |
AAM_Core_Subject_Default::UID
|
147 |
),
|
|
|
148 |
'view' => __CLASS__
|
149 |
));
|
150 |
}
|
application/Backend/Feature/Main/Uri.php
CHANGED
@@ -5,111 +5,62 @@
|
|
5 |
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
* file 'license.txt', which is part of this source code package. *
|
7 |
* ======================================================================
|
|
|
|
|
8 |
*/
|
9 |
|
10 |
/**
|
11 |
-
*
|
12 |
-
*
|
13 |
* @package AAM
|
14 |
-
* @
|
15 |
*/
|
16 |
-
class AAM_Backend_Feature_Main_Uri
|
17 |
-
|
18 |
-
|
19 |
-
* Construct
|
20 |
-
*/
|
21 |
-
public function __construct() {
|
22 |
-
parent::__construct();
|
23 |
-
|
24 |
-
$allowed = AAM_Backend_Subject::getInstance()->isAllowedToManage();
|
25 |
-
if (!$allowed || !current_user_can('aam_manage_uri')) {
|
26 |
-
AAM::api()->denyAccess(array('reason' => 'aam_manage_uri'));
|
27 |
-
}
|
28 |
-
}
|
29 |
-
|
30 |
-
/**
|
31 |
-
*
|
32 |
-
* @return type
|
33 |
-
*/
|
34 |
-
public function getTable() {
|
35 |
-
return wp_json_encode($this->retrieveAllRules());
|
36 |
-
}
|
37 |
|
38 |
/**
|
39 |
-
*
|
40 |
-
*
|
41 |
-
|
42 |
-
public function save() {
|
43 |
-
$uri = filter_input(INPUT_POST, 'uri');
|
44 |
-
$id = filter_input(INPUT_POST, 'id');
|
45 |
-
$type = filter_input(INPUT_POST, 'type');
|
46 |
-
$value = filter_input(INPUT_POST, 'value');
|
47 |
-
$code = filter_input(INPUT_POST, 'code');
|
48 |
-
|
49 |
-
$object = AAM_Backend_Subject::getInstance()->getObject('uri');
|
50 |
-
|
51 |
-
if (empty($id)) {
|
52 |
-
$id = uniqid();
|
53 |
-
}
|
54 |
-
|
55 |
-
$object->save($id, str_replace(site_url(), '', $uri), $type, $value, $code);
|
56 |
-
|
57 |
-
return wp_json_encode(array('status' => 'success'));
|
58 |
-
}
|
59 |
-
|
60 |
-
/**
|
61 |
-
*
|
62 |
-
* @return type
|
63 |
*/
|
64 |
-
|
65 |
-
|
66 |
-
}
|
67 |
-
|
68 |
/**
|
69 |
-
*
|
70 |
-
*
|
|
|
71 |
*/
|
72 |
-
|
73 |
-
$id = filter_input(INPUT_POST, 'id');
|
74 |
-
$object = AAM_Backend_Subject::getInstance()->getObject('uri');
|
75 |
-
|
76 |
-
$object->delete($id);
|
77 |
-
|
78 |
-
return wp_json_encode(array('status' => 'success'));
|
79 |
-
}
|
80 |
|
81 |
/**
|
82 |
-
*
|
|
|
|
|
83 |
*/
|
84 |
-
|
85 |
-
|
86 |
-
}
|
87 |
-
|
88 |
/**
|
89 |
-
*
|
90 |
-
*
|
|
|
|
|
|
|
|
|
91 |
*/
|
92 |
-
public function
|
|
|
93 |
$subject = AAM_Backend_Subject::getInstance();
|
94 |
-
|
95 |
-
|
96 |
-
}
|
97 |
-
|
98 |
-
/**
|
99 |
-
*
|
100 |
-
* @return type
|
101 |
-
*/
|
102 |
-
protected function retrieveAllRules() {
|
103 |
-
$rules = AAM_Backend_Subject::getInstance()->getObject('uri')->getOption();
|
104 |
-
|
105 |
$response = array(
|
106 |
'recordsTotal' => count($rules),
|
107 |
'recordsFiltered' => count($rules),
|
108 |
'draw' => AAM_Core_Request::request('draw'),
|
109 |
'data' => array(),
|
110 |
);
|
111 |
-
|
112 |
-
foreach($rules as $id => $rule) {
|
113 |
$response['data'][] = array(
|
114 |
$id,
|
115 |
$rule['uri'],
|
@@ -119,46 +70,83 @@ class AAM_Backend_Feature_Main_Uri extends AAM_Backend_Feature_Abstract {
|
|
119 |
'edit,delete'
|
120 |
);
|
121 |
}
|
122 |
-
|
123 |
-
return $response;
|
124 |
}
|
125 |
|
126 |
/**
|
127 |
-
*
|
128 |
-
*
|
129 |
-
*
|
130 |
-
*
|
131 |
-
* @
|
132 |
-
*
|
133 |
-
* @access protected
|
134 |
*/
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
139 |
}
|
140 |
|
141 |
/**
|
142 |
-
* Register
|
143 |
-
*
|
144 |
* @return void
|
145 |
-
*
|
146 |
* @access public
|
|
|
147 |
*/
|
148 |
-
public static function register()
|
|
|
149 |
AAM_Backend_Feature::registerFeature((object) array(
|
150 |
'uid' => 'uri',
|
151 |
'position' => 55,
|
152 |
'title' => __('URI Access', AAM_KEY),
|
153 |
-
'capability' =>
|
154 |
'type' => 'main',
|
155 |
'subjects' => array(
|
156 |
-
AAM_Core_Subject_Role::UID,
|
157 |
AAM_Core_Subject_User::UID,
|
158 |
AAM_Core_Subject_Visitor::UID,
|
159 |
AAM_Core_Subject_Default::UID
|
160 |
),
|
161 |
-
'option' => 'core.settings.backendAccessControl,core.settings.frontendAccessControl',
|
162 |
'view' => __CLASS__
|
163 |
));
|
164 |
}
|
5 |
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
* file 'license.txt', which is part of this source code package. *
|
7 |
* ======================================================================
|
8 |
+
*
|
9 |
+
* @version 6.0.0
|
10 |
*/
|
11 |
|
12 |
/**
|
13 |
+
* URI service
|
14 |
+
*
|
15 |
* @package AAM
|
16 |
+
* @version 6.0.0
|
17 |
*/
|
18 |
+
class AAM_Backend_Feature_Main_Uri
|
19 |
+
extends AAM_Backend_Feature_Abstract implements AAM_Backend_Feature_ISubjectAware
|
20 |
+
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
/**
|
23 |
+
* Default access capability to the feature
|
24 |
+
*
|
25 |
+
* @version 6.0.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
*/
|
27 |
+
const ACCESS_CAPABILITY = 'aam_manage_uri';
|
28 |
+
|
|
|
|
|
29 |
/**
|
30 |
+
* Type of AAM core object
|
31 |
+
*
|
32 |
+
* @version 6.0.0
|
33 |
*/
|
34 |
+
const OBJECT_TYPE = AAM_Core_Object_Uri::OBJECT_TYPE;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
/**
|
37 |
+
* HTML template to render
|
38 |
+
*
|
39 |
+
* @version 6.0.0
|
40 |
*/
|
41 |
+
const TEMPLATE = 'service/uri.phtml';
|
42 |
+
|
|
|
|
|
43 |
/**
|
44 |
+
* Get list of all rules
|
45 |
+
*
|
46 |
+
* @return string
|
47 |
+
*
|
48 |
+
* @access public
|
49 |
+
* @version 6.0.0
|
50 |
*/
|
51 |
+
public function getTable()
|
52 |
+
{
|
53 |
$subject = AAM_Backend_Subject::getInstance();
|
54 |
+
$rules = $subject->getObject(self::OBJECT_TYPE)->getOption();
|
55 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
$response = array(
|
57 |
'recordsTotal' => count($rules),
|
58 |
'recordsFiltered' => count($rules),
|
59 |
'draw' => AAM_Core_Request::request('draw'),
|
60 |
'data' => array(),
|
61 |
);
|
62 |
+
|
63 |
+
foreach ($rules as $id => $rule) {
|
64 |
$response['data'][] = array(
|
65 |
$id,
|
66 |
$rule['uri'],
|
70 |
'edit,delete'
|
71 |
);
|
72 |
}
|
73 |
+
|
74 |
+
return wp_json_encode($response);
|
75 |
}
|
76 |
|
77 |
/**
|
78 |
+
* Save URI access rule
|
79 |
+
*
|
80 |
+
* @return string
|
81 |
+
*
|
82 |
+
* @access public
|
83 |
+
* @version 6.0.0
|
|
|
84 |
*/
|
85 |
+
public function save()
|
86 |
+
{
|
87 |
+
$uri = filter_input(INPUT_POST, 'uri');
|
88 |
+
$id = filter_input(INPUT_POST, 'id');
|
89 |
+
$type = filter_input(INPUT_POST, 'type');
|
90 |
+
$value = filter_input(INPUT_POST, 'value');
|
91 |
+
$code = filter_input(INPUT_POST, 'code');
|
92 |
+
|
93 |
+
$object = AAM_Backend_Subject::getInstance()->getObject(self::OBJECT_TYPE);
|
94 |
+
|
95 |
+
// If ID is not specified, then we are creating a new rule
|
96 |
+
if (empty($id)) {
|
97 |
+
$id = uniqid();
|
98 |
+
}
|
99 |
+
|
100 |
+
$object->updateOptionItem($id, array(
|
101 |
+
'uri' => str_replace(site_url(), '', $uri),
|
102 |
+
'type' => $type,
|
103 |
+
'action' => $value,
|
104 |
+
'code' => $code
|
105 |
+
))->save();
|
106 |
+
|
107 |
+
return wp_json_encode(array('status' => 'success'));
|
108 |
+
}
|
109 |
+
|
110 |
+
/**
|
111 |
+
* Delete URI access rule
|
112 |
+
*
|
113 |
+
* @return string
|
114 |
+
*
|
115 |
+
* @access public
|
116 |
+
* @version 6.0.0
|
117 |
+
*/
|
118 |
+
public function delete()
|
119 |
+
{
|
120 |
+
$id = filter_input(INPUT_POST, 'id');
|
121 |
+
$object = AAM_Backend_Subject::getInstance()->getObject(self::OBJECT_TYPE);
|
122 |
+
|
123 |
+
return wp_json_encode(
|
124 |
+
array('status' => ($object->delete($id) ? 'success' : 'failure'))
|
125 |
+
);
|
126 |
}
|
127 |
|
128 |
/**
|
129 |
+
* Register service UI
|
130 |
+
*
|
131 |
* @return void
|
132 |
+
*
|
133 |
* @access public
|
134 |
+
* @version 6.0.0
|
135 |
*/
|
136 |
+
public static function register()
|
137 |
+
{
|
138 |
AAM_Backend_Feature::registerFeature((object) array(
|
139 |
'uid' => 'uri',
|
140 |
'position' => 55,
|
141 |
'title' => __('URI Access', AAM_KEY),
|
142 |
+
'capability' => self::ACCESS_CAPABILITY,
|
143 |
'type' => 'main',
|
144 |
'subjects' => array(
|
145 |
+
AAM_Core_Subject_Role::UID,
|
146 |
AAM_Core_Subject_User::UID,
|
147 |
AAM_Core_Subject_Visitor::UID,
|
148 |
AAM_Core_Subject_Default::UID
|
149 |
),
|
|
|
150 |
'view' => __CLASS__
|
151 |
));
|
152 |
}
|
application/Backend/Feature/Main/{GetStarted.php → Welcome.php}
RENAMED
@@ -5,35 +5,40 @@
|
|
5 |
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
* file 'license.txt', which is part of this source code package. *
|
7 |
* ======================================================================
|
|
|
|
|
8 |
*/
|
9 |
|
10 |
/**
|
11 |
-
*
|
12 |
-
*
|
13 |
* @package AAM
|
14 |
-
* @
|
15 |
*/
|
16 |
-
class
|
17 |
-
|
|
|
18 |
/**
|
19 |
-
*
|
|
|
|
|
20 |
*/
|
21 |
-
|
22 |
-
|
23 |
-
}
|
24 |
-
|
25 |
/**
|
26 |
-
* Register
|
27 |
-
*
|
28 |
* @return void
|
29 |
-
*
|
30 |
* @access public
|
|
|
31 |
*/
|
32 |
-
public static function register()
|
|
|
33 |
AAM_Backend_Feature::registerFeature((object) array(
|
34 |
-
'uid' => '
|
35 |
'position' => 1,
|
36 |
-
'title' => __('
|
37 |
'type' => 'main',
|
38 |
'subjects' => array(
|
39 |
AAM_Core_Subject_Default::UID,
|
@@ -41,7 +46,6 @@ class AAM_Backend_Feature_Main_GetStarted extends AAM_Backend_Feature_Abstract
|
|
41 |
AAM_Core_Subject_User::UID,
|
42 |
AAM_Core_Subject_Visitor::UID
|
43 |
),
|
44 |
-
'option' => 'core.settings.getStarted',
|
45 |
'view' => __CLASS__
|
46 |
));
|
47 |
}
|
5 |
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
* file 'license.txt', which is part of this source code package. *
|
7 |
* ======================================================================
|
8 |
+
*
|
9 |
+
* @version 6.0.0
|
10 |
*/
|
11 |
|
12 |
/**
|
13 |
+
* AAM Welcome backend service
|
14 |
+
*
|
15 |
* @package AAM
|
16 |
+
* @version 6.0.0
|
17 |
*/
|
18 |
+
class AAM_Backend_Feature_Main_Welcome extends AAM_Backend_Feature_Abstract
|
19 |
+
{
|
20 |
+
|
21 |
/**
|
22 |
+
* HTML template to render
|
23 |
+
*
|
24 |
+
* @version 6.0.0
|
25 |
*/
|
26 |
+
const TEMPLATE = 'service/welcome.phtml';
|
27 |
+
|
|
|
|
|
28 |
/**
|
29 |
+
* Register welcome service
|
30 |
+
*
|
31 |
* @return void
|
32 |
+
*
|
33 |
* @access public
|
34 |
+
* @version 6.0.0
|
35 |
*/
|
36 |
+
public static function register()
|
37 |
+
{
|
38 |
AAM_Backend_Feature::registerFeature((object) array(
|
39 |
+
'uid' => 'welcome',
|
40 |
'position' => 1,
|
41 |
+
'title' => __('Welcome', AAM_KEY),
|
42 |
'type' => 'main',
|
43 |
'subjects' => array(
|
44 |
AAM_Core_Subject_Default::UID,
|
46 |
AAM_Core_Subject_User::UID,
|
47 |
AAM_Core_Subject_Visitor::UID
|
48 |
),
|
|
|
49 |
'view' => __CLASS__
|
50 |
));
|
51 |
}
|
application/Backend/Feature/Settings/ConfigPress.php
CHANGED
@@ -5,71 +5,69 @@
|
|
5 |
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
* file 'license.txt', which is part of this source code package. *
|
7 |
* ======================================================================
|
|
|
|
|
8 |
*/
|
9 |
|
10 |
/**
|
11 |
-
* Backend ConfigPress
|
12 |
-
*
|
13 |
* @package AAM
|
14 |
-
* @
|
15 |
*/
|
16 |
-
class AAM_Backend_Feature_Settings_ConfigPress extends AAM_Backend_Feature_Abstract
|
17 |
-
|
|
|
|
|
|
|
18 |
/**
|
19 |
-
*
|
|
|
|
|
20 |
*/
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
if (!current_user_can('aam_manage_settings')) {
|
25 |
-
AAM::api()->denyAccess(array('reason' => 'aam_manage_settings'));
|
26 |
-
}
|
27 |
-
}
|
28 |
-
|
29 |
/**
|
30 |
-
*
|
|
|
|
|
31 |
*/
|
32 |
-
|
33 |
-
|
34 |
-
}
|
35 |
-
|
36 |
/**
|
37 |
* Save config
|
38 |
-
*
|
39 |
* @return boolean
|
40 |
-
*
|
41 |
* @access protected
|
|
|
42 |
*/
|
43 |
-
public function save()
|
44 |
-
|
45 |
-
$config =
|
46 |
-
|
47 |
-
//
|
48 |
$data = str_replace(array('“', '”'), '"', $config);
|
49 |
-
|
50 |
-
return
|
51 |
}
|
52 |
-
|
53 |
/**
|
54 |
-
* Register
|
55 |
-
*
|
56 |
* @return void
|
57 |
-
*
|
58 |
* @access public
|
|
|
59 |
*/
|
60 |
-
public static function register()
|
|
|
61 |
AAM_Backend_Feature::registerFeature((object) array(
|
62 |
'uid' => 'configpress',
|
63 |
'position' => 90,
|
64 |
'title' => __('ConfigPress', AAM_KEY),
|
65 |
-
'capability' =>
|
66 |
'type' => 'settings',
|
67 |
-
'subjects' => array(
|
68 |
-
AAM_Core_Subject_Role::UID,
|
69 |
-
AAM_Core_Subject_User::UID,
|
70 |
-
AAM_Core_Subject_Visitor::UID,
|
71 |
-
AAM_Core_Subject_Default::UID
|
72 |
-
),
|
73 |
'view' => __CLASS__
|
74 |
));
|
75 |
}
|
5 |
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
* file 'license.txt', which is part of this source code package. *
|
7 |
* ======================================================================
|
8 |
+
*
|
9 |
+
* @version 6.0.0
|
10 |
*/
|
11 |
|
12 |
/**
|
13 |
+
* Backend ConfigPress tab
|
14 |
+
*
|
15 |
* @package AAM
|
16 |
+
* @version 6.0.0
|
17 |
*/
|
18 |
+
class AAM_Backend_Feature_Settings_ConfigPress extends AAM_Backend_Feature_Abstract
|
19 |
+
{
|
20 |
+
|
21 |
+
use AAM_Core_Contract_RequestTrait;
|
22 |
+
|
23 |
/**
|
24 |
+
* Default access capability to the settings
|
25 |
+
*
|
26 |
+
* @version 6.0.0
|
27 |
*/
|
28 |
+
const ACCESS_CAPABILITY = 'aam_manage_settings';
|
29 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
/**
|
31 |
+
* HTML template to render
|
32 |
+
*
|
33 |
+
* @version 6.0.0
|
34 |
*/
|
35 |
+
const TEMPLATE = 'settings/configpress.phtml';
|
36 |
+
|
|
|
|
|
37 |
/**
|
38 |
* Save config
|
39 |
+
*
|
40 |
* @return boolean
|
41 |
+
*
|
42 |
* @access protected
|
43 |
+
* @version 6.0.0
|
44 |
*/
|
45 |
+
public function save()
|
46 |
+
{
|
47 |
+
$config = $this->getFromPost('config');
|
48 |
+
|
49 |
+
// Normalize ConfigPress settings
|
50 |
$data = str_replace(array('“', '”'), '"', $config);
|
51 |
+
|
52 |
+
return AAM_Core_ConfigPress::getInstance()->save($data);
|
53 |
}
|
54 |
+
|
55 |
/**
|
56 |
+
* Register service UI
|
57 |
+
*
|
58 |
* @return void
|
59 |
+
*
|
60 |
* @access public
|
61 |
+
* @version 6.0.0
|
62 |
*/
|
63 |
+
public static function register()
|
64 |
+
{
|
65 |
AAM_Backend_Feature::registerFeature((object) array(
|
66 |
'uid' => 'configpress',
|
67 |
'position' => 90,
|
68 |
'title' => __('ConfigPress', AAM_KEY),
|
69 |
+
'capability' => self::ACCESS_CAPABILITY,
|
70 |
'type' => 'settings',
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
'view' => __CLASS__
|
72 |
));
|
73 |
}
|
application/Backend/Feature/Settings/Content.php
CHANGED
@@ -5,68 +5,61 @@
|
|
5 |
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
* file 'license.txt', which is part of this source code package. *
|
7 |
* ======================================================================
|
|
|
|
|
8 |
*/
|
9 |
|
10 |
/**
|
11 |
* Backend content settings
|
12 |
-
*
|
13 |
* @package AAM
|
14 |
-
* @
|
15 |
*/
|
16 |
-
class AAM_Backend_Feature_Settings_Content extends AAM_Backend_Feature_Abstract
|
17 |
-
|
|
|
18 |
/**
|
19 |
-
*
|
|
|
|
|
20 |
*/
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
if (!current_user_can('aam_manage_settings')) {
|
25 |
-
AAM::api()->denyAccess(array('reason' => 'aam_manage_settings'));
|
26 |
-
}
|
27 |
-
}
|
28 |
-
|
29 |
/**
|
30 |
-
*
|
|
|
|
|
31 |
*/
|
32 |
-
|
33 |
-
|
34 |
-
}
|
35 |
-
|
36 |
/**
|
37 |
-
*
|
38 |
-
*
|
|
|
|
|
|
|
|
|
39 |
*/
|
40 |
-
protected function getList()
|
41 |
-
|
42 |
-
|
43 |
-
'title' => __('Media Files Access Control', AAM_KEY),
|
44 |
-
'descr' => sprintf(AAM_Backend_View_Helper::preparePhrase('Allow AAM to manage a physically access to all media files located in the defined by the system [uploads] folder. [Note!] This feature requires additional steps as described in %sthis article%s.', 'strong', 'strong'), '<a href="https://aamplugin.com/article/how-to-manage-wordpress-media-access" target="_blank">', '</a>'),
|
45 |
-
'value' => AAM_Core_Config::get('core.settings.mediaAccessControl', false)
|
46 |
-
),
|
47 |
-
'core.settings.manageHiddenPostTypes' => array(
|
48 |
-
'title' => __('Manage Hidden Post Types', AAM_KEY),
|
49 |
-
'descr' => __('By default AAM allows you to manage access only to public post types on Posts & Terms tab. By enabling this feature, you also will be able to manage access to hidden post types like revisions, navigation menus or any other custom post types that are not registered as public.', AAM_KEY),
|
50 |
-
'value' => AAM_Core_Config::get('core.settings.manageHiddenPostTypes', false)
|
51 |
-
)
|
52 |
-
);
|
53 |
-
|
54 |
-
return apply_filters('aam-settings-filter', $settings, 'post');
|
55 |
}
|
56 |
-
|
57 |
/**
|
58 |
-
* Register
|
59 |
-
*
|
60 |
* @return void
|
61 |
-
*
|
62 |
* @access public
|
|
|
63 |
*/
|
64 |
-
public static function register()
|
65 |
-
|
|
|
66 |
'uid' => 'settings-content',
|
67 |
'position' => 5,
|
68 |
'title' => __('Content Settings', AAM_KEY),
|
69 |
-
'capability' =>
|
70 |
'type' => 'settings',
|
71 |
'view' => __CLASS__
|
72 |
));
|
5 |
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
* file 'license.txt', which is part of this source code package. *
|
7 |
* ======================================================================
|
8 |
+
*
|
9 |
+
* @version 6.0.0
|
10 |
*/
|
11 |
|
12 |
/**
|
13 |
* Backend content settings
|
14 |
+
*
|
15 |
* @package AAM
|
16 |
+
* @version 6.0.0
|
17 |
*/
|
18 |
+
class AAM_Backend_Feature_Settings_Content extends AAM_Backend_Feature_Abstract
|
19 |
+
{
|
20 |
+
|
21 |
/**
|
22 |
+
* Default access capability to the collection of settings
|
23 |
+
*
|
24 |
+
* @version 6.0.0
|
25 |
*/
|
26 |
+
const ACCESS_CAPABILITY = 'aam_manage_settings';
|
27 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
/**
|
29 |
+
* HTML template to render
|
30 |
+
*
|
31 |
+
* @version 6.0.0
|
32 |
*/
|
33 |
+
const TEMPLATE = 'settings/content.phtml';
|
34 |
+
|
|
|
|
|
35 |
/**
|
36 |
+
* Get list of content options
|
37 |
+
*
|
38 |
+
* @return array
|
39 |
+
*
|
40 |
+
* @access protected
|
41 |
+
* @version 6.0.0
|
42 |
*/
|
43 |
+
protected function getList()
|
44 |
+
{
|
45 |
+
return apply_filters('aam_settings_list_filter', array(), 'content');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
}
|
47 |
+
|
48 |
/**
|
49 |
+
* Register service UI
|
50 |
+
*
|
51 |
* @return void
|
52 |
+
*
|
53 |
* @access public
|
54 |
+
* @version 6.0.0
|
55 |
*/
|
56 |
+
public static function register()
|
57 |
+
{
|
58 |
+
AAM_Backend_Feature::registerFeature((object)array(
|
59 |
'uid' => 'settings-content',
|
60 |
'position' => 5,
|
61 |
'title' => __('Content Settings', AAM_KEY),
|
62 |
+
'capability' => self::ACCESS_CAPABILITY,
|
63 |
'type' => 'settings',
|
64 |
'view' => __CLASS__
|
65 |
));
|
application/Backend/Feature/Settings/Core.php
CHANGED
@@ -5,128 +5,79 @@
|
|
5 |
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
* file 'license.txt', which is part of this source code package. *
|
7 |
* ======================================================================
|
|
|
|
|
8 |
*/
|
9 |
|
10 |
/**
|
11 |
* Backend core settings
|
12 |
-
*
|
13 |
* @package AAM
|
14 |
-
* @
|
15 |
*/
|
16 |
-
class AAM_Backend_Feature_Settings_Core extends AAM_Backend_Feature_Abstract
|
17 |
-
|
|
|
18 |
/**
|
19 |
-
*
|
|
|
|
|
20 |
*/
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
if (!current_user_can('aam_manage_settings')) {
|
25 |
-
AAM::api()->denyAccess(array('reason' => 'aam_manage_settings'));
|
26 |
-
}
|
27 |
-
}
|
28 |
-
|
29 |
/**
|
30 |
-
*
|
|
|
|
|
31 |
*/
|
32 |
-
|
33 |
-
|
34 |
-
}
|
35 |
-
|
36 |
/**
|
37 |
-
*
|
38 |
-
*
|
|
|
|
|
|
|
|
|
39 |
*/
|
40 |
-
protected function getList()
|
|
|
41 |
$settings = array(
|
42 |
-
'core.settings.getStarted' => array(
|
43 |
-
'title' => __('Get Started Tab', AAM_KEY),
|
44 |
-
'descr' => __('Display the "Get Started" feature on the Main panel. You can disable this feature to remove the extra tab when you get familiar with core access control concepts.', AAM_KEY),
|
45 |
-
'value' => AAM_Core_Config::get('core.settings.getStarted', true)
|
46 |
-
),
|
47 |
'core.settings.editCapabilities' => array(
|
48 |
-
'title'
|
49 |
-
'
|
50 |
-
'value'
|
51 |
-
),
|
52 |
-
'core.settings.backendAccessControl' => array(
|
53 |
-
'title' => __('Backend Access Control', AAM_KEY),
|
54 |
-
'descr' => __('Allow AAM to manage access to the backend. Keep this option disabled if there is no needs to restrict backend features for other users.', AAM_KEY),
|
55 |
-
'value' => AAM_Core_Config::get('core.settings.backendAccessControl', true)
|
56 |
-
),
|
57 |
-
'core.settings.frontendAccessControl' => array(
|
58 |
-
'title' => __('Frontend Access Control', AAM_KEY),
|
59 |
-
'descr' => __('Allow AAM to manage access to the frontend. Keep this option disabled if there is no needs to restrict frontend resources for users and visitors.', AAM_KEY),
|
60 |
-
'value' => AAM_Core_Config::get('core.settings.frontendAccessControl', true)
|
61 |
-
),
|
62 |
-
'core.settings.apiAccessControl' => array(
|
63 |
-
'title' => __('API Access Control', AAM_KEY),
|
64 |
-
'descr' => __('Allow AAM to manage access to the website resources that are invoked with WordPress core APIs. Keep this option disabled if there is no needs to restrict API access.', AAM_KEY),
|
65 |
-
'value' => AAM_Core_Config::get('core.settings.apiAccessControl', true)
|
66 |
),
|
67 |
'ui.settings.renderAccessMetabox' => array(
|
68 |
-
'title'
|
69 |
-
'
|
70 |
-
'value'
|
71 |
-
),
|
72 |
-
'ui.settings.renderAccessActionLink' => array(
|
73 |
-
'title' => __('Render Access Link', AAM_KEY),
|
74 |
-
'descr' => __('Render Access shortcut link under any post, page, custom post type, category, custom taxonomy title or user name.', AAM_KEY),
|
75 |
-
'value' => AAM_Core_Config::get('ui.settings.renderAccessActionLink', true),
|
76 |
-
),
|
77 |
-
'core.settings.secureLogin' => array(
|
78 |
-
'title' => __('Secure Login', AAM_KEY),
|
79 |
-
'descr' => __('AAM comes with its own user login handler. With this feature you can add AJAX login widget to your frontend page that significantly enhance your website security.', AAM_KEY),
|
80 |
-
'value' => AAM_Core_Config::get('core.settings.secureLogin', true)
|
81 |
-
),
|
82 |
-
'core.settings.xmlrpc' => array(
|
83 |
-
'title' => __('XML-RPC WordPress API', AAM_KEY),
|
84 |
-
'descr' => sprintf(AAM_Backend_View_Helper::preparePhrase('Remote procedure call (RPC) interface is used to manage WordPress website content and features. For more information check %sXML-RPC Support%s article.', 'b'), '<a href="https://codex.wordpress.org/XML-RPC_Support">', '</a>'),
|
85 |
-
'value' => AAM_Core_Config::get('core.settings.xmlrpc', true)
|
86 |
-
),
|
87 |
-
'core.settings.restful' => array(
|
88 |
-
'title' => __('RESTful WordPress API', AAM_KEY),
|
89 |
-
'descr' => sprintf(AAM_Backend_View_Helper::preparePhrase('RESTful interface that is used to manage WordPress website content and features. For more information check %sREST API handbook%s.', 'b'), '<a href="https://developer.wordpress.org/rest-api/">', '</a>'),
|
90 |
-
'value' => AAM_Core_Config::get('core.settings.restful', true)
|
91 |
-
),
|
92 |
-
'core.settings.jwtAuthentication' => array(
|
93 |
-
'title' => __('JWT Authentication', AAM_KEY),
|
94 |
-
'descr' => sprintf(AAM_Backend_View_Helper::preparePhrase('[Note!] PHP 5.4 or higher is required for this feature. Enable the ability to authenticate user with WordPress RESTful API and JWT token. For more information, check %sHow to authenticate WordPress user with JWT token%s article', 'b'), '<a href="https://aamplugin.com/article/how-to-authenticate-wordpress-user-with-jwt-token">', '</a>'),
|
95 |
-
'value' => AAM_Core_Config::get('core.settings.jwtAuthentication', true)
|
96 |
),
|
97 |
'core.settings.multiSubject' => array(
|
98 |
-
'title'
|
99 |
-
'
|
100 |
-
'value'
|
101 |
-
),
|
102 |
-
'core.settings.extensionSupport' => array(
|
103 |
-
'title' => __('Support AAM Extensions', AAM_KEY),
|
104 |
-
'descr' => __('AAM comes with the limited list of premium and free extensions that significantly enhance AAM behavior. You can disable support for AAM extension and any already installed extension will no longer be loaded during the website execution as well as website administrator will not be able to install new extensions.', AAM_KEY),
|
105 |
-
'value' => AAM_Core_Config::get('core.settings.extensionSupport', true)
|
106 |
-
),
|
107 |
-
'core.settings.cron' => array(
|
108 |
-
'title' => __('AAM Cron Job', AAM_KEY),
|
109 |
-
'descr' => __('AAM cron job executes periodically (typically once a day) to check for available updates for already installed extensions. Cron job is not executed if there are no installed extensions.', AAM_KEY),
|
110 |
-
'value' => AAM_Core_Config::get('core.settings.cron', true)
|
111 |
)
|
112 |
);
|
113 |
-
|
114 |
-
return apply_filters('
|
115 |
}
|
116 |
-
|
117 |
/**
|
118 |
-
* Register
|
119 |
-
*
|
120 |
* @return void
|
121 |
-
*
|
122 |
* @access public
|
|
|
123 |
*/
|
124 |
-
public static function register()
|
125 |
-
|
|
|
126 |
'uid' => 'settings-core',
|
127 |
-
'position' =>
|
128 |
'title' => __('Core Settings', AAM_KEY),
|
129 |
-
'capability' =>
|
130 |
'type' => 'settings',
|
131 |
'view' => __CLASS__
|
132 |
));
|
5 |
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
* file 'license.txt', which is part of this source code package. *
|
7 |
* ======================================================================
|
8 |
+
*
|
9 |
+
* @version 6.0.0
|
10 |
*/
|
11 |
|
12 |
/**
|
13 |
* Backend core settings
|
14 |
+
*
|
15 |
* @package AAM
|
16 |
+
* @version 6.0.0
|
17 |
*/
|
18 |
+
class AAM_Backend_Feature_Settings_Core extends AAM_Backend_Feature_Abstract
|
19 |
+
{
|
20 |
+
|
21 |
/**
|
22 |
+
* Default access capability to the collection of settings
|
23 |
+
*
|
24 |
+
* @version 6.0.0
|
25 |
*/
|
26 |
+
const ACCESS_CAPABILITY = 'aam_manage_settings';
|
27 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
/**
|
29 |
+
* HTML template to render
|
30 |
+
*
|
31 |
+
* @version 6.0.0
|
32 |
*/
|
33 |
+
const TEMPLATE = 'settings/core.phtml';
|
34 |
+
|
|
|
|
|
35 |
/**
|
36 |
+
* Get list of core options
|
37 |
+
*
|
38 |
+
* @return array
|
39 |
+
*
|
40 |
+
* @access protected
|
41 |
+
* @version 6.0.0
|
42 |
*/
|
43 |
+
protected function getList()
|
44 |
+
{
|
45 |
$settings = array(
|
|
|
|
|
|
|
|
|
|
|
46 |
'core.settings.editCapabilities' => array(
|
47 |
+
'title' => __('Edit/Delete Capabilities', AAM_KEY),
|
48 |
+
'description' => AAM_Backend_View_Helper::preparePhrase('Allow to edit or delete any existing capability on the Capabilities tab. [Warning!] For experienced users only. Changing or deleting capability may result in loosing access to some features or even the entire website.', 'b'),
|
49 |
+
'value' => AAM_Core_Config::get('core.settings.editCapabilities', true)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
),
|
51 |
'ui.settings.renderAccessMetabox' => array(
|
52 |
+
'title' => __('Render Access Manager Metabox', AAM_KEY),
|
53 |
+
'description' => __('Render "Access Manager" metabox on all post, term or user edit pages.', AAM_KEY),
|
54 |
+
'value' => AAM_Core_Config::get('ui.settings.renderAccessMetabox', true),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
),
|
56 |
'core.settings.multiSubject' => array(
|
57 |
+
'title' => __('Multiple Roles Support', AAM_KEY),
|
58 |
+
'description' => sprintf(__('Enable support for multiple roles per use. The final access settings will be combined based on the merging preferences. For more information check %sWordPress access control for users with multiple roles%s article.', AAM_KEY), '<a href="https://aamplugin.com/article/wordpress-access-control-for-users-with-multiple-roles">', '</a>'),
|
59 |
+
'value' => AAM_Core_Config::get('core.settings.multiSubject', false)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
)
|
61 |
);
|
62 |
+
|
63 |
+
return apply_filters('aam_settings_list_filter', $settings, 'core');
|
64 |
}
|
65 |
+
|
66 |
/**
|
67 |
+
* Register core settings UI
|
68 |
+
*
|
69 |
* @return void
|
70 |
+
*
|
71 |
* @access public
|
72 |
+
* @version 6.0.0
|
73 |
*/
|
74 |
+
public static function register()
|
75 |
+
{
|
76 |
+
AAM_Backend_Feature::registerFeature((object)array(
|
77 |
'uid' => 'settings-core',
|
78 |
+
'position' => 5,
|
79 |
'title' => __('Core Settings', AAM_KEY),
|
80 |
+
'capability' => self::ACCESS_CAPABILITY,
|
81 |
'type' => 'settings',
|
82 |
'view' => __CLASS__
|
83 |
));
|
application/Backend/Feature/Settings/Manager.php
CHANGED
@@ -5,54 +5,59 @@
|
|
5 |
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
* file 'license.txt', which is part of this source code package. *
|
7 |
* ======================================================================
|
|
|
|
|
8 |
*/
|
9 |
|
10 |
/**
|
11 |
-
* Backend
|
12 |
-
*
|
13 |
* @package AAM
|
14 |
-
* @
|
15 |
*/
|
16 |
-
class AAM_Backend_Feature_Settings_Manager extends AAM_Backend_Feature_Abstract
|
17 |
-
|
|
|
|
|
|
|
18 |
/**
|
19 |
-
*
|
20 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
* @return string
|
22 |
*
|
23 |
* @access public
|
|
|
24 |
*/
|
25 |
-
public function save()
|
26 |
-
|
27 |
-
$
|
28 |
-
|
|
|
29 |
AAM_Core_Config::set($param, $value);
|
30 |
-
|
31 |
return wp_json_encode(array('status' => 'success'));
|
32 |
}
|
33 |
-
|
34 |
/**
|
35 |
* Clear all AAM settings
|
36 |
-
*
|
37 |
* @return string
|
38 |
-
*
|
39 |
* @access public
|
|
|
40 |
*/
|
41 |
-
public function clearSettings()
|
|
|
42 |
AAM_Core_API::clearSettings();
|
43 |
|
44 |
return wp_json_encode(array('status' => 'success'));
|
45 |
}
|
46 |
|
47 |
-
/**
|
48 |
-
* Clear AAM cache manually
|
49 |
-
*
|
50 |
-
* @return string
|
51 |
-
*
|
52 |
-
* @access public
|
53 |
-
*/
|
54 |
-
public function clearCache() {
|
55 |
-
return wp_json_encode(array('status' => 'success'));
|
56 |
-
}
|
57 |
-
|
58 |
}
|
5 |
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
* file 'license.txt', which is part of this source code package. *
|
7 |
* ======================================================================
|
8 |
+
*
|
9 |
+
* @version 6.0.0
|
10 |
*/
|
11 |
|
12 |
/**
|
13 |
+
* Backend Settings area manager
|
14 |
+
*
|
15 |
* @package AAM
|
16 |
+
* @version 6.0.0
|
17 |
*/
|
18 |
+
class AAM_Backend_Feature_Settings_Manager extends AAM_Backend_Feature_Abstract
|
19 |
+
{
|
20 |
+
|
21 |
+
use AAM_Core_Contract_RequestTrait;
|
22 |
+
|
23 |
/**
|
24 |
+
* Default access capability to the settings tab
|
25 |
+
*
|
26 |
+
* @version 6.0.0
|
27 |
+
*/
|
28 |
+
const ACCESS_CAPABILITY = 'aam_manage_settings';
|
29 |
+
|
30 |
+
/**
|
31 |
+
* Save the option
|
32 |
+
*
|
33 |
* @return string
|
34 |
*
|
35 |
* @access public
|
36 |
+
* @version 6.0.0
|
37 |
*/
|
38 |
+
public function save()
|
39 |
+
{
|
40 |
+
$param = $this->getFromPost('param');
|
41 |
+
$value = $this->getFromPost('value');
|
42 |
+
|
43 |
AAM_Core_Config::set($param, $value);
|
44 |
+
|
45 |
return wp_json_encode(array('status' => 'success'));
|
46 |
}
|
47 |
+
|
48 |
/**
|
49 |
* Clear all AAM settings
|
50 |
+
*
|
51 |
* @return string
|
52 |
+
*
|
53 |
* @access public
|
54 |
+
* @version 6.0.0
|
55 |
*/
|
56 |
+
public function clearSettings()
|
57 |
+
{
|
58 |
AAM_Core_API::clearSettings();
|
59 |
|
60 |
return wp_json_encode(array('status' => 'success'));
|
61 |
}
|
62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
}
|
application/Backend/Feature/Settings/Security.php
CHANGED
@@ -5,78 +5,74 @@
|
|
5 |
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
* file 'license.txt', which is part of this source code package. *
|
7 |
* ======================================================================
|
|
|
|
|
8 |
*/
|
9 |
|
10 |
/**
|
11 |
* Backend security settings
|
12 |
-
*
|
13 |
* @package AAM
|
14 |
-
* @
|
15 |
*/
|
16 |
-
class AAM_Backend_Feature_Settings_Security extends AAM_Backend_Feature_Abstract
|
17 |
-
|
|
|
18 |
/**
|
19 |
-
*
|
|
|
|
|
20 |
*/
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
if (!current_user_can('aam_manage_settings')) {
|
25 |
-
AAM::api()->denyAccess(array('reason' => 'aam_manage_settings'));
|
26 |
-
}
|
27 |
-
}
|
28 |
-
|
29 |
/**
|
30 |
-
*
|
|
|
|
|
31 |
*/
|
32 |
-
|
33 |
-
|
34 |
-
}
|
35 |
-
|
36 |
/**
|
37 |
-
*
|
38 |
-
*
|
|
|
|
|
|
|
|
|
39 |
*/
|
40 |
-
protected function getList()
|
|
|
41 |
$settings = array(
|
42 |
-
'
|
43 |
-
'title'
|
44 |
-
'
|
45 |
-
'value'
|
46 |
),
|
47 |
-
'
|
48 |
-
'title'
|
49 |
-
'
|
50 |
-
'value'
|
51 |
-
),
|
52 |
-
'core.settings.singleSession' => array(
|
53 |
-
'title' => __('One Session Per User', AAM_KEY),
|
54 |
-
'descr' => sprintf(AAM_Backend_View_Helper::preparePhrase('Automatically destroy all other sessions for a user if he/she tries to login from different location. For more information about this option please refer to %sHow does AAM Secure Login works%s.', 'strong', 'strong'), '<a href="https://aamplugin.com/article/how-does-aam-secure-login-works" target="_blank">', '</a>'),
|
55 |
-
'value' => AAM_Core_Config::get('core.settings.singleSession', false)
|
56 |
-
),
|
57 |
-
'core.settings.bruteForceLockout' => array(
|
58 |
-
'title' => __('Brute Force Lockout', AAM_KEY),
|
59 |
-
'descr' => sprintf(AAM_Backend_View_Helper::preparePhrase('Automatically reject login attempts if number of unsuccessful login attempts is more than 20 over the period of 2 minutes (both values are configurable). For more information about this option please refer to %sHow does AAM Secure Login works%s.', 'strong', 'strong'), '<a href="https://aamplugin.com/article/how-does-aam-secure-login-works" target="_blank">', '</a>'),
|
60 |
-
'value' => AAM_Core_Config::get('core.settings.bruteForceLockout', false)
|
61 |
),
|
62 |
);
|
63 |
-
|
64 |
-
return apply_filters('
|
65 |
}
|
66 |
-
|
67 |
/**
|
68 |
-
* Register
|
69 |
-
*
|
70 |
* @return void
|
71 |
-
*
|
72 |
* @access public
|
|
|
73 |
*/
|
74 |
-
public static function register()
|
|
|
75 |
AAM_Backend_Feature::registerFeature((object) array(
|
76 |
'uid' => 'settings-security',
|
77 |
'position' => 6,
|
78 |
'title' => __('Security Settings', AAM_KEY),
|
79 |
-
'capability' =>
|
80 |
'type' => 'settings',
|
81 |
'view' => __CLASS__
|
82 |
));
|
5 |
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
* file 'license.txt', which is part of this source code package. *
|
7 |
* ======================================================================
|
8 |
+
*
|
9 |
+
* @version 6.0.0
|
10 |
*/
|
11 |
|
12 |
/**
|
13 |
* Backend security settings
|
14 |
+
*
|
15 |
* @package AAM
|
16 |
+
* @version 6.0.0
|
17 |
*/
|
18 |
+
class AAM_Backend_Feature_Settings_Security extends AAM_Backend_Feature_Abstract
|
19 |
+
{
|
20 |
+
|
21 |
/**
|
22 |
+
* Default access capability to the collection of settings
|
23 |
+
*
|
24 |
+
* @version 6.0.0
|
25 |
*/
|
26 |
+
const ACCESS_CAPABILITY = 'aam_manage_settings';
|
27 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
/**
|
29 |
+
* HTML template to render
|
30 |
+
*
|
31 |
+
* @version 6.0.0
|
32 |
*/
|
33 |
+
const TEMPLATE = 'settings/security.phtml';
|
34 |
+
|
|
|
|
|
35 |
/**
|
36 |
+
* Get list of security options
|
37 |
+
*
|
38 |
+
* @return array
|
39 |
+
*
|
40 |
+
* @access protected
|
41 |
+
* @version 6.0.0
|
42 |
*/
|
43 |
+
protected function getList()
|
44 |
+
{
|
45 |
$settings = array(
|
46 |
+
'service.secureLogin.feature.singleSession' => array(
|
47 |
+
'title' => __('One Session Per User', AAM_KEY),
|
48 |
+
'description' => sprintf(AAM_Backend_View_Helper::preparePhrase('Automatically destroy all other sessions for a user if he/she tries to login from different location. For more information about this option please refer to %sHow does AAM Secure Login works%s.', 'strong', 'strong'), '<a href="https://aamplugin.com/article/how-does-aam-secure-login-works" target="_blank">', '</a>'),
|
49 |
+
'value' => AAM_Core_Config::get('service.secureLogin.feature.singleSession', false)
|
50 |
),
|
51 |
+
'service.secureLogin.feature.bruteForceLockout' => array(
|
52 |
+
'title' => __('Brute Force Lockout', AAM_KEY),
|
53 |
+
'description' => sprintf(AAM_Backend_View_Helper::preparePhrase('Automatically reject login attempts if number of unsuccessful login attempts is more than 20 over the period of 2 minutes (both values are configurable). For more information about this option please refer to %sHow does AAM Secure Login works%s.', 'strong', 'strong'), '<a href="https://aamplugin.com/article/how-does-aam-secure-login-works" target="_blank">', '</a>'),
|
54 |
+
'value' => AAM_Core_Config::get('service.secureLogin.feature.bruteForceLockout', false)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
),
|
56 |
);
|
57 |
+
|
58 |
+
return apply_filters('aam_settings_list_filter', $settings, 'security');
|
59 |
}
|
60 |
+
|
61 |
/**
|
62 |
+
* Register security settings
|
63 |
+
*
|
64 |
* @return void
|
65 |
+
*
|
66 |
* @access public
|
67 |
+
* @version 6.0.0
|
68 |
*/
|
69 |
+
public static function register()
|
70 |
+
{
|
71 |
AAM_Backend_Feature::registerFeature((object) array(
|
72 |
'uid' => 'settings-security',
|
73 |
'position' => 6,
|
74 |
'title' => __('Security Settings', AAM_KEY),
|
75 |
+
'capability' => self::ACCESS_CAPABILITY,
|
76 |
'type' => 'settings',
|
77 |
'view' => __CLASS__
|
78 |
));
|
application/Backend/Feature/Settings/Service.php
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* ======================================================================
|
5 |
+
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
+
* file 'license.txt', which is part of this source code package. *
|
7 |
+
* ======================================================================
|
8 |
+
*
|
9 |
+
* @version 6.0.0
|
10 |
+
*/
|
11 |
+
|
12 |
+
/**
|
13 |
+
* AAM services
|
14 |
+
*
|
15 |
+
* @package AAM
|
16 |
+
* @version 6.0.0
|
17 |
+
*/
|
18 |
+
class AAM_Backend_Feature_Settings_Service extends AAM_Backend_Feature_Abstract
|
19 |
+
{
|
20 |
+
|
21 |
+
/**
|
22 |
+
* Default access capability to the collection of settings
|
23 |
+
*
|
24 |
+
* @version 6.0.0
|
25 |
+
*/
|
26 |
+
const ACCESS_CAPABILITY = 'aam_manage_services';
|
27 |
+
|
28 |
+
/**
|
29 |
+
* HTML template to render
|
30 |
+
*
|
31 |
+
* @version 6.0.0
|
32 |
+
*/
|
33 |
+
const TEMPLATE = 'settings/service.phtml';
|
34 |
+
|
35 |
+
/**
|
36 |
+
* Get list of services
|
37 |
+
*
|
38 |
+
* @return array
|
39 |
+
*
|
40 |
+
* @access protected
|
41 |
+
* @version 6.0.0
|
42 |
+
*/
|
43 |
+
protected function getList()
|
44 |
+
{
|
45 |
+
$response = apply_filters('aam_service_list_filter', array());
|
46 |
+
|
47 |
+
// Get each service status
|
48 |
+
foreach ($response as &$service) {
|
49 |
+
$service['status'] = AAM_Core_Config::get($service['setting'], 1);
|
50 |
+
}
|
51 |
+
|
52 |
+
return $response;
|
53 |
+
}
|
54 |
+
|
55 |
+
/**
|
56 |
+
* Register services settings tab
|
57 |
+
*
|
58 |
+
* @return void
|
59 |
+
*
|
60 |
+
* @access public
|
61 |
+
* @version 6.0.0
|
62 |
+
*/
|
63 |
+
public static function register()
|
64 |
+
{
|
65 |
+
AAM_Backend_Feature::registerFeature((object) array(
|
66 |
+
'uid' => 'settings-services',
|
67 |
+
'position' => 1,
|
68 |
+
'title' => __('Services', AAM_KEY),
|
69 |
+
'capability' => self::ACCESS_CAPABILITY,
|
70 |
+
'type' => 'settings',
|
71 |
+
'view' => __CLASS__
|
72 |
+
));
|
73 |
+
}
|
74 |
+
|
75 |
+
}
|
application/Backend/Feature/Subject/Role.php
CHANGED
@@ -5,35 +5,38 @@
|
|
5 |
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
* file 'license.txt', which is part of this source code package. *
|
7 |
* ======================================================================
|
|
|
|
|
8 |
*/
|
9 |
|
10 |
/**
|
11 |
* Role view manager
|
12 |
-
*
|
13 |
* @package AAM
|
14 |
-
* @
|
15 |
*/
|
16 |
-
class AAM_Backend_Feature_Subject_Role
|
17 |
-
|
|
|
18 |
/**
|
19 |
-
*
|
|
|
|
|
20 |
*/
|
21 |
-
|
22 |
-
|
23 |
-
AAM::api()->denyAccess(array('reason' => 'aam_manage_roles'));
|
24 |
-
}
|
25 |
-
}
|
26 |
-
|
27 |
/**
|
28 |
* Get role list
|
29 |
-
*
|
30 |
* Prepare and return the list of roles for the table view
|
31 |
-
*
|
32 |
* @return string JSON Encoded role list
|
33 |
-
*
|
34 |
* @access public
|
|
|
35 |
*/
|
36 |
-
public function getTable()
|
|
|
37 |
//retrieve list of users
|
38 |
$count = count_users();
|
39 |
$stats = $count['avail_roles'];
|
@@ -48,126 +51,159 @@ class AAM_Backend_Feature_Subject_Role {
|
|
48 |
);
|
49 |
|
50 |
foreach ($filtered as $id => $data) {
|
51 |
-
$
|
52 |
|
53 |
$response['data'][] = array(
|
54 |
$id,
|
55 |
-
$
|
56 |
translate_user_role($data['name']),
|
57 |
apply_filters(
|
58 |
-
'
|
59 |
-
implode(',', $this->prepareRowActions($
|
60 |
$data
|
61 |
),
|
62 |
AAM_Core_API::maxLevel($data['capabilities'])
|
63 |
);
|
64 |
}
|
65 |
-
|
66 |
-
return wp_json_encode(apply_filters('
|
67 |
}
|
68 |
-
|
69 |
/**
|
70 |
* Prepare the list of role actions
|
71 |
-
*
|
72 |
-
* @param int
|
73 |
-
*
|
74 |
-
*
|
75 |
* @return array
|
76 |
-
*
|
77 |
* @access protected
|
|
|
78 |
*/
|
79 |
-
protected function prepareRowActions($
|
80 |
-
|
81 |
-
$
|
82 |
-
|
83 |
-
if ($ui === 'principal') {
|
84 |
-
$subject = new AAM_Core_Subject_Role($roleId);
|
85 |
-
|
86 |
-
$object = $subject->getObject('policy');
|
87 |
-
$action = ($object->has($id) ? 'detach' : 'attach');
|
88 |
-
$manager = AAM_Core_Policy_Factory::get();
|
89 |
-
|
90 |
-
// Verify that current user can perform following action
|
91 |
-
$prefix = ($manager->canTogglePolicy($id, $action) ? '' : 'no-');
|
92 |
-
|
93 |
-
$actions = array($prefix . $action);
|
94 |
-
} else {
|
95 |
-
$actions = array('manage');
|
96 |
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
}
|
107 |
-
if (current_user_can('aam_delete_roles') && !$count) {
|
108 |
-
$actions[] = 'delete';
|
109 |
-
} else {
|
110 |
-
$actions[] = 'no-delete';
|
111 |
-
}
|
112 |
}
|
113 |
-
|
|
|
|
|
|
|
|
|
|
|
114 |
return $actions;
|
115 |
}
|
116 |
-
|
117 |
/**
|
118 |
-
*
|
119 |
-
*
|
|
|
|
|
|
|
|
|
|
|
120 |
* @return string
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
121 |
*/
|
122 |
-
|
123 |
-
|
124 |
-
|
|
|
125 |
);
|
126 |
}
|
127 |
-
|
128 |
/**
|
129 |
-
* Fetch role list
|
130 |
-
*
|
131 |
* @return array
|
132 |
-
*
|
133 |
* @access protected
|
|
|
134 |
*/
|
135 |
-
protected function fetchRoleList()
|
|
|
136 |
$response = array();
|
137 |
-
|
138 |
-
//
|
139 |
$search = trim(AAM_Core_Request::request('search.value'));
|
140 |
$exclude = trim(AAM_Core_Request::request('exclude'));
|
141 |
$roles = get_editable_roles();
|
142 |
-
|
143 |
foreach ($roles as $id => $role) {
|
144 |
$match = preg_match('/^' . $search . '/i', $role['name']);
|
145 |
if (($exclude !== $id) && (!$search || $match)) {
|
146 |
$response[$id] = $role;
|
147 |
}
|
148 |
}
|
149 |
-
|
150 |
return $response;
|
151 |
}
|
152 |
|
153 |
/**
|
154 |
-
*
|
155 |
-
*
|
156 |
-
* @return
|
157 |
-
*
|
158 |
-
* @access
|
|
|
159 |
*/
|
160 |
-
|
161 |
-
|
162 |
-
|
|
|
|
|
|
|
163 |
if (current_user_can('aam_create_roles')) {
|
164 |
$name = sanitize_text_field(filter_input(INPUT_POST, 'name'));
|
165 |
$roles = AAM_Core_API::getRoles();
|
166 |
$role_id = sanitize_key(strtolower($name));
|
|
|
|
|
167 |
|
168 |
-
//
|
169 |
-
|
170 |
-
|
|
|
|
|
|
|
|
|
171 |
|
172 |
if ($role = $roles->add_role($role_id, $name, $caps)) {
|
173 |
$response = array(
|
@@ -178,93 +214,93 @@ class AAM_Backend_Feature_Subject_Role {
|
|
178 |
'level' => AAM_Core_API::maxLevel($caps)
|
179 |
)
|
180 |
);
|
181 |
-
|
182 |
-
if
|
|
|
183 |
$this->cloneSettings($role, $parent);
|
184 |
}
|
185 |
-
|
186 |
-
do_action('
|
187 |
} else {
|
188 |
-
$response['reason'] = __("Role
|
189 |
}
|
190 |
}
|
191 |
|
192 |
-
return
|
193 |
}
|
194 |
-
|
195 |
/**
|
196 |
-
*
|
197 |
-
*
|
198 |
-
* @param
|
199 |
-
* @param
|
|
|
|
|
|
|
|
|
|
|
200 |
*/
|
201 |
-
protected function cloneSettings($role, $parent)
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
str_replace($parent->name, $role->name, $setting->option_name),
|
210 |
-
maybe_unserialize($setting->option_value)
|
211 |
-
);
|
212 |
-
}
|
213 |
-
}
|
214 |
-
|
215 |
-
//clone _postmeta settings
|
216 |
-
$pquery = "SELECT * FROM {$wpdb->postmeta} WHERE `meta_key` LIKE %s";
|
217 |
-
if ($wpdb->query($wpdb->prepare($pquery, 'aam-%-role' . $parent->name))) {
|
218 |
-
foreach($wpdb->last_result as $setting) {
|
219 |
-
add_post_meta(
|
220 |
-
$setting->post_id,
|
221 |
-
str_replace($parent->name, $role->name, $setting->meta_key),
|
222 |
-
maybe_unserialize($setting->meta_value)
|
223 |
-
);
|
224 |
-
}
|
225 |
-
}
|
226 |
}
|
227 |
-
|
228 |
/**
|
229 |
* Edit role name
|
230 |
-
*
|
231 |
-
* @return
|
232 |
-
*
|
233 |
-
* @access
|
|
|
234 |
*/
|
235 |
-
|
|
|
236 |
if (current_user_can('aam_edit_roles')) {
|
237 |
$role = AAM_Backend_Subject::getInstance();
|
238 |
|
239 |
$role->update(esc_js(trim(filter_input(INPUT_POST, 'name'))));
|
240 |
-
|
241 |
-
do_action('
|
242 |
-
|
243 |
$response = array('status' => 'success');
|
244 |
} else {
|
245 |
-
$response = array(
|
|
|
|
|
|
|
246 |
}
|
247 |
-
|
248 |
-
return
|
249 |
}
|
250 |
|
251 |
/**
|
252 |
* Delete role
|
253 |
-
*
|
254 |
-
* @return
|
255 |
-
*
|
256 |
-
* @access
|
|
|
257 |
*/
|
258 |
-
|
259 |
-
|
260 |
-
|
|
|
261 |
if (current_user_can('aam_delete_roles')) {
|
262 |
if (AAM_Backend_Subject::getInstance()->delete()) {
|
263 |
-
$status = 'success';
|
|
|
|
|
264 |
}
|
|
|
|
|
265 |
}
|
266 |
|
267 |
-
return
|
268 |
}
|
269 |
|
270 |
}
|
5 |
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
* file 'license.txt', which is part of this source code package. *
|
7 |
* ======================================================================
|
8 |
+
*
|
9 |
+
* @version 6.0.0
|
10 |
*/
|
11 |
|
12 |
/**
|
13 |
* Role view manager
|
14 |
+
*
|
15 |
* @package AAM
|
16 |
+
* @version 6.0.0
|
17 |
*/
|
18 |
+
class AAM_Backend_Feature_Subject_Role
|
19 |
+
{
|
20 |
+
|
21 |
/**
|
22 |
+
* Capability that allows to manage roles
|
23 |
+
*
|
24 |
+
* @version 6.0.0
|
25 |
*/
|
26 |
+
const ACCESS_CAPABILITY = 'aam_manage_roles';
|
27 |
+
|
|
|
|
|
|
|
|
|
28 |
/**
|
29 |
* Get role list
|
30 |
+
*
|
31 |
* Prepare and return the list of roles for the table view
|
32 |
+
*
|
33 |
* @return string JSON Encoded role list
|
34 |
+
*
|
35 |
* @access public
|
36 |
+
* @version 6.0.0
|
37 |
*/
|
38 |
+
public function getTable()
|
39 |
+
{
|
40 |
//retrieve list of users
|
41 |
$count = count_users();
|
42 |
$stats = $count['avail_roles'];
|
51 |
);
|
52 |
|
53 |
foreach ($filtered as $id => $data) {
|
54 |
+
$user_count = (isset($stats[$id]) ? $stats[$id] : 0);
|
55 |
|
56 |
$response['data'][] = array(
|
57 |
$id,
|
58 |
+
$user_count,
|
59 |
translate_user_role($data['name']),
|
60 |
apply_filters(
|
61 |
+
'aam_role_row_actions_filter',
|
62 |
+
implode(',', $this->prepareRowActions($user_count)),
|
63 |
$data
|
64 |
),
|
65 |
AAM_Core_API::maxLevel($data['capabilities'])
|
66 |
);
|
67 |
}
|
68 |
+
|
69 |
+
return wp_json_encode(apply_filters('aam_get_role_list_filter', $response));
|
70 |
}
|
71 |
+
|
72 |
/**
|
73 |
* Prepare the list of role actions
|
74 |
+
*
|
75 |
+
* @param int $user_count
|
76 |
+
*
|
|
|
77 |
* @return array
|
78 |
+
*
|
79 |
* @access protected
|
80 |
+
* @version 6.0.0
|
81 |
*/
|
82 |
+
protected function prepareRowActions($user_count)
|
83 |
+
{
|
84 |
+
$actions = array('manage');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
|
86 |
+
if (current_user_can('aam_edit_roles')) {
|
87 |
+
$actions[] = 'edit';
|
88 |
+
} else {
|
89 |
+
$actions[] = 'no-edit';
|
90 |
+
}
|
91 |
+
if (current_user_can('aam_create_roles')) {
|
92 |
+
$actions[] = 'clone';
|
93 |
+
} else {
|
94 |
+
$actions[] = 'no-clone';
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
}
|
96 |
+
if (current_user_can('aam_delete_roles') && !$user_count) {
|
97 |
+
$actions[] = 'delete';
|
98 |
+
} else {
|
99 |
+
$actions[] = 'no-delete';
|
100 |
+
}
|
101 |
+
|
102 |
return $actions;
|
103 |
}
|
104 |
+
|
105 |
/**
|
106 |
+
* Additional layer for method authorization
|
107 |
+
*
|
108 |
+
* This is used to control if user is allowed to perform certain AJAX action
|
109 |
+
*
|
110 |
+
* @param string $method
|
111 |
+
* @param array $args
|
112 |
+
*
|
113 |
* @return string
|
114 |
+
*
|
115 |
+
* @access public
|
116 |
+
* @version 6.0.0
|
117 |
+
*/
|
118 |
+
public function __call($method, $args)
|
119 |
+
{
|
120 |
+
$response = array(
|
121 |
+
'status' => 'failure', 'reason' => __('Unauthorized operation', AAM_KEY)
|
122 |
+
);
|
123 |
+
|
124 |
+
if (method_exists($this, "_{$method}")) {
|
125 |
+
$response = call_user_func(array($this, "_{$method}"));
|
126 |
+
} else {
|
127 |
+
_doing_it_wrong(
|
128 |
+
__CLASS__ . '::' . $method,
|
129 |
+
'User Manager does not have this method defined',
|
130 |
+
'6.0.0'
|
131 |
+
);
|
132 |
+
}
|
133 |
+
|
134 |
+
return wp_json_encode($response);
|
135 |
+
}
|
136 |
+
|
137 |
+
/**
|
138 |
+
* Get pure list of roles (without any meta info)
|
139 |
+
*
|
140 |
+
* @return array
|
141 |
+
*
|
142 |
+
* @access private
|
143 |
+
* @version 6.0.0
|
144 |
*/
|
145 |
+
private function _getList()
|
146 |
+
{
|
147 |
+
return apply_filters(
|
148 |
+
'aam_get_role_list_filter', $this->fetchRoleList()
|
149 |
);
|
150 |
}
|
151 |
+
|
152 |
/**
|
153 |
+
* Fetch role list from the DB
|
154 |
+
*
|
155 |
* @return array
|
156 |
+
*
|
157 |
* @access protected
|
158 |
+
* @version 6.0.0
|
159 |
*/
|
160 |
+
protected function fetchRoleList()
|
161 |
+
{
|
162 |
$response = array();
|
163 |
+
|
164 |
+
// Filter by name
|
165 |
$search = trim(AAM_Core_Request::request('search.value'));
|
166 |
$exclude = trim(AAM_Core_Request::request('exclude'));
|
167 |
$roles = get_editable_roles();
|
168 |
+
|
169 |
foreach ($roles as $id => $role) {
|
170 |
$match = preg_match('/^' . $search . '/i', $role['name']);
|
171 |
if (($exclude !== $id) && (!$search || $match)) {
|
172 |
$response[$id] = $role;
|
173 |
}
|
174 |
}
|
175 |
+
|
176 |
return $response;
|
177 |
}
|
178 |
|
179 |
/**
|
180 |
+
* Create new role
|
181 |
+
*
|
182 |
+
* @return array
|
183 |
+
*
|
184 |
+
* @access private
|
185 |
+
* @version 6.0.0
|
186 |
*/
|
187 |
+
private function _create()
|
188 |
+
{
|
189 |
+
$response = array(
|
190 |
+
'status' => 'failure', 'reason' => __('Unauthorized operation', AAM_KEY)
|
191 |
+
);
|
192 |
+
|
193 |
if (current_user_can('aam_create_roles')) {
|
194 |
$name = sanitize_text_field(filter_input(INPUT_POST, 'name'));
|
195 |
$roles = AAM_Core_API::getRoles();
|
196 |
$role_id = sanitize_key(strtolower($name));
|
197 |
+
$inherit = trim(filter_input(INPUT_POST, 'inherit'));
|
198 |
+
$doClone = filter_input(INPUT_POST, 'clone', FILTER_VALIDATE_BOOLEAN);
|
199 |
|
200 |
+
// If inherited role is set get capabilities from it
|
201 |
+
if ($inherit) {
|
202 |
+
$parent = $roles->get_role($inherit);
|
203 |
+
$caps = ($parent ? $parent->capabilities : array());
|
204 |
+
} else {
|
205 |
+
$caps = array();
|
206 |
+
}
|
207 |
|
208 |
if ($role = $roles->add_role($role_id, $name, $caps)) {
|
209 |
$response = array(
|
214 |
'level' => AAM_Core_API::maxLevel($caps)
|
215 |
)
|
216 |
);
|
217 |
+
|
218 |
+
// Clone settings if needed
|
219 |
+
if ($doClone && !empty($parent)) {
|
220 |
$this->cloneSettings($role, $parent);
|
221 |
}
|
222 |
+
|
223 |
+
do_action('aam_post_add_role_action', $role, $parent);
|
224 |
} else {
|
225 |
+
$response['reason'] = __("Role {$name} already exists", AAM_KEY);
|
226 |
}
|
227 |
}
|
228 |
|
229 |
+
return $response;
|
230 |
}
|
231 |
+
|
232 |
/**
|
233 |
+
* Clone access settings
|
234 |
+
*
|
235 |
+
* @param object $role
|
236 |
+
* @param object $parent
|
237 |
+
*
|
238 |
+
* @return boolean
|
239 |
+
*
|
240 |
+
* @access protected
|
241 |
+
* @version 6.0.0
|
242 |
*/
|
243 |
+
protected function cloneSettings($role, $parent)
|
244 |
+
{
|
245 |
+
$settings = AAM_Core_AccessSettings::getInstance();
|
246 |
+
|
247 |
+
// Clone the settings
|
248 |
+
$settings->set("role.{$role->name}", $settings->get("role.{$parent->name}"));
|
249 |
+
|
250 |
+
return $settings->save();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
251 |
}
|
252 |
+
|
253 |
/**
|
254 |
* Edit role name
|
255 |
+
*
|
256 |
+
* @return array
|
257 |
+
*
|
258 |
+
* @access private
|
259 |
+
* @version 6.0.0
|
260 |
*/
|
261 |
+
private function _edit()
|
262 |
+
{
|
263 |
if (current_user_can('aam_edit_roles')) {
|
264 |
$role = AAM_Backend_Subject::getInstance();
|
265 |
|
266 |
$role->update(esc_js(trim(filter_input(INPUT_POST, 'name'))));
|
267 |
+
|
268 |
+
do_action('aam_post_update_role_action', $role->getSubject());
|
269 |
+
|
270 |
$response = array('status' => 'success');
|
271 |
} else {
|
272 |
+
$response = array(
|
273 |
+
'status' => 'failure',
|
274 |
+
'reason' => __('Unauthorized operation', AAM_KEY)
|
275 |
+
);
|
276 |
}
|
277 |
+
|
278 |
+
return $response;
|
279 |
}
|
280 |
|
281 |
/**
|
282 |
* Delete role
|
283 |
+
*
|
284 |
+
* @return array
|
285 |
+
*
|
286 |
+
* @access private
|
287 |
+
* @version 6.0.0
|
288 |
*/
|
289 |
+
private function _delete()
|
290 |
+
{
|
291 |
+
$response = array('status' => 'failure');
|
292 |
+
|
293 |
if (current_user_can('aam_delete_roles')) {
|
294 |
if (AAM_Backend_Subject::getInstance()->delete()) {
|
295 |
+
$response['status'] = 'success';
|
296 |
+
} else {
|
297 |
+
$response['reason'] = __('Failed to delete the role', AAM_KEY);
|
298 |
}
|
299 |
+
} else {
|
300 |
+
$response['reason'] = __('Unauthorized operation', AAM_KEY);
|
301 |
}
|
302 |
|
303 |
+
return $response;
|
304 |
}
|
305 |
|
306 |
}
|
application/Backend/Feature/Subject/User.php
CHANGED
@@ -5,40 +5,45 @@
|
|
5 |
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
* file 'license.txt', which is part of this source code package. *
|
7 |
* ======================================================================
|
|
|
|
|
8 |
*/
|
9 |
|
10 |
/**
|
11 |
* User view manager
|
12 |
-
*
|
13 |
* @package AAM
|
14 |
-
* @
|
15 |
*/
|
16 |
-
class AAM_Backend_Feature_Subject_User
|
17 |
-
|
|
|
|
|
|
|
18 |
/**
|
19 |
-
*
|
|
|
|
|
20 |
*/
|
21 |
-
|
22 |
-
|
23 |
-
AAM::api()->denyAccess(array('reason' => 'aam_manage_users'));
|
24 |
-
}
|
25 |
-
}
|
26 |
-
|
27 |
/**
|
28 |
* Retrieve list of users
|
29 |
-
*
|
30 |
* Based on filters, get list of users
|
31 |
-
*
|
32 |
* @return string JSON encoded list of users
|
33 |
-
*
|
34 |
* @access public
|
|
|
35 |
*/
|
36 |
-
public function getTable()
|
|
|
37 |
$response = array(
|
38 |
-
'draw' =>
|
39 |
'data' => array()
|
40 |
);
|
41 |
-
|
42 |
//get total number of users
|
43 |
$total = count_users();
|
44 |
$result = $this->query();
|
@@ -47,399 +52,262 @@ class AAM_Backend_Feature_Subject_User {
|
|
47 |
$response['recordsFiltered'] = $result->get_total();
|
48 |
|
49 |
foreach ($result->get_results() as $row) {
|
50 |
-
$
|
51 |
-
|
52 |
-
|
53 |
}
|
54 |
|
55 |
return wp_json_encode($response);
|
56 |
}
|
57 |
-
|
58 |
/**
|
59 |
-
*
|
60 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
* @return string
|
62 |
-
*
|
63 |
* @access public
|
|
|
64 |
*/
|
65 |
-
public function
|
|
|
66 |
$response = array(
|
67 |
-
'status' => 'failure',
|
68 |
-
'reason' => __('Operation is not permitted', AAM_KEY)
|
69 |
);
|
70 |
-
|
71 |
-
$userId = filter_input(INPUT_POST, 'user');
|
72 |
-
$expires = filter_input(INPUT_POST, 'expires');
|
73 |
-
$action = filter_input(INPUT_POST, 'after');
|
74 |
-
$role = filter_input(INPUT_POST, 'role');
|
75 |
-
$jwt = filter_input(INPUT_POST, 'jwt');
|
76 |
-
|
77 |
-
if (current_user_can('edit_users')) {
|
78 |
-
if ($userId != get_current_user_id()) {
|
79 |
-
if ($this->isAllowed(new AAM_Core_Subject_User($userId))) {
|
80 |
-
$this->updateUserExpiration($userId, $expires, $action, $role, $jwt);
|
81 |
-
$response = array('status' => 'success');
|
82 |
-
}
|
83 |
-
} else {
|
84 |
-
$response['reason'] = __('You cannot set expiration to yourself', AAM_KEY);
|
85 |
-
}
|
86 |
-
}
|
87 |
-
|
88 |
-
return wp_json_encode($response);
|
89 |
-
}
|
90 |
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
'status' => 'failure',
|
99 |
-
'reason' => __('Operation is not permitted', AAM_KEY)
|
100 |
-
);
|
101 |
-
|
102 |
-
$userId = filter_input(INPUT_POST, 'user');
|
103 |
-
|
104 |
-
if (current_user_can('edit_users')) {
|
105 |
-
if ($userId != get_current_user_id()) {
|
106 |
-
if ($this->isAllowed(new AAM_Core_Subject_User($userId))) {
|
107 |
-
$meta = get_user_meta($userId, 'aam_user_expiration', true);
|
108 |
-
|
109 |
-
if (!empty($meta)) {
|
110 |
-
$parts = explode('|', $meta);
|
111 |
-
if (!empty($parts[3])) {
|
112 |
-
AAM_Core_Jwt_Manager::getInstance()->revokeToken(
|
113 |
-
$userId, $parts[3]
|
114 |
-
);
|
115 |
-
}
|
116 |
}
|
117 |
-
|
118 |
-
$response =
|
119 |
-
'status' => $result ? 'success' : 'failure'
|
120 |
-
);
|
121 |
}
|
122 |
-
} else {
|
123 |
-
$response['reason'] = __('You cannot manager expiration to yourself', AAM_KEY);
|
124 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
125 |
}
|
126 |
-
|
127 |
-
return wp_json_encode($response);
|
128 |
-
}
|
129 |
-
|
130 |
-
/**
|
131 |
-
*
|
132 |
-
* @return type
|
133 |
-
*/
|
134 |
-
public function switchToUser() {
|
135 |
-
$response = array(
|
136 |
-
'status' => 'failure',
|
137 |
-
'reason' => 'You are not allowed to switch to this user'
|
138 |
-
);
|
139 |
-
|
140 |
-
if (current_user_can('aam_switch_users')) {
|
141 |
-
$user = AAM_Backend_Subject::getInstance()->get();
|
142 |
-
|
143 |
-
if ($this->isAllowed($user)) {
|
144 |
-
AAM_Core_API::updateOption(
|
145 |
-
'aam-user-switch-' . $user->ID, get_current_user_id()
|
146 |
-
);
|
147 |
-
|
148 |
-
// Making sure that user that we are switching too is not logged in
|
149 |
-
// already. Reported by https://github.com/KenAer
|
150 |
-
$sessions = WP_Session_Tokens::get_instance($user->ID);
|
151 |
-
if (count($sessions->get_all()) >= 1) {
|
152 |
-
$sessions->destroy_all();
|
153 |
-
}
|
154 |
-
|
155 |
-
// If there is jwt token in cookie, make sure it is deleted otherwise
|
156 |
-
// user technically will never be switched
|
157 |
-
if (AAM_Core_Request::cookie('aam-jwt')) {
|
158 |
-
setcookie(
|
159 |
-
'aam-jwt',
|
160 |
-
'',
|
161 |
-
time() - YEAR_IN_SECONDS,
|
162 |
-
'/',
|
163 |
-
parse_url(get_bloginfo('url'), PHP_URL_HOST),
|
164 |
-
is_ssl(),
|
165 |
-
true
|
166 |
-
);
|
167 |
-
}
|
168 |
-
|
169 |
-
wp_clear_auth_cookie();
|
170 |
-
wp_set_auth_cookie( $user->ID, true );
|
171 |
-
wp_set_current_user( $user->ID );
|
172 |
|
173 |
-
$response = array('status' => 'success', 'redirect' => admin_url());
|
174 |
-
}
|
175 |
-
}
|
176 |
-
|
177 |
return wp_json_encode($response);
|
178 |
}
|
179 |
-
|
180 |
-
/**
|
181 |
-
* Query database for list of users
|
182 |
-
*
|
183 |
-
* Based on filters and settings get the list of users from database
|
184 |
-
*
|
185 |
-
* @return \WP_User_Query
|
186 |
-
*
|
187 |
-
* @access public
|
188 |
-
*/
|
189 |
-
public function query() {
|
190 |
-
$search = trim(AAM_Core_Request::request('search.value'));
|
191 |
-
$role = trim(AAM_Core_Request::request('role'));
|
192 |
-
|
193 |
-
$args = array(
|
194 |
-
'blog_id' => get_current_blog_id(),
|
195 |
-
'fields' => 'all',
|
196 |
-
'number' => AAM_Core_Request::request('length'),
|
197 |
-
'offset' => AAM_Core_Request::request('start'),
|
198 |
-
'search' => ($search ? $search . '*' : ''),
|
199 |
-
'search_columns' => array(
|
200 |
-
'user_login', 'user_email', 'display_name'
|
201 |
-
),
|
202 |
-
'orderby' => 'display_name',
|
203 |
-
'order' => $this->getOrderDirection()
|
204 |
-
);
|
205 |
-
|
206 |
-
if (!empty($role)) {
|
207 |
-
$args['role__in'] = $role;
|
208 |
-
}
|
209 |
-
|
210 |
-
return new WP_User_Query($args);
|
211 |
-
}
|
212 |
-
|
213 |
-
/**
|
214 |
-
*
|
215 |
-
* @return type
|
216 |
-
*/
|
217 |
-
protected function getOrderDirection() {
|
218 |
-
$dir = 'asc';
|
219 |
-
$order = AAM_Core_Request::post('order.0');
|
220 |
-
|
221 |
-
if (!empty($order['column']) && ($order['column'] === '2')) {
|
222 |
-
$dir = !empty($order['dir']) ? $order['dir'] : 'asc';
|
223 |
-
}
|
224 |
-
|
225 |
-
return strtoupper($dir);
|
226 |
-
}
|
227 |
|
228 |
/**
|
229 |
-
*
|
230 |
-
*
|
231 |
-
* @return string
|
232 |
-
*
|
233 |
-
* @access public
|
234 |
-
*/
|
235 |
-
public function block() {
|
236 |
-
$result = false;
|
237 |
-
|
238 |
-
if (current_user_can('aam_toggle_users') && current_user_can('edit_users')) {
|
239 |
-
$subject = AAM_Backend_Subject::getInstance();
|
240 |
-
|
241 |
-
if ($this->isAllowed($subject->get())) {
|
242 |
-
//user is not allowed to lock himself
|
243 |
-
if (intval($subject->getId()) !== get_current_user_id()) {
|
244 |
-
$result = $subject->block();
|
245 |
-
}
|
246 |
-
}
|
247 |
-
}
|
248 |
-
|
249 |
-
return wp_json_encode(array('status' => ($result ? 'success' : 'failure')));
|
250 |
-
}
|
251 |
-
|
252 |
-
/**
|
253 |
-
* Undocumented function
|
254 |
*
|
255 |
-
* @return void
|
256 |
-
*/
|
257 |
-
public function generateJwt() {
|
258 |
-
if (current_user_can('aam_manage_jwt')) {
|
259 |
-
$user = AAM_Backend_Subject::getInstance()->get();
|
260 |
-
$expires = filter_input(INPUT_POST, 'expires');
|
261 |
-
$trigger = filter_input(INPUT_POST, 'trigger', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
|
262 |
-
|
263 |
-
try {
|
264 |
-
$max = AAM::getUser()->getMaxLevel();
|
265 |
-
if ($max >= AAM_Core_API::maxLevel($user->allcaps)) {
|
266 |
-
$issuer = new AAM_Core_Jwt_Issuer();
|
267 |
-
$jwt = $issuer->issueToken(
|
268 |
-
array(
|
269 |
-
'userId' => $user->ID,
|
270 |
-
'revocable' => true,
|
271 |
-
'refreshable' => false,
|
272 |
-
'trigger' => $trigger
|
273 |
-
),
|
274 |
-
$expires
|
275 |
-
);
|
276 |
-
AAM_Core_Jwt_Manager::getInstance()->registerToken($user->ID, $jwt->token);
|
277 |
-
$result = array(
|
278 |
-
'status' => 'success',
|
279 |
-
'jwt' => $jwt->token
|
280 |
-
);
|
281 |
-
} else {
|
282 |
-
$result = array('status' => 'failure', 'reason' => 'User ID has higher level than current user');
|
283 |
-
}
|
284 |
-
} catch (Exception $ex) {
|
285 |
-
$result = array('status' => 'failure', 'reason' => $ex->getMessage());
|
286 |
-
}
|
287 |
-
} else {
|
288 |
-
$result = array('status' => 'failure', 'reason' => 'You are not allowed to manage JWT tokens');
|
289 |
-
}
|
290 |
-
|
291 |
-
return wp_json_encode($result);
|
292 |
-
}
|
293 |
-
|
294 |
-
/**
|
295 |
-
* Prepare row
|
296 |
-
*
|
297 |
* @param AAM_Core_Subject_User $user
|
298 |
-
*
|
299 |
* @return array
|
300 |
-
*
|
301 |
* @access protected
|
|
|
302 |
*/
|
303 |
-
protected function prepareRow(AAM_Core_Subject_User $user)
|
|
|
304 |
return array(
|
305 |
$user->ID,
|
306 |
-
implode(', ', $this->
|
307 |
-
|
308 |
implode(',', $this->prepareRowActions($user)),
|
309 |
AAM_Core_API::maxLevel($user->getMaxLevel()),
|
310 |
-
|
311 |
);
|
312 |
}
|
313 |
-
|
314 |
/**
|
315 |
-
*
|
316 |
-
*
|
317 |
* @param array $roles
|
318 |
-
*
|
319 |
* @return array
|
320 |
-
*
|
321 |
* @access protected
|
|
|
322 |
*/
|
323 |
-
protected function
|
|
|
324 |
$response = array();
|
325 |
-
|
326 |
$names = AAM_Core_API::getRoles()->get_names();
|
327 |
-
|
328 |
if (is_array($roles)) {
|
329 |
-
foreach($roles as $role) {
|
330 |
if (array_key_exists($role, $names)) {
|
331 |
$response[] = translate_user_role($names[$role]);
|
332 |
}
|
333 |
}
|
334 |
}
|
335 |
-
|
336 |
return $response;
|
337 |
}
|
338 |
-
|
339 |
/**
|
340 |
* Prepare user row actions
|
341 |
-
*
|
342 |
-
* @param
|
343 |
-
*
|
344 |
* @return array
|
345 |
-
*
|
346 |
* @access protected
|
|
|
347 |
*/
|
348 |
-
protected function prepareRowActions(AAM_Core_Subject_User $user)
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
if ($ui === 'principal') {
|
354 |
-
$object = $user->getObject('policy');
|
355 |
-
$actions = array(($object->has($id) ? 'detach' : 'attach'));
|
356 |
-
} else {
|
357 |
-
$actions = array('manage');
|
358 |
-
|
359 |
-
if (AAM_Core_Config::get('core.settings.secureLogin', true)
|
360 |
-
&& current_user_can('aam_toggle_users')) {
|
361 |
-
$actions[] = ($user->user_status ? 'unlock' : 'lock');
|
362 |
-
}
|
363 |
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
|
|
|
|
369 |
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
376 |
} else {
|
377 |
-
$
|
|
|
|
|
|
|
378 |
}
|
379 |
-
|
380 |
-
return $
|
381 |
}
|
382 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
383 |
/**
|
384 |
-
*
|
385 |
-
*
|
386 |
-
*
|
387 |
-
*
|
388 |
-
* @
|
389 |
-
*
|
390 |
-
*
|
391 |
-
* @return bool
|
392 |
-
*
|
393 |
* @access protected
|
|
|
394 |
*/
|
395 |
-
protected function
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
400 |
);
|
|
|
|
|
|
|
|
|
|
|
|
|
401 |
}
|
402 |
-
|
403 |
/**
|
404 |
-
* Get user
|
405 |
-
*
|
406 |
-
* @param WP_User $user
|
407 |
-
*
|
408 |
* @return string
|
409 |
-
*
|
410 |
* @access protected
|
|
|
411 |
*/
|
412 |
-
protected function
|
413 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
414 |
}
|
415 |
-
|
416 |
/**
|
417 |
-
* Check
|
418 |
-
*
|
419 |
-
* @param AAM_Core_Subject_User $user
|
420 |
-
*
|
421 |
* @return boolean
|
422 |
-
*
|
423 |
* @access protected
|
|
|
424 |
*/
|
425 |
-
protected function isAllowed(
|
426 |
-
|
427 |
-
if (
|
428 |
-
$
|
429 |
-
} else {
|
430 |
-
$sameLevel = current_user_can('administrator');
|
431 |
}
|
432 |
|
433 |
-
|
434 |
-
$subjectMaxLevel = $user->getMaxLevel();
|
435 |
-
|
436 |
-
if ($sameLevel) {
|
437 |
-
$allowed = $userMaxLevel >= $subjectMaxLevel;
|
438 |
-
} else {
|
439 |
-
$allowed = $userMaxLevel > $subjectMaxLevel;
|
440 |
-
}
|
441 |
-
|
442 |
-
return $allowed;
|
443 |
}
|
444 |
|
445 |
}
|
5 |
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
* file 'license.txt', which is part of this source code package. *
|
7 |
* ======================================================================
|
8 |
+
*
|
9 |
+
* @version 6.0.0
|
10 |
*/
|
11 |
|
12 |
/**
|
13 |
* User view manager
|
14 |
+
*
|
15 |
* @package AAM
|
16 |
+
* @version 6.0.0
|
17 |
*/
|
18 |
+
class AAM_Backend_Feature_Subject_User
|
19 |
+
{
|
20 |
+
|
21 |
+
use AAM_Core_Contract_RequestTrait;
|
22 |
+
|
23 |
/**
|
24 |
+
* Access capability for the user manager service
|
25 |
+
*
|
26 |
+
* @version 6.0.0
|
27 |
*/
|
28 |
+
const ACCESS_CAPABILITY = 'aam_manage_users';
|
29 |
+
|
|
|
|
|
|
|
|
|
30 |
/**
|
31 |
* Retrieve list of users
|
32 |
+
*
|
33 |
* Based on filters, get list of users
|
34 |
+
*
|
35 |
* @return string JSON encoded list of users
|
36 |
+
*
|
37 |
* @access public
|
38 |
+
* @version 6.0.0
|
39 |
*/
|
40 |
+
public function getTable()
|
41 |
+
{
|
42 |
$response = array(
|
43 |
+
'draw' => $this->getFromRequest('draw'),
|
44 |
'data' => array()
|
45 |
);
|
46 |
+
|
47 |
//get total number of users
|
48 |
$total = count_users();
|
49 |
$result = $this->query();
|
52 |
$response['recordsFiltered'] = $result->get_total();
|
53 |
|
54 |
foreach ($result->get_results() as $row) {
|
55 |
+
$response['data'][] = $this->prepareRow(
|
56 |
+
new AAM_Core_Subject_User($row->ID)
|
57 |
+
);
|
58 |
}
|
59 |
|
60 |
return wp_json_encode($response);
|
61 |
}
|
62 |
+
|
63 |
/**
|
64 |
+
* Additional layer for method authorization
|
65 |
+
*
|
66 |
+
* This is used to control if user is allowed to perform certain AJAX action for
|
67 |
+
* provided user
|
68 |
+
*
|
69 |
+
* @param string $method
|
70 |
+
* @param array $args
|
71 |
+
*
|
72 |
* @return string
|
73 |
+
*
|
74 |
* @access public
|
75 |
+
* @version 6.0.0
|
76 |
*/
|
77 |
+
public function __call($method, $args)
|
78 |
+
{
|
79 |
$response = array(
|
80 |
+
'status' => 'failure', 'reason' => __('Unauthorized operation', AAM_KEY)
|
|
|
81 |
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
|
83 |
+
if (method_exists($this, "_{$method}")) {
|
84 |
+
$user_id = $this->getFromPost('user');
|
85 |
+
|
86 |
+
if (current_user_can('aam_manager') && current_user_can('edit_users')) {
|
87 |
+
if ($user_id != get_current_user_id()) {
|
88 |
+
if ($this->isAllowed($user_id)) {
|
89 |
+
$response = call_user_func(array($this, "_{$method}"));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
}
|
91 |
+
} else {
|
92 |
+
$response['reason'] = __('Cannot manage yourself', AAM_KEY);
|
|
|
|
|
93 |
}
|
|
|
|
|
94 |
}
|
95 |
+
} else {
|
96 |
+
_doing_it_wrong(
|
97 |
+
__CLASS__ . '::' . $method,
|
98 |
+
'User Manager does not have this method defined',
|
99 |
+
'6.0.0'
|
100 |
+
);
|
101 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
|
|
|
|
|
|
|
|
|
103 |
return wp_json_encode($response);
|
104 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
|
106 |
/**
|
107 |
+
* Prepare individual user row
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
* @param AAM_Core_Subject_User $user
|
110 |
+
*
|
111 |
* @return array
|
112 |
+
*
|
113 |
* @access protected
|
114 |
+
* @version 6.0.0
|
115 |
*/
|
116 |
+
protected function prepareRow(AAM_Core_Subject_User $user)
|
117 |
+
{
|
118 |
return array(
|
119 |
$user->ID,
|
120 |
+
implode(', ', $this->prepareUserRoles($user->roles)),
|
121 |
+
$user->getName(),
|
122 |
implode(',', $this->prepareRowActions($user)),
|
123 |
AAM_Core_API::maxLevel($user->getMaxLevel()),
|
124 |
+
get_user_meta($user->ID, AAM_Core_Subject_User::EXPIRATION_OPTION, true)
|
125 |
);
|
126 |
}
|
127 |
+
|
128 |
/**
|
129 |
+
* Prepare the list of user roles
|
130 |
+
*
|
131 |
* @param array $roles
|
132 |
+
*
|
133 |
* @return array
|
134 |
+
*
|
135 |
* @access protected
|
136 |
+
* @version 6.0.0
|
137 |
*/
|
138 |
+
protected function prepareUserRoles($roles)
|
139 |
+
{
|
140 |
$response = array();
|
141 |
+
|
142 |
$names = AAM_Core_API::getRoles()->get_names();
|
143 |
+
|
144 |
if (is_array($roles)) {
|
145 |
+
foreach ($roles as $role) {
|
146 |
if (array_key_exists($role, $names)) {
|
147 |
$response[] = translate_user_role($names[$role]);
|
148 |
}
|
149 |
}
|
150 |
}
|
151 |
+
|
152 |
return $response;
|
153 |
}
|
154 |
+
|
155 |
/**
|
156 |
* Prepare user row actions
|
157 |
+
*
|
158 |
+
* @param AAM_Core_Subject_User $user
|
159 |
+
*
|
160 |
* @return array
|
161 |
+
*
|
162 |
* @access protected
|
163 |
+
* @version 6.0.0
|
164 |
*/
|
165 |
+
protected function prepareRowActions(AAM_Core_Subject_User $user)
|
166 |
+
{
|
167 |
+
$allowed = $this->isAllowed($user);
|
168 |
+
$actions = array();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
169 |
|
170 |
+
if ($allowed) {
|
171 |
+
$actions = array(
|
172 |
+
'manage',
|
173 |
+
current_user_can('edit_users') ? 'edit' : 'no-edit',
|
174 |
+
current_user_can('aam_switch_users') ? 'switch' : 'no-switch'
|
175 |
+
);
|
176 |
+
}
|
177 |
|
178 |
+
return apply_filters('aam_user_row_actions_filter', $actions, $user, $allowed);
|
179 |
+
}
|
180 |
+
|
181 |
+
/**
|
182 |
+
* Save user expiration
|
183 |
+
*
|
184 |
+
* @return array
|
185 |
+
*
|
186 |
+
* @access private
|
187 |
+
* @version 6.0.0
|
188 |
+
*/
|
189 |
+
private function _saveExpiration()
|
190 |
+
{
|
191 |
+
$userId = $this->getFromPost('user');
|
192 |
+
$expires = $this->getFromPost('expires');
|
193 |
+
$action = $this->getFromPost('after');
|
194 |
+
$role = $this->getFromPost('role');
|
195 |
+
|
196 |
+
$result = AAM::api()->getUser($userId)->setUserExpiration(array(
|
197 |
+
'expires' => $expires,
|
198 |
+
'action' => $action,
|
199 |
+
'meta' => (!empty($role) ? $role : null)
|
200 |
+
));
|
201 |
+
|
202 |
+
if ($result) {
|
203 |
+
$response = array('status' => 'success');
|
204 |
} else {
|
205 |
+
$response = array(
|
206 |
+
'status' => 'failure',
|
207 |
+
'reason' => __('Unexpected application error', AAM_KEY)
|
208 |
+
);
|
209 |
}
|
210 |
+
|
211 |
+
return $response;
|
212 |
}
|
213 |
+
|
214 |
+
/**
|
215 |
+
* Reset user expiration settings
|
216 |
+
*
|
217 |
+
* @return array
|
218 |
+
*
|
219 |
+
* @access private
|
220 |
+
* @version 6.0.0
|
221 |
+
*/
|
222 |
+
private function _resetExpiration()
|
223 |
+
{
|
224 |
+
$userId = $this->getFromPost('user');
|
225 |
+
$result = AAM::api()->getUser($userId)->resetExpiration();
|
226 |
+
|
227 |
+
if ($result) {
|
228 |
+
$response = array('status' => 'success');
|
229 |
+
} else {
|
230 |
+
$response = array(
|
231 |
+
'status' => 'failure',
|
232 |
+
'reason' => __('Unexpected application error', AAM_KEY)
|
233 |
+
);
|
234 |
+
}
|
235 |
+
|
236 |
+
return $response;
|
237 |
+
}
|
238 |
+
|
239 |
/**
|
240 |
+
* Query database for list of users
|
241 |
+
*
|
242 |
+
* Based on filters and settings get the list of users from database
|
243 |
+
*
|
244 |
+
* @return \WP_User_Query
|
245 |
+
*
|
|
|
|
|
|
|
246 |
* @access protected
|
247 |
+
* @version 6.0.0
|
248 |
*/
|
249 |
+
protected function query()
|
250 |
+
{
|
251 |
+
$search = trim(AAM_Core_Request::request('search.value'));
|
252 |
+
$role = trim(AAM_Core_Request::request('role'));
|
253 |
+
|
254 |
+
$args = array(
|
255 |
+
'blog_id' => get_current_blog_id(),
|
256 |
+
'fields' => 'all',
|
257 |
+
'number' => AAM_Core_Request::request('length'),
|
258 |
+
'offset' => AAM_Core_Request::request('start'),
|
259 |
+
'search' => ($search ? $search . '*' : ''),
|
260 |
+
'search_columns' => array(
|
261 |
+
'user_login', 'user_email', 'display_name'
|
262 |
+
),
|
263 |
+
'orderby' => 'display_name',
|
264 |
+
'order' => $this->getOrderDirection()
|
265 |
);
|
266 |
+
|
267 |
+
if (!empty($role)) {
|
268 |
+
$args['role__in'] = $role;
|
269 |
+
}
|
270 |
+
|
271 |
+
return new WP_User_Query($args);
|
272 |
}
|
273 |
+
|
274 |
/**
|
275 |
+
* Get user list order direction
|
276 |
+
*
|
|
|
|
|
277 |
* @return string
|
278 |
+
*
|
279 |
* @access protected
|
280 |
+
* @version 6.0.0
|
281 |
*/
|
282 |
+
protected function getOrderDirection()
|
283 |
+
{
|
284 |
+
$dir = 'asc';
|
285 |
+
$order = AAM_Core_Request::post('order.0');
|
286 |
+
|
287 |
+
if (!empty($order['column']) && (intval($order['column']) === 2)) {
|
288 |
+
$dir = !empty($order['dir']) ? $order['dir'] : 'asc';
|
289 |
+
}
|
290 |
+
|
291 |
+
return strtoupper($dir);
|
292 |
}
|
293 |
+
|
294 |
/**
|
295 |
+
* Check is current user is allowed to manage requested user
|
296 |
+
*
|
297 |
+
* @param int|AAM_Core_Subject_User $user
|
298 |
+
*
|
299 |
* @return boolean
|
300 |
+
*
|
301 |
* @access protected
|
302 |
+
* @version 6.0.0
|
303 |
*/
|
304 |
+
protected function isAllowed($user)
|
305 |
+
{
|
306 |
+
if (is_numeric($user)) {
|
307 |
+
$user = AAM::api()->getUser($user);
|
|
|
|
|
308 |
}
|
309 |
|
310 |
+
return AAM_Core_API::isUserLevelAllowed($user->getMaxLevel());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
311 |
}
|
312 |
|
313 |
}
|
application/Backend/Filter.php
DELETED
@@ -1,274 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* ======================================================================
|
5 |
-
* LICENSE: This file is subject to the terms and conditions defined in *
|
6 |
-
* file 'license.txt', which is part of this source code package. *
|
7 |
-
* ======================================================================
|
8 |
-
*/
|
9 |
-
|
10 |
-
/**
|
11 |
-
* Backend manager
|
12 |
-
*
|
13 |
-
* @package AAM
|
14 |
-
* @author Vasyl Martyniuk <vasyl@vasyltech.com>
|
15 |
-
*/
|
16 |
-
class AAM_Backend_Filter {
|
17 |
-
|
18 |
-
/**
|
19 |
-
* Instance of itself
|
20 |
-
*
|
21 |
-
* @var AAM_Backend_Filter
|
22 |
-
*
|
23 |
-
* @access private
|
24 |
-
*/
|
25 |
-
private static $_instance = null;
|
26 |
-
|
27 |
-
/**
|
28 |
-
* Initialize backend filters
|
29 |
-
*
|
30 |
-
* @return void
|
31 |
-
*
|
32 |
-
* @access protected
|
33 |
-
*/
|
34 |
-
protected function __construct() {
|
35 |
-
//menu filter
|
36 |
-
if (!AAM::isAAM() || !current_user_can('aam_manage_admin_menu')) {
|
37 |
-
add_filter('parent_file', array($this, 'filterMenu'), 999, 1);
|
38 |
-
}
|
39 |
-
|
40 |
-
//manager WordPress metaboxes
|
41 |
-
add_action("in_admin_header", array($this, 'metaboxes'), 999);
|
42 |
-
add_action("widgets_admin_page", array($this, 'metaboxes'), 999);
|
43 |
-
|
44 |
-
//control admin area
|
45 |
-
add_action('admin_notices', array($this, 'adminNotices'), -1);
|
46 |
-
add_action('network_admin_notices', array($this, 'adminNotices'), -1);
|
47 |
-
add_action('user_admin_notices', array($this, 'adminNotices'), -1);
|
48 |
-
|
49 |
-
//post restrictions
|
50 |
-
add_filter('page_row_actions', array($this, 'postRowActions'), 10, 2);
|
51 |
-
add_filter('post_row_actions', array($this, 'postRowActions'), 10, 2);
|
52 |
-
|
53 |
-
//user/role filters
|
54 |
-
if (!is_multisite() || !is_super_admin()) {
|
55 |
-
add_filter('editable_roles', array($this, 'filterRoles'));
|
56 |
-
add_action('pre_get_users', array($this, 'filterUserQuery'), 999);
|
57 |
-
add_filter('views_users', array($this, 'filterViews'));
|
58 |
-
}
|
59 |
-
|
60 |
-
AAM_Backend_Authorization::bootstrap(); //bootstrap backend authorization
|
61 |
-
}
|
62 |
-
|
63 |
-
/**
|
64 |
-
* Filter the Admin Menu
|
65 |
-
*
|
66 |
-
* @param string $parent_file
|
67 |
-
*
|
68 |
-
* @return string
|
69 |
-
*
|
70 |
-
* @access public
|
71 |
-
*/
|
72 |
-
public function filterMenu($parent_file) {
|
73 |
-
//filter admin menu
|
74 |
-
AAM::getUser()->getObject('menu')->filter();
|
75 |
-
|
76 |
-
return $parent_file;
|
77 |
-
}
|
78 |
-
|
79 |
-
/**
|
80 |
-
* Handle metabox initialization process
|
81 |
-
*
|
82 |
-
* @return void
|
83 |
-
*
|
84 |
-
* @access public
|
85 |
-
*/
|
86 |
-
public function metaboxes() {
|
87 |
-
global $post;
|
88 |
-
|
89 |
-
//make sure that nobody is playing with screen options
|
90 |
-
if (is_a($post, 'WP_Post')) {
|
91 |
-
$screen = $post->post_type;
|
92 |
-
} else {
|
93 |
-
$screen_object = get_current_screen();
|
94 |
-
$screen = ($screen_object ? $screen_object->id : '');
|
95 |
-
}
|
96 |
-
|
97 |
-
if (AAM_Core_Request::get('init') !== 'metabox') {
|
98 |
-
if ($screen !== 'widgets') {
|
99 |
-
AAM::getUser()->getObject('metabox')->filterBackend($screen);
|
100 |
-
} else {
|
101 |
-
AAM::getUser()->getObject('metabox')->filterAppearanceWidgets();
|
102 |
-
}
|
103 |
-
}
|
104 |
-
}
|
105 |
-
|
106 |
-
/**
|
107 |
-
* Manage notifications visibility
|
108 |
-
*
|
109 |
-
* @return void
|
110 |
-
*
|
111 |
-
* @access public
|
112 |
-
*/
|
113 |
-
public function adminNotices() {
|
114 |
-
if (AAM_Core_API::capabilityExists('show_admin_notices')) {
|
115 |
-
if (!current_user_can('show_admin_notices')) {
|
116 |
-
remove_all_actions('admin_notices');
|
117 |
-
remove_all_actions('network_admin_notices');
|
118 |
-
remove_all_actions('user_admin_notices');
|
119 |
-
}
|
120 |
-
}
|
121 |
-
}
|
122 |
-
|
123 |
-
/**
|
124 |
-
* Post Quick Menu Actions Filtering
|
125 |
-
*
|
126 |
-
* @param array $actions
|
127 |
-
* @param WP_Post $post
|
128 |
-
*
|
129 |
-
* @return array
|
130 |
-
*
|
131 |
-
* @access public
|
132 |
-
*/
|
133 |
-
public function postRowActions($actions, $post) {
|
134 |
-
$object = AAM::getUser()->getObject('post', $post->ID, $post);
|
135 |
-
|
136 |
-
//filter edit menu
|
137 |
-
if (!$object->allowed('backend.edit')) {
|
138 |
-
if (isset($actions['edit'])) {
|
139 |
-
unset($actions['edit']);
|
140 |
-
}
|
141 |
-
if (isset($actions['inline hide-if-no-js'])) {
|
142 |
-
unset($actions['inline hide-if-no-js']);
|
143 |
-
}
|
144 |
-
}
|
145 |
-
|
146 |
-
//filter delete menu
|
147 |
-
if (!$object->allowed('backend.delete')) {
|
148 |
-
if (isset($actions['trash'])) { unset($actions['trash']); }
|
149 |
-
if (isset($actions['delete'])) { unset($actions['delete']); }
|
150 |
-
}
|
151 |
-
|