PluginProbe
Elementor Website Builder – more than just a page builder / 3.19.3
Elementor Website Builder – more than just a page builder v3.19.3
4.3.0-beta3 4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 All 452 releases
elementor / core / role-manager / role-manager.php

role-manager.php in Elementor Website Builder – more than just a page builder 3.19.3, at core/role-manager/role-manager.php

293 lines 8.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor\Core\RoleManager;
3
4 use Elementor\Core\Admin\Menu\Admin_Menu_Manager;
5 use Elementor\Plugin;
6 use Elementor\Settings;
7 use Elementor\Settings_Page;
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit; // Exit if accessed directly.
11 }
12
13 class Role_Manager extends Settings_Page {
14
15 const PAGE_ID = 'elementor-role-manager';
16
17 const ROLE_MANAGER_OPTION_NAME = 'exclude_user_roles';
18
19 const ROLE_MANAGER_ADVANCED = 'role-manager';
20
21 private static $advanced_options = [];
22
23 /**
24 * @since 2.0.0
25 * @access public
26 */
27 public function get_role_manager_options() {
28 return get_option( 'elementor_' . self::ROLE_MANAGER_OPTION_NAME, [] );
29 }
30
31 private function get_role_manager_advanced_options() {
32 return get_option( 'elementor_' . self::ROLE_MANAGER_ADVANCED, [] );
33 }
34
35 public function get_user_advanced_options() {
36 if ( ! empty( static::$advanced_options ) ) {
37 return static::$advanced_options;
38 }
39
40 static::$advanced_options = $this->get_role_manager_advanced_options();
41 return static::$advanced_options;
42 }
43
44 /**
45 * @since 2.0.0
46 * @access protected
47 */
48 protected function get_page_title() {
49 return esc_html__( 'Role Manager', 'elementor' );
50 }
51
52 /**
53 * @since 2.0.0
54 * @access public
55 */
56 public function register_admin_menu( Admin_Menu_Manager $admin_menu ) {
57 $admin_menu->register( static::PAGE_ID, new Role_Manager_Menu_Item( $this ) );
58 }
59
60 /**
61 * @since 2.0.0
62 * @access protected
63 */
64 protected function create_tabs() {
65 $validation_class = 'Elementor\Settings_Validations';
66 return [
67 'general' => [
68 'label' => esc_html__( 'General', 'elementor' ),
69 'sections' => [
70 'tools' => [
71 'fields' => [
72 'exclude_user_roles' => [
73 'label' => esc_html__( 'Exclude Roles', 'elementor' ),
74 'field_args' => [
75 'type' => 'checkbox_list_roles',
76 'exclude' => [ 'super_admin', 'administrator' ],
77 ],
78 'setting_args' => [
79 'sanitize_callback' => [ $validation_class, 'checkbox_list' ],
80 ],
81 ],
82 self::ROLE_MANAGER_ADVANCED => [
83 'field_args' => [
84 'type' => 'raw_html',
85 'html' => '',
86 ],
87 'setting_args' => [
88 'sanitize_callback' => [ $this, 'save_advanced_options' ],
89 ],
90 ],
91 ],
92 ],
93 ],
94 ],
95 ];
96 }
97
98 public function save_advanced_options( $input ) {
99 return $input;
100 }
101
102 /**
103 * @since 2.0.0
104 * @access public
105 */
106 public function display_settings_page() {
107 $this->get_tabs();
108 ?>
109 <div class="wrap">
110 <h1 class="wp-heading-inline"><?php echo esc_html( $this->get_page_title() ); ?></h1>
111
112 <div id="elementor-role-manager">
113 <h3><?php echo esc_html__( 'Manage What Your Users Can Edit In Elementor', 'elementor' ); ?></h3>
114 <form id="elementor-settings-form" method="post" action="options.php">
115 <?php
116 settings_fields( static::PAGE_ID );
117 echo '<div class="elementor-settings-form-page elementor-active">';
118 foreach ( get_editable_roles() as $role_slug => $role_data ) {
119 if ( 'administrator' === $role_slug ) {
120 continue;
121 }
122 $this->display_role_controls( $role_slug, $role_data );
123 }
124 submit_button();
125 ?>
126 </form>
127 </div>
128 </div><!-- /.wrap -->
129 <?php
130 }
131
132 /**
133 * @since 2.0.0
134 * @access private
135 *
136 * @param string $role_slug The role slug.
137 * @param array $role_data An array with role data.
138 */
139 private function display_role_controls( $role_slug, $role_data ) {
140 static $excluded_options = false;
141 if ( false === $excluded_options ) {
142 $excluded_options = $this->get_role_manager_options();
143 }
144
145 ?>
146 <div class="elementor-role-row <?php echo esc_attr( $role_slug ); ?>">
147 <div class="elementor-role-label">
148 <span class="elementor-role-name"><?php echo esc_html( translate_user_role( $role_data['name'] ) ); ?></span>
149 <span data-excluded-label="<?php esc_attr_e( 'Role Excluded', 'elementor' ); ?>" class="elementor-role-excluded-indicator"></span>
150 <span class="elementor-role-toggle"><span class="dashicons dashicons-arrow-down"></span></span>
151 </div>
152 <div class="elementor-role-controls hidden">
153 <div class="elementor-role-control">
154 <label>
155 <input type="checkbox" name="elementor_exclude_user_roles[]" value="<?php echo esc_attr( $role_slug ); ?>"<?php checked( in_array( $role_slug, $excluded_options, true ), true ); ?>>
156 <?php echo esc_html__( 'No access to editor', 'elementor' ); ?>
157 </label>
158 </div>
159 <div>
160 <?php
161 /**
162 * Role restrictions controls.
163 *
164 * Fires after the role manager checkbox that allows the user to
165 * exclude the role.
166 *
167 * This filter allows developers to add custom controls to the role
168 * manager.
169 *
170 * @since 2.0.0
171 *
172 * @param string $role_slug The role slug.
173 * @param array $role_data An array with role data.
174 */
175 do_action( 'elementor/role/restrictions/controls', $role_slug, $role_data );
176 ?>
177 </div>
178 </div>
179 </div>
180 <?php
181 }
182
183 public function add_json_enable_control( $role_slug ) {
184 $value = 'json-upload';
185 $id = self::ROLE_MANAGER_ADVANCED . '_' . $role_slug . '_' . $value;
186 $name = 'elementor_' . self::ROLE_MANAGER_ADVANCED . '[' . $role_slug . '][]';
187
188 $advanced_options = $this->get_user_advanced_options();
189 $checked = isset( $advanced_options[ $role_slug ] ) ? $advanced_options[ $role_slug ] : [];
190 ?>
191 <div class="elementor-role-control">
192 <label for="<?php echo esc_attr( $id ); ?>">
193 <input type="checkbox" name="<?php echo esc_attr( $name ); ?>" id="<?php echo esc_attr( $id ); ?>" value="<?php echo esc_attr( $value ); ?>" <?php checked( in_array( $value, $checked ), true ); ?>>
194 <?php echo esc_html__( 'Enable the option to upload JSON files', 'elementor' ); ?>
195 </label>
196 <p class="elementor-role-control-warning"><strong><?php echo esc_html__( 'Heads up', 'elementor' ); ?>:</strong> <?php echo esc_html__( 'Giving broad access to upload JSON files can pose a security risk to your website because such files may contain malicious scripts, etc.', 'elementor' ); ?></p>
197 </div>
198 <?php
199 }
200 /**
201 * @since 2.0.0
202 * @access public
203 */
204 public function get_go_pro_link_html() {
205 ?>
206 <div class="elementor-role-go-pro">
207 <div class="elementor-role-go-pro__desc"><?php echo esc_html__( 'Want to give access only to content?', 'elementor' ); ?></div>
208 <div class="elementor-role-go-pro__link"><a class="elementor-button go-pro" target="_blank" href="https://go.elementor.com/go-pro-role-manager/"><?php echo esc_html__( 'Upgrade', 'elementor' ); ?></a></div>
209 </div>
210 <?php
211 }
212
213 /**
214 * @since 2.0.0
215 * @access public
216 */
217 public function get_user_restrictions_array() {
218 $user = wp_get_current_user();
219 $user_roles = $user->roles;
220 $options = $this->get_user_restrictions();
221 $restrictions = [];
222 if ( empty( $options ) ) {
223 return $restrictions;
224 }
225
226 foreach ( $user_roles as $role ) {
227 if ( ! isset( $options[ $role ] ) ) {
228 continue;
229 }
230 $restrictions = array_merge( $restrictions, $options[ $role ] );
231 }
232 return array_unique( $restrictions );
233 }
234
235 /**
236 * @since 2.0.0
237 * @access private
238 */
239 private function get_user_restrictions() {
240 static $restrictions = false;
241 if ( ! $restrictions ) {
242 $restrictions = [];
243
244 /**
245 * Editor user restrictions.
246 *
247 * Filters the user restrictions in the editor.
248 *
249 * @since 2.0.0
250 *
251 * @param array $restrictions User restrictions.
252 */
253 $restrictions = apply_filters( 'elementor/editor/user/restrictions', $restrictions );
254 }
255 return $restrictions;
256 }
257
258 /**
259 * @since 2.0.0
260 * @access public
261 *
262 * @param $capability
263 *
264 * @return bool
265 */
266 public function user_can( $capability ) {
267 $options = $this->get_user_restrictions_array();
268
269 if ( in_array( $capability, $options, true ) ) {
270 return false;
271 }
272
273 return true;
274 }
275
276 /**
277 * @since 2.0.0
278 * @access public
279 */
280 public function __construct() {
281 parent::__construct();
282
283 if ( ! Plugin::$instance->experiments->is_feature_active( 'admin_menu_rearrangement' ) ) {
284 add_action( 'elementor/admin/menu/register', function ( Admin_Menu_Manager $admin_menu ) {
285 $this->register_admin_menu( $admin_menu );
286 }, Settings::ADMIN_MENU_PRIORITY + 10 );
287 }
288
289 add_action( 'elementor/role/restrictions/controls', [ $this, 'add_json_enable_control' ] );
290 add_action( 'elementor/role/restrictions/controls', [ $this, 'get_go_pro_link_html' ] );
291 }
292 }
293