PluginProbe ʕ •ᴥ•ʔ
Advanced Access Manager – Access Governance for WordPress / trunk
Advanced Access Manager – Access Governance for WordPress vtrunk
6.8.4 6.8.5 6.9.0 6.9.1 6.9.10 6.9.11 6.9.12 6.9.13 6.9.14 6.9.15 6.9.16 6.9.17 6.9.18 6.9.19 6.9.2 6.9.20 6.9.21 6.9.22 6.9.23 6.9.24 6.9.25 6.9.26 6.9.27 6.9.28 6.9.29 6.9.3 6.9.30 6.9.31 6.9.32 6.9.33 6.9.34 6.9.35 6.9.36 6.9.37 6.9.38 6.9.39 6.9.4 6.9.41 6.9.42 6.9.43 6.9.44 6.9.45 6.9.46 6.9.47 6.9.48 6.9.49 6.9.5 6.9.51 6.9.6 6.9.7 6.9.8 6.9.9 7.0.0 7.0.0-alpha.6 7.0.0-alpha.7 7.0.0-beta.1 7.0.0-rc1 7.0.0-rc2 7.0.0-rc3 7.0.1 7.0.10 7.0.11 7.0.2 7.0.3 7.0.4 7.0.5 7.0.6 7.0.7 7.0.8 7.0.9 7.1.0 7.1.1 trunk 3.0 4.0 4.0.1 4.1 4.2 4.3 4.4 4.4.1 4.5 4.6 4.6.1 4.6.2 4.7 4.7.1 4.7.2 4.7.5 4.7.6 4.8 4.8.1 4.9 4.9.1 4.9.2 4.9.3 4.9.4 4.9.5 4.9.5.1 4.9.5.2 5.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1 5.1.1 5.10 5.11 5.2 5.2.1 5.2.5 5.2.6 5.2.7 5.3 5.3.1 5.3.2 5.3.3 5.3.4 5.3.5 5.4 5.4.1 5.4.2 5.4.3 5.4.3.1 5.4.3.2 5.5 5.5.1 5.5.2 5.6 5.6.1 5.6.1.1 5.7 5.7.1 5.7.2 5.7.3 5.8 5.8.1 5.8.2 5.8.3 5.9 5.9.1 5.9.1.1 5.9.2 5.9.2.1 5.9.3 5.9.4 5.9.5 5.9.6 5.9.6.1 5.9.6.2 5.9.6.3 5.9.7 5.9.7.1 5.9.7.2 5.9.7.3 5.9.8 5.9.8.1 5.9.9 5.9.9.1 6.0.0 6.0.1 6.0.2 6.0.3 6.0.4 6.0.5 6.1.0 6.1.1 6.2.0 6.2.1 6.2.2 6.3.0 6.3.1 6.3.2 6.3.3 6.4.0 6.4.1 6.4.2 6.4.3 6.5.0 6.5.1 6.5.2 6.5.3 6.5.4 6.6.0 6.6.1 6.6.2 6.6.3 6.6.4 6.7.0 6.7.1 6.7.2 6.7.3 6.7.4 6.7.5 6.7.6 6.7.7 6.7.8 6.7.9 6.8.0 6.8.1 6.8.2 6.8.3
advanced-access-manager / application / Backend / Feature / Main / Content.php
advanced-access-manager / application / Backend / Feature / Main Last commit date
AccessDeniedRedirect.php 1 year ago AdminToolbar.php 1 year ago ApiRoute.php 1 year ago BackendMenu.php 1 year ago Capability.php 1 year ago Content.php 1 year ago Identity.php 1 year ago Jwt.php 1 year ago LoginRedirect.php 1 year ago LogoutRedirect.php 1 year ago Metabox.php 1 year ago NotFoundRedirect.php 1 year ago Policy.php 1 year ago Url.php 1 year ago Welcome.php 1 year ago Widget.php 1 year ago
Content.php
300 lines
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 posts & terms service UI
12 *
13 * @package AAM
14 * @version 7.0.0
15 */
16 class AAM_Backend_Feature_Main_Content extends AAM_Backend_Feature_Abstract
17 {
18
19 /**
20 * Default access capability to the service
21 *
22 * @version 7.0.0
23 */
24 const ACCESS_CAPABILITY = 'aam_manage_content';
25
26 /**
27 * HTML template to render
28 *
29 * @version 7.0.0
30 */
31 const TEMPLATE = 'service/content.php';
32
33
34 /**
35 * Get access form with pre-populated data
36 *
37 * @param mixed $resource_id
38 * @param string $resource_type
39 *
40 * @return string
41 * @access public
42 *
43 * @version 7.0.6
44 */
45 public function render_content_access_form($resource_id, $resource_type)
46 {
47 $access_level = AAM_Backend_AccessLevel::get_instance();
48
49 // Making sure we are dealing with correct resource ID
50 if ($resource_type === AAM_Framework_Type_Resource::TERM) {
51 // Get term
52 $resource_identifier = get_term(
53 intval($resource_id),
54 AAM::api()->misc->get($_POST, 'taxonomy', '')
55 );
56
57 $post_type = AAM::api()->misc->get($_POST, 'post_type');
58
59 if (!empty($post_type)) {
60 $resource_identifier->post_type = $post_type;
61 }
62 } elseif ($resource_type === AAM_Framework_Type_Resource::POST) {
63 $resource_identifier = get_post($resource_id);
64 } elseif ($resource_type === AAM_Framework_Type_Resource::TAXONOMY) {
65 $resource_identifier = get_taxonomy($resource_id);
66 } elseif ($resource_type === AAM_Framework_Type_Resource::POST_TYPE) {
67 $resource_identifier = get_post_type_object($resource_id);
68 }
69
70 // Do not render anything for illegal resource or resource that does not
71 // exist anymore
72 if (!is_wp_error($resource_id) && is_object($resource_identifier)) {
73 $resource = $access_level->get_resource($resource_type);
74 $args = [
75 'resource' => $resource,
76 'resource_identifier' => $resource_identifier,
77 'resource_id' => $resource_id,
78 'access_controls' => $this->_prepare_access_controls(
79 $resource, $resource_identifier
80 ),
81 // TODO: Consider removing the Backend Access Level
82 'access_level' => AAM_Backend_AccessLevel::get_instance()
83 ];
84
85 // Do the SSR for the access form
86 $result = apply_filters(
87 "aam_{$resource_type}_access_form_filter",
88 $this->_load_partial('content-access-form', (object) $args),
89 (object) $args
90 );
91 } else {
92 $result = null;
93 }
94
95 return $result;
96 }
97
98 /**
99 * Load dynamic template
100 *
101 * @param string $name
102 * @param object $params
103 *
104 * @return string
105 * @access public
106 *
107 * @version 7.0.0
108 */
109 private function _load_partial($name, object $params)
110 {
111 ob_start();
112
113 // Prepare the complete filepath
114 $file_path = dirname(__DIR__) . '/../tmpl/partial/' . $name . '.php';
115
116 require $file_path;
117 $content = ob_get_contents();
118
119 ob_end_clean();
120
121 return $content;
122 }
123
124 /**
125 * Prepare list of access controls for currently managed resource
126 *
127 * @param AAM_Framework_Resource_Interface $resource
128 * @param mixed $resource_identifier
129 *
130 * @return array
131 * @access private
132 *
133 * @version 7.0.0
134 */
135 private function _prepare_access_controls($resource, $resource_identifier)
136 {
137 $result = [];
138
139 if ($resource->type === AAM_Framework_Type_Resource::POST) {
140 $result = $this->_prepare_post_access_controls(
141 $resource, $resource_identifier
142 );
143 } else {
144 $result = $this->_prepare_other_access_controls(
145 $resource, $resource_identifier
146 );
147 }
148
149 return $result;
150 }
151
152 /**
153 * Prepare access controls for the post resource
154 *
155 * @param AAM_Framework_Resource_Post $resource
156 * @param mixed $resource_identifier
157 *
158 * @return array
159 * @access private
160 *
161 * @version 7.0.0
162 */
163 private function _prepare_post_access_controls($resource, $resource_identifier)
164 {
165 $list = $resource->get_permission($resource_identifier, 'list');
166
167 if (!empty($list) && $list['effect'] !== 'allow') {
168 $on = !empty($list['on']) ? $list['on'] : [ 'frontend', 'backend', 'api' ];
169 } else {
170 $on = [];
171 }
172
173 $read = $resource->get_permission($resource_identifier, 'read');
174 $comment = $resource->get_permission($resource_identifier, 'comment');
175 $edit = $resource->get_permission($resource_identifier, 'edit');
176 $publish = $resource->get_permission($resource_identifier, 'publish');
177 $delete = $resource->get_permission($resource_identifier, 'delete');
178
179 return apply_filters('aam_ui_content_access_controls_filter', [
180 'list' => array(
181 'title' => __('Hidden', 'advanced-access-manager'),
182 'modal' => 'modal_content_visibility',
183 'is_denied' => !empty($list) && $list['effect'] !== 'allow',
184 'areas' => $on,
185 'customize' => __('Customize visibility', 'advanced-access-manager'),
186 'tooltip' => sprintf(
187 __('Customize the visibility of "%s" separately for each section of your website. It\'s crucial to thoughtfully select which areas will have hidden content. For instance, you might choose to hide certain posts in the backend for content editors, while still allowing them to be visible on the frontend for general users.', 'advanced-access-manager'),
188 $resource_identifier->post_title
189 ),
190 'description' => sprintf(
191 __('Hide the "%s" from all menus, lists, and API responses. However, it remains accessible via a direct URL. Visibility can be customized for the frontend, backend and API areas independently.', 'advanced-access-manager'),
192 $resource_identifier->post_title
193 ),
194 'on' => [
195 'frontend' => sprintf(
196 __('Hide the "%s" on the website frontend', 'advanced-access-manager'),
197 $resource_identifier->post_title
198 ),
199 'backend' => sprintf(
200 __('Hide the "%s" in the backend (admin area)', 'advanced-access-manager'),
201 $resource_identifier->post_title
202 ),
203 'api' => sprintf(
204 __('Hide the "%s" in the RESTful API results', 'advanced-access-manager'),
205 $resource_identifier->post_title
206 )
207 ]
208 ),
209 'read' => array(
210 'title' => __('Restricted', 'advanced-access-manager'),
211 'modal' => 'modal_content_restriction',
212 'is_denied' => !empty($read) && $read['effect'] !== 'allow',
213 'customize' => __('Customize direct access', 'advanced-access-manager'),
214 'tooltip' => sprintf(
215 __('Restrict direct access to read or download the "%s". This restriction can be customized with options such as setting an access expiration date, creating a password, redirecting to a different location, and more.', 'advanced-access-manager'),
216 $resource_identifier->post_title
217 ),
218 'description' => sprintf(
219 __('Restrict direct access to "%s". This restriction can be customized with options such as setting an access expiration date, creating a password, redirecting to a different location, and more.', 'advanced-access-manager'),
220 $resource_identifier->post_title
221 )
222 ),
223 'comment' => array(
224 'title' => __('Leave Comments', 'advanced-access-manager'),
225 'is_denied' => !empty($comment) && $comment['effect'] !== 'allow',
226 'description' => sprintf(
227 __('Limit the ability to leave comments on the "%s".', 'advanced-access-manager'),
228 $resource_identifier->post_title
229 )
230 ),
231 'edit' => array(
232 'title' => __('Edit', 'advanced-access-manager'),
233 'is_denied' => !empty($edit) && $edit['effect'] !== 'allow',
234 'description' => sprintf(
235 __('Disable the ability to edit "%s". Editing "%s" will be restricted both in the backend area and via the RESTful API.', 'advanced-access-manager'),
236 $resource_identifier->post_title,
237 $resource_identifier->post_title
238 )
239 ),
240 'publish' => array(
241 'title' => __('Publish', 'advanced-access-manager'),
242 'is_denied' => !empty($publish) && $publish['effect'] !== 'allow',
243 'description' => sprintf(
244 __('Manage the ability to publish draft "%s" or any updates to already published versions. If denied, a user will only be able to submit for review.', 'advanced-access-manager'),
245 $resource_identifier->post_title
246 )
247 ),
248 'delete' => array(
249 'title' => __('Delete', 'advanced-access-manager'),
250 'is_denied' => !empty($delete) && $delete['effect'] !== 'allow',
251 'description' => sprintf(
252 __('Disable the ability to delete "%s". Deletion will be restricted both in the backend area and via the RESTful API.', 'advanced-access-manager'),
253 $resource_identifier->post_title
254 )
255 )
256 ], $resource, $resource_identifier);
257 }
258
259 /**
260 * Prepare access controls for other resources
261 *
262 * @param AAM_Framework_Resource_Interface $resource
263 * @param mixed $resource_identifier
264 *
265 * @return array
266 * @access private
267 *
268 * @version 7.0.0
269 */
270 private function _prepare_other_access_controls($resource, $resource_identifier)
271 {
272 return apply_filters(
273 'aam_ui_content_access_controls_filter',
274 [],
275 $resource,
276 $resource_identifier
277 );
278 }
279
280 /**
281 * Register Posts & Pages service UI
282 *
283 * @return void
284 * @access public
285 *
286 * @version 7.0.0
287 */
288 public static function register()
289 {
290 AAM_Backend_Feature::registerFeature((object) array(
291 'uid' => 'post',
292 'position' => 20,
293 'title' => __('Posts & Terms', 'advanced-access-manager'),
294 'capability' => self::ACCESS_CAPABILITY,
295 'type' => 'main',
296 'view' => __CLASS__
297 ));
298 }
299
300 }