PluginProbe
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards / 5.5.85
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards v5.5.85
5.5.85 5.5.84 5.5.83 5.5.82 5.5.81 5.5.80 5.5.79 5.5.77 5.5.76 5.5.75 5.5.73 5.5.72 5.5.22 5.5.23 5.5.29 5.5.3 5.5.31 5.5.32 5.5.34 5.5.35 5.5.36 5.5.37 5.5.4 5.5.40 5.5.41 All 161 releases
wp-data-access / WPDataAccess / Settings / WPDA_Settings_Legacy_ManageRoles.php

WPDA_Settings_Legacy_ManageRoles.php in WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards 5.5.85, at WPDataAccess/Settings/WPDA_Settings_Legacy_ManageRoles.php

210 lines 8.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WPDataAccess\Settings {
4
5 use WPDataAccess\Utilities\WPDA_Message_Box;
6 use WPDataAccess\WPDA;
7
8 class WPDA_Settings_Legacy_ManageRoles extends WPDA_Settings_Legacy_Page {
9
10 /**
11 * Add roles tab content
12 *
13 * See class documentation for flow explanation.
14 *
15 * @since 2.7.0
16 */
17 public function show() {
18
19 $wp_default_roles = array(
20 'administrator' => true,
21 'editor' => true,
22 'author' => true,
23 'contributor' => true,
24 'subscriber' => true,
25 );
26
27 if ( isset( $_REQUEST['action'] ) ) {
28 // Security check.
29 if ( 'delete' === $_REQUEST['action'] ) {
30 $wp_nonce = isset( $_REQUEST['_wpnoncedelrole'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['_wpnoncedelrole'] ) ) : ''; // input var okay.
31 if ( ! wp_verify_nonce( $wp_nonce, 'wpda-manage-roles-settings-' . WPDA::get_current_user_login() ) ) {
32 wp_die( esc_attr__( 'ERROR: Not authorized', 'wp-data-access' ) );
33 }
34 } else {
35 $wp_nonce = isset( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) ) : ''; // input var okay.
36 if ( ! wp_verify_nonce( $wp_nonce, 'wpda-manage-roles-settings-' . WPDA::get_current_user_login() ) ) {
37 wp_die( esc_attr__( 'ERROR: Not authorized', 'wp-data-access' ) );
38 }
39 }
40
41 if ( 'save' === $_REQUEST['action'] ) {
42 WPDA::set_option(
43 WPDA::OPTION_WPDA_ENABLE_ROLE_MANAGEMENT,
44 isset( $_REQUEST['enable_role_management'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['enable_role_management'] ) ) : 'off' // input var okay.
45 );
46
47 WPDA::set_option(
48 WPDA::OPTION_WPDA_USE_ROLES_IN_SHORTCODE,
49 isset( $_REQUEST['use_roles_in_shortcode'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['use_roles_in_shortcode'] ) ) : 'off' // input var okay.
50 );
51
52 if ( isset( $_REQUEST['wpda_role_name'] ) && is_array( $_REQUEST['wpda_role_name'] ) &&
53 isset( $_REQUEST['wpda_role_label'] ) && is_array( $_REQUEST['wpda_role_label'] )
54 ) {
55 $no_roles = count( $_REQUEST['wpda_role_name'] ); // phpcs:ignore -- 8.1 proof
56 for ( $i = 0; $i < $no_roles; $i ++ ) {
57 $sanitized_new_role_name = sanitize_text_field( wp_unslash( $_REQUEST['wpda_role_name'][ $i ] ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated
58 $sanitized_new_role_label = sanitize_text_field( wp_unslash( $_REQUEST['wpda_role_label'][ $i ] ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated
59 add_role( $sanitized_new_role_name, $sanitized_new_role_label );
60 }
61 }
62 $msg = new WPDA_Message_Box(
63 array(
64 'message_text' => __( 'Settings saved', 'wp-data-access' ),
65 )
66 );
67 $msg->box();
68 } elseif ( 'delete' === $_REQUEST['action'] ) {
69 if ( isset( $_REQUEST['delete_role_name'] ) ) {
70 $sanitized_role_name = sanitize_text_field( wp_unslash( $_REQUEST['delete_role_name'] ) ); // input var okay.
71 $all_users = get_users(
72 array( 'role' => $sanitized_role_name )
73 );
74 foreach ( $all_users as $user ) {
75 $wp_user = new \WP_User( $user->ID );
76 $wp_user->remove_role( $sanitized_role_name );
77 }
78 remove_role( $sanitized_role_name );
79
80 $msg = new WPDA_Message_Box(
81 array(
82 'message_text' => __( 'Settings saved', 'wp-data-access' ),
83 )
84 );
85 $msg->box();
86 }
87 } elseif ( 'setdefaults' === $_REQUEST['action'] ) {
88 // Set back to default values.
89 WPDA::set_option( WPDA::OPTION_WPDA_ENABLE_ROLE_MANAGEMENT );
90 WPDA::set_option( WPDA::OPTION_WPDA_USE_ROLES_IN_SHORTCODE );
91 }
92 }
93
94 $enable_role_management = WPDA::get_option( WPDA::OPTION_WPDA_ENABLE_ROLE_MANAGEMENT );
95 $use_roles_in_shortcode = WPDA::get_option( WPDA::OPTION_WPDA_USE_ROLES_IN_SHORTCODE );
96 ?>
97
98 <form id="wpda_settings_manage_roles"
99 method="post"
100 action="?page=<?php echo esc_attr( $this->page ); ?>&tab=legacy&vtab=roles">
101
102 <table class="wpda-table-settings">
103
104 <tr style="border-top: 1px solid #ccc">
105 <th>
106 <?php esc_html_e( 'Plugin Role Management', 'wp-data-access' ); ?>
107 </th>
108 <td>
109 <label>
110 <input type="checkbox" name="enable_role_management"
111 <?php echo 'on' === $enable_role_management ? 'checked' : ''; ?>/>
112 <?php esc_html_e( 'Enable role management', 'wp-data-access' ); ?>
113 </label>
114 <br/>
115 <label>
116 <input type="checkbox" name="use_roles_in_shortcode"
117 <?php echo 'on' === $use_roles_in_shortcode ? 'checked' : ''; ?>/>
118 <?php esc_html_e( 'Use roles in Data Projects shortcodes', 'wp-data-access' ); ?>
119 </label>
120 </td>
121 </tr>
122
123 <tr>
124 <th>
125 <?php esc_html_e( 'Available Roles', 'wp-data-access' ); ?>
126 </th>
127 <td>
128 <div id="list_roles">
129 <?php
130 global $wp_roles;
131 foreach ( $wp_roles->roles as $role => $val ) {
132 $is_wp_role = isset( $wp_default_roles[ $role ] );
133 $role_label = isset( $val['name'] ) ? $val['name'] : $role;
134 ?>
135 <div id="<?php echo esc_attr( $role ); ?>">
136 <span class="dashicons <?php echo $is_wp_role ? 'dashicons-wordpress' : 'dashicons-trash'; ?> wpda_tooltip"
137 style="font-size: 14px; vertical-align: text-top;<?php echo $is_wp_role ? '' : ' cursor: pointer;'; ?>"
138 <?php echo $is_wp_role ? '' : 'title="Delete role"'; ?>></span>
139 <?php echo esc_attr( $role_label ); ?>
140 </div>
141 <?php
142 }
143 ?>
144 </div>
145 <p>
146 <a href="javascript:void(0)" class="button" onclick="add_new_role()">Add
147 New Role</a>
148 </p>
149 </td>
150 </tr>
151
152 </table>
153
154 <div class="wpda-table-settings-button">
155 <input type="hidden" name="action" value="save"/>
156 <button type="submit" class="button button-primary">
157 <i class="fas fa-check wpda_icon_on_button"></i>
158 <?php esc_html_e( 'Save Manage Roles Settings', 'wp-data-access' ); ?>
159 </button>
160 <a href="javascript:void(0)"
161 onclick="if (confirm('<?php esc_html_e( 'Reset to defaults?', 'wp-data-access' ); ?>')) {
162 jQuery('input[name=\'action\']').val('setdefaults');
163 jQuery('#wpda_settings_manage_roles').trigger('submit');
164 }"
165 class="button button-secondary">
166 <i class="fas fa-times-circle wpda_icon_on_button"></i>
167 <?php esc_html_e( 'Reset Manage Roles Settings To Defaults', 'wp-data-access' ); ?>
168 </a>
169 </div>
170 <?php wp_nonce_field( 'wpda-manage-roles-settings-' . WPDA::get_current_user_login(), '_wpnonce', false ); ?>
171
172 </form>
173
174 <form id="delete_role_form"
175 method="post"
176 action="?page=<?php echo esc_attr( $this->page ); ?>&tab=roles">
177 <input type="hidden" id="delete_role_name" name="delete_role_name" value="">
178 <input type="hidden" name="action" value="delete">
179 <?php wp_nonce_field( 'wpda-manage-roles-settings-' . WPDA::get_current_user_login(), '_wpnoncedelrole', false ); ?>
180 </form>
181
182
183 <script type='text/javascript'>
184 function add_new_role() {
185 jQuery('#list_roles').append(
186 '<div>' +
187 ' <span class="dashicons dashicons-trash" style="font-size: 14px; vertical-align: text-top; cursor: pointer;" onclick="jQuery(this).parent().remove();"></span>' +
188 ' <label for="wpda_role_name[]">Name: </label><input name="wpda_role_name[]" style="vertical-align: middle; text-transform: lowercase;"/>' +
189 ' <label for="wpda_role_label[]">Label: </label><input name="wpda_role_label[]" style="vertical-align: middle;"/>' +
190 '</div>');
191 }
192
193 jQuery('.dashicons-trash').on('click', function (e) {
194 if (confirm('<?php echo esc_attr__( 'Delete role?', 'wp-data-access' ) . '\n' . esc_attr__( 'Role will be removed from all users.', 'wp-data-access' ) . '\n' . esc_attr__( 'This action cannot be undone!', 'wp-data-access' ); ?>')) {
195 parent = jQuery(e.target).parent();
196 parent_id = parent.attr('id');
197 jQuery('#delete_role_name').val(parent_id);
198 jQuery('#delete_role_form').submit();
199 }
200 });
201 </script>
202
203 <?php
204
205 }
206
207 }
208
209 }
210