PluginProbe
Elementor Website Builder – more than just a page builder / 3.6.5
Elementor Website Builder – more than just a page builder v3.6.5
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 4.0.7 All 451 releases
elementor / core / role-manager / role-manager.php

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

253 lines 6.4 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\Plugin;
5 use Elementor\Settings_Page;
6 use Elementor\Settings;
7 use Elementor\Utils;
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 /**
20 * @since 2.0.0
21 * @access public
22 */
23 public function get_role_manager_options() {
24 return get_option( 'elementor_' . self::ROLE_MANAGER_OPTION_NAME, [] );
25 }
26
27 /**
28 * @since 2.0.0
29 * @access protected
30 */
31 protected function get_page_title() {
32 return __( 'Role Manager', 'elementor' );
33 }
34
35 /**
36 * @since 2.0.0
37 * @access public
38 */
39 public function register_admin_menu() {
40 $sanitized_page_title = esc_html( $this->get_page_title() );
41
42 add_submenu_page(
43 Settings::PAGE_ID,
44 $sanitized_page_title,
45 $sanitized_page_title,
46 'manage_options',
47 self::PAGE_ID,
48 [ $this, 'display_settings_page' ]
49 );
50 }
51
52 /**
53 * @since 2.0.0
54 * @access protected
55 */
56 protected function create_tabs() {
57 $validation_class = 'Elementor\Settings_Validations';
58 return [
59 'general' => [
60 'label' => esc_html__( 'General', 'elementor' ),
61 'sections' => [
62 'tools' => [
63 'fields' => [
64 'exclude_user_roles' => [
65 'label' => esc_html__( 'Exclude Roles', 'elementor' ),
66 'field_args' => [
67 'type' => 'checkbox_list_roles',
68 'exclude' => [ 'super_admin', 'administrator' ],
69 ],
70 'setting_args' => [
71 'sanitize_callback' => [ $validation_class, 'checkbox_list' ],
72 ],
73 ],
74 ],
75 ],
76 ],
77 ],
78 ];
79 }
80
81 /**
82 * @since 2.0.0
83 * @access public
84 */
85 public function display_settings_page() {
86 $this->get_tabs();
87 ?>
88 <div class="wrap">
89 <h1 class="wp-heading-inline"><?php echo esc_html( $this->get_page_title() ); ?></h1>
90
91 <div id="elementor-role-manager">
92 <h3><?php echo esc_html__( 'Manage What Your Users Can Edit In Elementor', 'elementor' ); ?></h3>
93 <form id="elementor-settings-form" method="post" action="options.php">
94 <?php
95 settings_fields( static::PAGE_ID );
96 echo '<div class="elementor-settings-form-page elementor-active">';
97 foreach ( get_editable_roles() as $role_slug => $role_data ) {
98 if ( 'administrator' === $role_slug ) {
99 continue;
100 }
101 $this->display_role_controls( $role_slug, $role_data );
102 }
103 submit_button();
104 ?>
105 </form>
106 </div>
107 </div><!-- /.wrap -->
108 <?php
109 }
110
111 /**
112 * @since 2.0.0
113 * @access private
114 *
115 * @param string $role_slug The role slug.
116 * @param array $role_data An array with role data.
117 */
118 private function display_role_controls( $role_slug, $role_data ) {
119 static $excluded_options = false;
120 if ( false === $excluded_options ) {
121 $excluded_options = $this->get_role_manager_options();
122 }
123
124 ?>
125 <div class="elementor-role-row <?php echo esc_attr( $role_slug ); ?>">
126 <div class="elementor-role-label">
127 <span class="elementor-role-name"><?php echo esc_html( $role_data['name'] ); ?></span>
128 <span data-excluded-label="<?php esc_attr_e( 'Role Excluded', 'elementor' ); ?>" class="elementor-role-excluded-indicator"></span>
129 <span class="elementor-role-toggle"><span class="dashicons dashicons-arrow-down"></span></span>
130 </div>
131 <div class="elementor-role-controls hidden">
132 <div class="elementor-role-control">
133 <label>
134 <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 ); ?>>
135 <?php echo esc_html__( 'No access to editor', 'elementor' ); ?>
136 </label>
137 </div>
138 <div>
139 <?php
140 /**
141 * Role restrictions controls.
142 *
143 * Fires after the role manager checkbox that allows the user to
144 * exclude the role.
145 *
146 * This filter allows developers to add custom controls to the role
147 * manager.
148 *
149 * @since 2.0.0
150 *
151 * @param string $role_slug The role slug.
152 * @param array $role_data An array with role data.
153 */
154 do_action( 'elementor/role/restrictions/controls', $role_slug, $role_data );
155 ?>
156 </div>
157 </div>
158 </div>
159 <?php
160 }
161
162 /**
163 * @since 2.0.0
164 * @access public
165 */
166 public function get_go_pro_link_html() {
167 $pro_link = Utils::get_pro_link( 'https://elementor.com/pro/?utm_source=wp-role-manager&utm_campaign=gopro&utm_medium=wp-dash' );
168 ?>
169 <div class="elementor-role-go-pro">
170 <div class="elementor-role-go-pro__desc"><?php echo esc_html__( 'Want to give access only to content?', 'elementor' ); ?></div>
171 <div class="elementor-role-go-pro__link"><a class="elementor-button elementor-button-default elementor-button-go-pro" target="_blank" href="<?php echo esc_url( $pro_link ); ?>"><?php echo esc_html__( 'Go Pro', 'elementor' ); ?></a></div>
172 </div>
173 <?php
174 }
175
176 /**
177 * @since 2.0.0
178 * @access public
179 */
180 public function get_user_restrictions_array() {
181 $user = wp_get_current_user();
182 $user_roles = $user->roles;
183 $options = $this->get_user_restrictions();
184 $restrictions = [];
185 if ( empty( $options ) ) {
186 return $restrictions;
187 }
188
189 foreach ( $user_roles as $role ) {
190 if ( ! isset( $options[ $role ] ) ) {
191 continue;
192 }
193 $restrictions = array_merge( $restrictions, $options[ $role ] );
194 }
195 return array_unique( $restrictions );
196 }
197
198 /**
199 * @since 2.0.0
200 * @access private
201 */
202 private function get_user_restrictions() {
203 static $restrictions = false;
204 if ( ! $restrictions ) {
205 $restrictions = [];
206
207 /**
208 * Editor user restrictions.
209 *
210 * Filters the user restrictions in the editor.
211 *
212 * @since 2.0.0
213 *
214 * @param array $restrictions User restrictions.
215 */
216 $restrictions = apply_filters( 'elementor/editor/user/restrictions', $restrictions );
217 }
218 return $restrictions;
219 }
220
221 /**
222 * @since 2.0.0
223 * @access public
224 *
225 * @param $capability
226 *
227 * @return bool
228 */
229 public function user_can( $capability ) {
230 $options = $this->get_user_restrictions_array();
231
232 if ( in_array( $capability, $options, true ) ) {
233 return false;
234 }
235
236 return true;
237 }
238
239 /**
240 * @since 2.0.0
241 * @access public
242 */
243 public function __construct() {
244 parent::__construct();
245
246 if ( ! Plugin::$instance->experiments->is_feature_active( 'admin_menu_rearrangement' ) ) {
247 add_action( 'admin_menu', [ $this, 'register_admin_menu' ], 100 );
248 }
249
250 add_action( 'elementor/role/restrictions/controls', [ $this, 'get_go_pro_link_html' ] );
251 }
252 }
253