PluginProbe
Groups – Memberships and Access Control / 1.11.2
Groups – Memberships and Access Control v1.11.2
4.7.1 4.7.0 4.6.0 4.5.0 4.4.0 4.3.0 trunk 1.0.0-beta-1 1.0.0-beta-2 1.0.0-beta-3 1.0.0-beta-3b 1.0.0-beta-3c 1.0.0-beta-3d 1.1.4 1.1.5 1.10.0 1.10.1 1.10.2 1.10.3 1.11.0 1.11.1 1.11.2 1.11.3 1.12.0 1.13.0 All 131 releases
groups / lib / admin / groups-admin-options.php

groups-admin-options.php in Groups – Memberships and Access Control 1.11.2, at lib/admin/groups-admin-options.php

370 lines 13.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * groups-admin-options.php
4 *
5 * Copyright (c) "kento" Karim Rahimpur www.itthinx.com
6 *
7 * This code is released under the GNU General Public License.
8 * See COPYRIGHT.txt and LICENSE.txt.
9 *
10 * This code is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * This header and all notices must be kept intact.
16 *
17 * @author Karim Rahimpur
18 * @package groups
19 * @since groups 1.0.0
20 */
21
22 if ( !defined( 'ABSPATH' ) ) {
23 exit;
24 }
25
26 /**
27 * @var string options form nonce name
28 */
29 define( 'GROUPS_ADMIN_OPTIONS_NONCE', 'groups-admin-nonce' );
30
31 /**
32 * Options admin screen.
33 */
34 function groups_admin_options() {
35
36 global $wpdb, $wp_roles;
37
38 if ( !current_user_can( GROUPS_ADMINISTER_OPTIONS ) ) {
39 wp_die( __( 'Access denied.', GROUPS_PLUGIN_DOMAIN ) );
40 }
41
42 $is_sitewide_plugin = false;
43 if ( is_multisite() ) {
44 $active_sitewide_plugins = get_site_option( 'active_sitewide_plugins', array() );
45 $active_sitewide_plugins = array_keys( $active_sitewide_plugins );
46 $is_sitewide_plugin = in_array( 'groups/groups.php', $active_sitewide_plugins );
47 }
48
49 $caps = array(
50 GROUPS_ACCESS_GROUPS => __( 'Access Groups', GROUPS_PLUGIN_DOMAIN ),
51 GROUPS_ADMINISTER_GROUPS => __( 'Administer Groups', GROUPS_PLUGIN_DOMAIN ),
52 GROUPS_ADMINISTER_OPTIONS => __( 'Administer Groups plugin options', GROUPS_PLUGIN_DOMAIN ),
53 );
54
55 //
56 // handle options form submission
57 //
58 if ( isset( $_POST['submit'] ) ) {
59 if ( wp_verify_nonce( $_POST[GROUPS_ADMIN_OPTIONS_NONCE], 'admin' ) ) {
60
61 // admin override
62 if ( empty( $_POST[GROUPS_ADMINISTRATOR_ACCESS_OVERRIDE] ) ) {
63 $admin_override = false;
64 } else {
65 $admin_override = true;
66 }
67 // Don't move this to the plugin options, access will be faster
68 add_option( GROUPS_ADMINISTRATOR_ACCESS_OVERRIDE, $admin_override ); // WP 3.3.1 : update alone wouldn't create the option when value is false
69 update_option( GROUPS_ADMINISTRATOR_ACCESS_OVERRIDE, $admin_override );
70
71 $post_types_option = Groups_Options::get_option( Groups_Post_Access::POST_TYPES, array() );
72 $post_types = get_post_types( array( 'public' => true ) );
73 $selected_post_types = is_array( $_POST['add_meta_boxes'] ) ? $_POST['add_meta_boxes'] : array();
74 foreach( $post_types as $post_type ) {
75 $post_types_option[$post_type]['add_meta_box'] = in_array( $post_type, $selected_post_types );
76 }
77 Groups_Options::update_option( Groups_Post_Access::POST_TYPES, $post_types_option );
78
79 $valid_read_caps = array( Groups_Post_Access::READ_POST_CAPABILITY );
80 if ( !empty( $_POST[GROUPS_READ_POST_CAPABILITIES] ) ) {
81 $read_caps = $_POST[GROUPS_READ_POST_CAPABILITIES];
82 foreach( $read_caps as $read_cap ) {
83 if ( $valid_cap = Groups_Capability::read( $read_cap ) ) {
84 if ( !in_array( $valid_cap->capability, $valid_read_caps ) ) {
85 $valid_read_caps[] = $valid_cap->capability;
86 }
87 }
88 }
89 }
90 Groups_Options::update_option( Groups_Post_Access::READ_POST_CAPABILITIES, $valid_read_caps );
91
92 // tree view
93 if ( !empty( $_POST[GROUPS_SHOW_TREE_VIEW] ) ) {
94 Groups_Options::update_option( GROUPS_SHOW_TREE_VIEW, true );
95 } else {
96 Groups_Options::update_option( GROUPS_SHOW_TREE_VIEW, false );
97 }
98
99 // show in user profiles
100 Groups_Options::update_option( GROUPS_SHOW_IN_USER_PROFILE, !empty( $_POST[GROUPS_SHOW_IN_USER_PROFILE] ) );
101
102 // roles & capabilities
103 $rolenames = $wp_roles->get_names();
104 foreach ( $rolenames as $rolekey => $rolename ) {
105 $role = $wp_roles->get_role( $rolekey );
106 foreach ( $caps as $capkey => $capname ) {
107 $role_cap_id = $rolekey.'-'.$capkey;
108 if ( !empty($_POST[$role_cap_id] ) ) {
109 $role->add_cap( $capkey );
110 } else {
111 $role->remove_cap( $capkey );
112 }
113 }
114 }
115 Groups_Controller::assure_capabilities();
116
117 if ( !$is_sitewide_plugin ) {
118 // delete data
119 if ( !empty( $_POST['delete-data'] ) ) {
120 Groups_Options::update_option( 'groups_delete_data', true );
121 } else {
122 Groups_Options::update_option( 'groups_delete_data', false );
123 }
124 }
125 Groups_Admin::add_message( __( 'Options saved.', GROUPS_PLUGIN_DOMAIN ) );
126 }
127 }
128
129 echo '<div class="groups-options wrap">';
130
131 echo
132 '<h1>' .
133 __( 'Groups Options', GROUPS_PLUGIN_DOMAIN ) .
134 '</h1>';
135
136 echo Groups_Admin::render_messages();
137
138 $admin_override = get_option( GROUPS_ADMINISTRATOR_ACCESS_OVERRIDE, GROUPS_ADMINISTRATOR_ACCESS_OVERRIDE_DEFAULT );
139
140 $show_tree_view = Groups_Options::get_option( GROUPS_SHOW_TREE_VIEW, GROUPS_SHOW_TREE_VIEW_DEFAULT );
141 $show_in_user_profile = Groups_Options::get_option( GROUPS_SHOW_IN_USER_PROFILE, GROUPS_SHOW_IN_USER_PROFILE_DEFAULT );
142
143 $rolenames = $wp_roles->get_names();
144 $caps_table = '<table class="groups-permissions">';
145 $caps_table .= '<thead>';
146 $caps_table .= '<tr>';
147 $caps_table .= '<td class="role">';
148 $caps_table .= __( 'Role', GROUPS_PLUGIN_DOMAIN );
149 $caps_table .= '</td>';
150 foreach ( $caps as $cap ) {
151 $caps_table .= '<td class="cap">';
152 $caps_table .= $cap;
153 $caps_table .= '</td>';
154 }
155
156 $caps_table .= '</tr>';
157 $caps_table .= '</thead>';
158 $caps_table .= '<tbody>';
159 foreach ( $rolenames as $rolekey => $rolename ) {
160 $role = $wp_roles->get_role( $rolekey );
161 $caps_table .= '<tr>';
162 $caps_table .= '<td>';
163 $caps_table .= translate_user_role( $rolename );
164 $caps_table .= '</td>';
165 foreach ( $caps as $capkey => $capname ) {
166
167 if ( $role->has_cap( $capkey ) ) {
168 $checked = ' checked="checked" ';
169 } else {
170 $checked = '';
171 }
172
173 $caps_table .= '<td class="checkbox">';
174 $role_cap_id = $rolekey.'-'.$capkey;
175 $caps_table .= '<input type="checkbox" name="' . $role_cap_id . '" id="' . $role_cap_id . '" ' . $checked . '/>';
176 $caps_table .= '</td>';
177 }
178 $caps_table .= '</tr>';
179 }
180 $caps_table .= '</tbody>';
181 $caps_table .= '</table>';
182
183 $delete_data = Groups_Options::get_option( 'groups_delete_data', false );
184
185 if ( isset( $_GET['dismiss-groups-extensions-box'] ) && isset( $_GET['groups-extensions-box-nonce'] ) && wp_verify_nonce( $_GET['groups-extensions-box-nonce'], 'dismiss-box' ) ) {
186 Groups_Options::update_user_option( 'show-extensions-box', false );
187 }
188 $extensions_box = '';
189 if ( Groups_Options::get_user_option( 'show-extensions-box', true ) ) {
190 $dismiss_url = wp_nonce_url( add_query_arg( 'dismiss-groups-extensions-box', '1', admin_url( 'admin.php?page=groups-admin-options' ) ), 'dismiss-box', 'groups-extensions-box-nonce' );
191 $extensions_box =
192 '<div id="groups-extensions-box">' .
193 __( 'Enhanced functionality is available via official <a href="http://www.itthinx.com/shop/">Extensions</a> for Groups.', GROUPS_PLUGIN_DOMAIN ) .
194 sprintf( '<a class="close" href="%s">x</a>', esc_url( $dismiss_url ) ) .
195 '</div>';
196 }
197
198 //
199 // print the options form
200 //
201 echo
202 '<form action="" name="options" method="post">' .
203
204 '<p>' .
205 '<input class="button button-primary" type="submit" name="submit" value="' . __( 'Save', GROUPS_PLUGIN_DOMAIN ) . '"/>' .
206 $extensions_box .
207 '</p>' .
208
209 '<div>' .
210 '<h2>' . __( 'Administrator Access Override', GROUPS_PLUGIN_DOMAIN ) . '</h2>' .
211 '<p>' .
212 '<label>' .
213 '<input name="' . GROUPS_ADMINISTRATOR_ACCESS_OVERRIDE . '" type="checkbox" ' . ( $admin_override ? 'checked="checked"' : '' ) . '/>' .
214 __( 'Administrators override all access permissions derived from Groups capabilities.', GROUPS_PLUGIN_DOMAIN ) .
215 '</label>' .
216 '</p>';
217
218 echo '<h2>' . __( 'Access restricions', GROUPS_PLUGIN_DOMAIN ) . '</h2>';
219
220 echo '<h3>' . __( 'Post types', GROUPS_PLUGIN_DOMAIN ) . '</h3>';
221
222 echo
223 '<p class="description">' . __( 'Show access restrictions for these post types.', GROUPS_PLUGIN_DOMAIN ) . '</p>';
224
225 $post_types_option = Groups_Options::get_option( Groups_Post_Access::POST_TYPES, array() );
226 $post_types = get_post_types( array( 'public' => true ) );
227 echo '<ul>';
228 foreach( $post_types as $post_type ) {
229 $post_type_object = get_post_type_object( $post_type );
230 echo '<li>';
231 echo '<label>';
232 $label = $post_type;
233 $labels = isset( $post_type_object->labels ) ? $post_type_object->labels : null;
234 if ( ( $labels !== null ) && isset( $labels->singular_name ) ) {
235 $label = __( $labels->singular_name );
236 }
237 $checked = ( !isset( $post_types_option[$post_type]['add_meta_box'] ) || $post_types_option[$post_type]['add_meta_box'] ) ? ' checked="checked" ' : '';
238 echo '<input name="add_meta_boxes[]" type="checkbox" value="' . esc_attr( $post_type ) . '" ' . $checked . '/>';
239 echo $label;
240 echo '</label>';
241 echo '</li>';
242 }
243 echo '<ul>';
244 echo
245 '<p class="description">' .
246 __( 'This determines for which post types access restriction settings are offered.', GROUPS_PLUGIN_DOMAIN ) . '<br/>' .
247 __( 'Disabling this setting for a post type does not remove existing access restrictions on individual posts of that type.', GROUPS_PLUGIN_DOMAIN ) . '<br/>' .
248 '</p>';
249
250
251 echo '<h3>' . __( 'Capabilities', GROUPS_PLUGIN_DOMAIN ) . '</h3>';
252
253 echo '<p class="description">' .
254 __( 'Include these capabilities to enforce read access on posts. The selected capabilities will be offered to restrict access to posts.', GROUPS_PLUGIN_DOMAIN ) .
255 '</p>';
256
257 $capability_table = _groups_get_tablename( "capability" );
258 $capabilities = $wpdb->get_results( "SELECT * FROM $capability_table ORDER BY capability" );
259 $applicable_read_caps = Groups_Options::get_option( Groups_Post_Access::READ_POST_CAPABILITIES, array( Groups_Post_Access::READ_POST_CAPABILITY ) );
260 echo '<div class="select-capability-container" style="width:62%;">';
261 printf( '<select class="select capability" name="%s" multiple="multiple">', GROUPS_READ_POST_CAPABILITIES . '[]' );
262 foreach( $capabilities as $capability ) {
263 $selected = in_array( $capability->capability, $applicable_read_caps ) ? ' selected="selected" ' : '';
264 if ( $capability->capability == Groups_Post_Access::READ_POST_CAPABILITY ) {
265 $selected .= ' disabled="disabled" ';
266 }
267 printf( '<option value="%s" %s>%s</option>', esc_attr( $capability->capability_id ), $selected, wp_filter_nohtml_kses( $capability->capability ) );
268 }
269 echo '</select>';
270 echo '</div>';
271
272 echo Groups_UIE::render_select( '.select.capability' );
273
274 echo
275 '<h2>' . __( 'User profiles', GROUPS_PLUGIN_DOMAIN ) . '</h2>' .
276 '<p>' .
277 '<label>' .
278 '<input name="' . GROUPS_SHOW_IN_USER_PROFILE . '" type="checkbox" ' . ( $show_in_user_profile ? 'checked="checked"' : '' ) . '/>' .
279 __( 'Show groups in user profiles.', GROUPS_PLUGIN_DOMAIN ) .
280 '</label>' .
281 '</p>';
282
283 echo
284 '<h2>' . __( 'Tree view', GROUPS_PLUGIN_DOMAIN ) . '</h2>' .
285 '<p>' .
286 '<label>' .
287 '<input name="' . GROUPS_SHOW_TREE_VIEW . '" type="checkbox" ' . ( $show_tree_view ? 'checked="checked"' : '' ) . '/>' .
288 __( 'Show the Groups tree view.', GROUPS_PLUGIN_DOMAIN ) .
289 '</label>' .
290 '</p>';
291
292 echo
293 '<h2>' . __( 'Permissions', GROUPS_PLUGIN_DOMAIN ) . '</h2>' .
294 '<p>' . __( 'These permissions apply to Groups management. They do not apply to access permissions derived from Groups capabilities.', GROUPS_PLUGIN_DOMAIN ) . '</p>' .
295 $caps_table .
296 '<p class="description">' .
297 __( 'A minimum set of permissions will be preserved.', GROUPS_PLUGIN_DOMAIN ) .
298 '<br/>' .
299 __( 'If you lock yourself out, please ask an administrator to help.', GROUPS_PLUGIN_DOMAIN ) .
300 '</p>';
301 if ( !$is_sitewide_plugin ) {
302 echo
303 '<h2>' . __( 'Deactivation and data persistence', GROUPS_PLUGIN_DOMAIN ) . '</h2>' .
304 '<p>' .
305 '<label>' .
306 '<input name="delete-data" type="checkbox" ' . ( $delete_data ? 'checked="checked"' : '' ) . '/>' .
307 __( 'Delete all Groups plugin data on deactivation', GROUPS_PLUGIN_DOMAIN ) .
308 '</label>' .
309 '</p>' .
310 '<p class="description warning">' .
311 __( 'CAUTION: If this option is active while the plugin is deactivated, ALL plugin settings and data will be DELETED. If you are going to use this option, now would be a good time to make a backup. By enabling this option you agree to be solely responsible for any loss of data or any other consequences thereof.', GROUPS_PLUGIN_DOMAIN ) .
312 '</p>';
313 }
314 echo
315 '<p>' .
316 wp_nonce_field( 'admin', GROUPS_ADMIN_OPTIONS_NONCE, true, false ) .
317 '<input class="button button-primary" type="submit" name="submit" value="' . __( 'Save', GROUPS_PLUGIN_DOMAIN ) . '"/>' .
318 '</p>' .
319 '</div>' .
320 '</form>';
321
322 echo '</div>'; // .groups-options
323 }
324
325 function groups_network_admin_options() {
326
327 if ( !current_user_can( GROUPS_ADMINISTER_OPTIONS ) ) {
328 wp_die( __( 'Access denied.', GROUPS_PLUGIN_DOMAIN ) );
329 }
330
331 echo
332 '<div>' .
333 '<h1>' .
334 __( 'Groups network options', GROUPS_PLUGIN_DOMAIN ) .
335 '</h1>' .
336 '</div>';
337
338 // handle options form submission
339 if ( isset( $_POST['submit'] ) ) {
340 if ( wp_verify_nonce( $_POST[GROUPS_ADMIN_OPTIONS_NONCE], 'admin' ) ) {
341 // delete data
342 if ( !empty( $_POST['delete-data'] ) ) {
343 Groups_Options::update_option( 'groups_network_delete_data', true );
344 } else {
345 Groups_Options::update_option( 'groups_network_delete_data', false );
346 }
347 }
348 }
349
350 $delete_data = Groups_Options::get_option( 'groups_network_delete_data', false );
351
352 // options form
353 echo
354 '<form action="" name="options" method="post">' .
355 '<div>' .
356 '<h2>' . __( 'Network deactivation and data persistence', GROUPS_PLUGIN_DOMAIN ) . '</h2>' .
357 '<p>' .
358 '<input name="delete-data" type="checkbox" ' . ( $delete_data ? 'checked="checked"' : '' ) . '/>' .
359 '<label for="delete-data">' . __( 'Delete all Groups plugin data for ALL sites on network deactivation', GROUPS_PLUGIN_DOMAIN ) . '</label>' .
360 '</p>' .
361 '<p class="description warning">' .
362 __( 'CAUTION: If this option is active while the plugin is deactivated, ALL plugin settings and data will be DELETED for <strong>all sites</strong>. If you are going to use this option, now would be a good time to make a backup. By enabling this option you agree to be solely responsible for any loss of data or any other consequences thereof.', GROUPS_PLUGIN_DOMAIN ) .
363 '</p>' .
364 '<p>' .
365 wp_nonce_field( 'admin', GROUPS_ADMIN_OPTIONS_NONCE, true, false ) .
366 '<input type="submit" name="submit" value="' . __( 'Save', GROUPS_PLUGIN_DOMAIN ) . '"/>' .
367 '</p>' .
368 '</div>' .
369 '</form>';
370 }