PluginProbe
Elementor Website Builder – more than just a page builder / 3.7.7
Elementor Website Builder – more than just a page builder v3.7.7
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.7.7, at core/role-manager/role-manager.php

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