| @@ -1,9 +1,8 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | namespace Elementor\Core\RoleManager; |
| 3 | 3 | |
| 4 | -use Elementor\Core\Utils\Promotions\Filtered_Promotions_Manager; | |
| 5 | -use Elementor\Modules\EditorOne\Classes\Menu_Data_Provider; | |
| 4 | +use Elementor\Core\Admin\Menu\Admin_Menu_Manager; | |
| 6 | 5 | use Elementor\Plugin; |
| 7 | 6 | use Elementor\Settings; |
| 8 | 7 | use Elementor\Settings_Page; |
| 9 | 8 | |
| @@ -16,12 +15,8 @@ | ||
| 16 | 15 | const PAGE_ID = 'elementor-role-manager'; |
| 17 | 16 | |
| 18 | 17 | const ROLE_MANAGER_OPTION_NAME = 'exclude_user_roles'; |
| 19 | 18 | |
| 20 | - const ROLE_MANAGER_ADVANCED = 'role-manager'; | |
| 21 | - | |
| 22 | - private static $advanced_options = []; | |
| 23 | - | |
| 24 | 19 | /** |
| 25 | 20 | * @since 2.0.0 |
| 26 | 21 | * @access public |
| 27 | 22 | */ |
| @@ -28,21 +23,8 @@ | ||
| 28 | 23 | public function get_role_manager_options() { |
| 29 | 24 | return get_option( 'elementor_' . self::ROLE_MANAGER_OPTION_NAME, [] ); |
| 30 | 25 | } |
| 31 | 26 | |
| 32 | - public function get_role_manager_advanced_options() { | |
| 33 | - return get_option( 'elementor_' . self::ROLE_MANAGER_ADVANCED, [] ); | |
| 34 | - } | |
| 35 | - | |
| 36 | - public function get_user_advanced_options() { | |
| 37 | - if ( ! empty( static::$advanced_options ) ) { | |
| 38 | - return static::$advanced_options; | |
| 39 | - } | |
| 40 | - | |
| 41 | - static::$advanced_options = $this->get_role_manager_advanced_options(); | |
| 42 | - return static::$advanced_options; | |
| 43 | - } | |
| 44 | - | |
| 45 | 27 | /** |
| 46 | 28 | * @since 2.0.0 |
| 47 | 29 | * @access protected |
| 48 | 30 | */ |
| @@ -51,8 +33,16 @@ | ||
| 51 | 33 | } |
| 52 | 34 | |
| 53 | 35 | /** |
| 54 | 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 | |
| 55 | 45 | * @access protected |
| 56 | 46 | */ |
| 57 | 47 | protected function create_tabs() { |
| 58 | 48 | $validation_class = 'Elementor\Settings_Validations'; |
| @@ -71,17 +61,8 @@ | ||
| 71 | 61 | 'setting_args' => [ |
| 72 | 62 | 'sanitize_callback' => [ $validation_class, 'checkbox_list' ], |
| 73 | 63 | ], |
| 74 | 64 | ], |
| 75 | - self::ROLE_MANAGER_ADVANCED => [ | |
| 76 | - 'field_args' => [ | |
| 77 | - 'type' => 'raw_html', | |
| 78 | - 'html' => '', | |
| 79 | - ], | |
| 80 | - 'setting_args' => [ | |
| 81 | - 'sanitize_callback' => [ $this, 'save_advanced_options' ], | |
| 82 | - ], | |
| 83 | - ], | |
| 84 | 65 | ], |
| 85 | 66 | ], |
| 86 | 67 | ], |
| 87 | 68 | ], |
| @@ -87,12 +68,8 @@ | ||
| 87 | 68 | ], |
| 88 | 69 | ]; |
| 89 | 70 | } |
| 90 | 71 | |
| 91 | - public function save_advanced_options( $input ) { | |
| 92 | - return $input; | |
| 93 | - } | |
| 94 | - | |
| 95 | 72 | /** |
| 96 | 73 | * @since 2.0.0 |
| 97 | 74 | * @access public |
| 98 | 75 | */ |
| @@ -101,25 +78,23 @@ | ||
| 101 | 78 | ?> |
| 102 | 79 | <div class="wrap"> |
| 103 | 80 | <h1 class="wp-heading-inline"><?php echo esc_html( $this->get_page_title() ); ?></h1> |
| 104 | 81 | |
| 105 | - <div> | |
| 106 | - <div id="elementor-role-manager"> | |
| 107 | - <h3><?php echo esc_html__( 'Manage What Your Users Can Edit In Elementor', 'elementor' ); ?></h3> | |
| 108 | - <form id="elementor-settings-form" method="post" action="options.php"> | |
| 109 | - <?php | |
| 110 | - settings_fields( static::PAGE_ID ); | |
| 111 | - echo '<div class="elementor-settings-form-page elementor-active">'; | |
| 112 | - foreach ( get_editable_roles() as $role_slug => $role_data ) { | |
| 113 | - if ( 'administrator' === $role_slug ) { | |
| 114 | - continue; | |
| 115 | - } | |
| 116 | - $this->display_role_controls( $role_slug, $role_data ); | |
| 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; | |
| 117 | 91 | } |
| 118 | - submit_button( __( 'Save Changes', 'elementor' ), 'primary', 'submit', true, [ 'data-id' => 'elementor-role-manager-button-save-changes' ] ); | |
| 119 | - ?> | |
| 120 | - </form> | |
| 121 | - </div> | |
| 92 | + $this->display_role_controls( $role_slug, $role_data ); | |
| 93 | + } | |
| 94 | + submit_button(); | |
| 95 | + ?> | |
| 96 | + </form> | |
| 122 | 97 | </div> |
| 123 | 98 | </div><!-- /.wrap --> |
| 124 | 99 | <?php |
| 125 | 100 | } |
| @@ -136,16 +111,14 @@ | ||
| 136 | 111 | if ( false === $excluded_options ) { |
| 137 | 112 | $excluded_options = $this->get_role_manager_options(); |
| 138 | 113 | } |
| 139 | 114 | |
| 140 | - $row_classes = 'elementor-role-row ' . esc_attr( $role_slug ) . ' e-editor-one'; | |
| 141 | - | |
| 142 | 115 | ?> |
| 143 | - <div class="<?php echo esc_attr( $row_classes ); ?>"> | |
| 116 | + <div class="elementor-role-row <?php echo esc_attr( $role_slug ); ?>"> | |
| 144 | 117 | <div class="elementor-role-label"> |
| 145 | - <span class="elementor-role-name"><?php echo esc_html( translate_user_role( $role_data['name'] ) ); ?></span> | |
| 118 | + <span class="elementor-role-name"><?php echo esc_html( $role_data['name'] ); ?></span> | |
| 146 | 119 | <span data-excluded-label="<?php esc_attr_e( 'Role Excluded', 'elementor' ); ?>" class="elementor-role-excluded-indicator"></span> |
| 147 | - <span class="elementor-role-toggle" data-id="<?php echo esc_attr( $role_slug ); ?>-toggle"><span class="dashicons dashicons-arrow-down"></span></span> | |
| 120 | + <span class="elementor-role-toggle"><span class="dashicons dashicons-arrow-down"></span></span> | |
| 148 | 121 | </div> |
| 149 | 122 | <div class="elementor-role-controls hidden"> |
| 150 | 123 | <div class="elementor-role-control"> |
| 151 | 124 | <label> |
| @@ -152,9 +125,9 @@ | ||
| 152 | 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 ); ?>> |
| 153 | 126 | <?php echo esc_html__( 'No access to editor', 'elementor' ); ?> |
| 154 | 127 | </label> |
| 155 | 128 | </div> |
| 156 | - <div class="elementor-role-controls-advanced"> | |
| 129 | + <div> | |
| 157 | 130 | <?php |
| 158 | 131 | /** |
| 159 | 132 | * Role restrictions controls. |
| 160 | 133 | * |
| @@ -176,77 +149,27 @@ | ||
| 176 | 149 | </div> |
| 177 | 150 | <?php |
| 178 | 151 | } |
| 179 | 152 | |
| 180 | - public function add_json_enable_control( $role_slug ) { | |
| 181 | - $value = 'json-upload'; | |
| 182 | - $id = self::ROLE_MANAGER_ADVANCED . '_' . $role_slug . '_' . $value; | |
| 183 | - $name = 'elementor_' . self::ROLE_MANAGER_ADVANCED . '[' . $role_slug . '][]'; | |
| 184 | - | |
| 185 | - $advanced_options = $this->get_user_advanced_options(); | |
| 186 | - $checked = isset( $advanced_options[ $role_slug ] ) ? $advanced_options[ $role_slug ] : []; | |
| 187 | - ?> | |
| 188 | - <div class="elementor-role-control"> | |
| 189 | - <label for="<?php echo esc_attr( $id ); ?>"> | |
| 190 | - <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 ), true ); ?>> | |
| 191 | - <?php echo esc_html__( 'Enable the option to upload JSON files', 'elementor' ); ?> | |
| 192 | - </label> | |
| 193 | - <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> | |
| 194 | - </div> | |
| 195 | - <?php | |
| 196 | - } | |
| 197 | - | |
| 198 | - public function add_custom_html_enable_control( $role_slug ) { | |
| 199 | - $value = 'custom-html'; | |
| 200 | - $id = self::ROLE_MANAGER_ADVANCED . '_' . $role_slug . '_' . $value; | |
| 201 | - $name = 'elementor_' . self::ROLE_MANAGER_ADVANCED . '[' . $role_slug . '][]'; | |
| 202 | - | |
| 203 | - $advanced_options = $this->get_user_advanced_options(); | |
| 204 | - $checked = isset( $advanced_options[ $role_slug ] ) ? $advanced_options[ $role_slug ] : []; | |
| 205 | - ?> | |
| 206 | - <div class="elementor-role-control"> | |
| 207 | - <label for="<?php echo esc_attr( $id ); ?>"> | |
| 208 | - <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 ), true ); ?>> | |
| 209 | - <?php echo esc_html__( 'Enable the option to use the HTML widget', 'elementor' ); ?> | |
| 210 | - </label> | |
| 211 | - <p class="elementor-role-control-warning"><strong><?php echo esc_html__( 'Heads up', 'elementor' ); ?>:</strong> <?php echo esc_html__( 'Giving broad access to edit the HTML widget can pose a security risk to your website because it enables users to run malicious scripts, etc.', 'elementor' ); ?></p> | |
| 212 | - </div> | |
| 213 | - <?php | |
| 214 | - } | |
| 215 | - | |
| 216 | 153 | /** |
| 217 | 154 | * @since 2.0.0 |
| 218 | 155 | * @access public |
| 219 | 156 | */ |
| 220 | 157 | public function get_go_pro_link_html() { |
| 221 | - $promotion = $this->get_go_pro_link_content(); | |
| 222 | - | |
| 223 | 158 | ?> |
| 224 | 159 | <div class="elementor-role-go-pro"> |
| 225 | - <div class="elementor-role-go-pro__desc"><?php echo esc_html( $promotion['description'] ); ?></div> | |
| 226 | - <div class="elementor-role-go-pro__link"><a class="elementor-button go-pro" target="_blank" href="<?php echo esc_url( $promotion['upgrade_url'] ); ?>"><?php echo esc_html( $promotion['upgrade_text'] ); ?></a></div> | |
| 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 go-pro" target="_blank" href="https://go.elementor.com/go-pro-role-manager/"><?php echo esc_html__( 'Upgrade', 'elementor' ); ?></a></div> | |
| 227 | 162 | </div> |
| 228 | 163 | <?php |
| 229 | 164 | } |
| 230 | 165 | |
| 231 | - public function get_go_pro_link_content() { | |
| 232 | - $upgrade_url = 'https://go.elementor.com/go-pro-role-manager/'; | |
| 233 | - | |
| 234 | - $promotion = [ | |
| 235 | - 'description' => esc_html__( 'Want to give access only to content?', 'elementor' ), | |
| 236 | - 'upgrade_url' => esc_url( $upgrade_url ), | |
| 237 | - 'upgrade_text' => esc_html__( 'Upgrade', 'elementor' ), | |
| 238 | - ]; | |
| 239 | - | |
| 240 | - return Filtered_Promotions_Manager::get_filtered_promotion_data( $promotion, 'elementor/role/custom_promotion', 'upgrade_url' ); | |
| 241 | - } | |
| 242 | - | |
| 243 | 166 | /** |
| 244 | 167 | * @since 2.0.0 |
| 245 | 168 | * @access public |
| 246 | 169 | */ |
| 247 | 170 | public function get_user_restrictions_array() { |
| 248 | - $user = wp_get_current_user(); | |
| 171 | + $user = wp_get_current_user(); | |
| 249 | 172 | $user_roles = $user->roles; |
| 250 | 173 | $options = $this->get_user_restrictions(); |
| 251 | 174 | $restrictions = []; |
| 252 | 175 | if ( empty( $options ) ) { |
| @@ -302,12 +225,8 @@ | ||
| 302 | 225 | |
| 303 | 226 | return true; |
| 304 | 227 | } |
| 305 | 228 | |
| 306 | - private function register_editor_one_menu( Menu_Data_Provider $menu_data_provider ) { | |
| 307 | - $menu_data_provider->register_menu( new Editor_One_Role_Manager_Menu() ); | |
| 308 | - } | |
| 309 | - | |
| 310 | 229 | /** |
| 311 | 230 | * @since 2.0.0 |
| 312 | 231 | * @access public |
| 313 | 232 | */ |
| @@ -313,15 +232,13 @@ | ||
| 313 | 232 | */ |
| 314 | 233 | public function __construct() { |
| 315 | 234 | parent::__construct(); |
| 316 | 235 | |
| 317 | - add_action( 'elementor/editor-one/menu/register', function ( Menu_Data_Provider $menu_data_provider ) { | |
| 318 | - $this->register_editor_one_menu( $menu_data_provider ); | |
| 319 | - } ); | |
| 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 | + } | |
| 320 | 241 | |
| 321 | - add_action( 'elementor/role/restrictions/controls', [ $this, 'add_json_enable_control' ] ); | |
| 322 | - add_action( 'elementor/role/restrictions/controls', [ $this, 'add_custom_html_enable_control' ] ); | |
| 323 | 242 | add_action( 'elementor/role/restrictions/controls', [ $this, 'get_go_pro_link_html' ] ); |
| 324 | - | |
| 325 | - add_filter( 'elementor/editor/user/restrictions', [ $this, 'get_role_manager_advanced_options' ] ); | |
| 326 | 243 | } |
| 327 | 244 | } |