PluginProbe
Groups – Memberships and Access Control / 1.1.4
Groups – Memberships and Access Control v1.1.4
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.1.4, at lib/admin/groups-admin-options.php

244 lines 8.7 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 /**
23 * @var string options form nonce name
24 */
25 define( 'GROUPS_ADMIN_OPTIONS_NONCE', 'groups-admin-nonce' );
26
27 function groups_admin_options() {
28
29 global $wpdb, $wp_roles;
30
31 if ( !current_user_can( GROUPS_ADMINISTER_OPTIONS ) ) {
32 wp_die( __( 'Access denied.', GROUPS_PLUGIN_DOMAIN ) );
33 }
34
35 $is_sitewide_plugin = false;
36 if ( is_multisite() ) {
37 $active_sitewide_plugins = get_site_option( 'active_sitewide_plugins', array() );
38 $active_sitewide_plugins = array_keys( $active_sitewide_plugins );
39 $is_sitewide_plugin = in_array( 'groups/groups.php', $active_sitewide_plugins );
40 }
41
42 echo
43 '<div>' .
44 '<h2>' .
45 __( 'Groups options', GROUPS_PLUGIN_DOMAIN ) .
46 '</h2>' .
47 '</div>';
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 // tree view
72 if ( !empty( $_POST[GROUPS_SHOW_TREE_VIEW] ) ) {
73 Groups_Options::update_option( GROUPS_SHOW_TREE_VIEW, true );
74 } else {
75 Groups_Options::update_option( GROUPS_SHOW_TREE_VIEW, false );
76 }
77
78 // roles & capabilities
79 $rolenames = $wp_roles->get_names();
80 foreach ( $rolenames as $rolekey => $rolename ) {
81 $role = $wp_roles->get_role( $rolekey );
82 foreach ( $caps as $capkey => $capname ) {
83 $role_cap_id = $rolekey.'-'.$capkey;
84 if ( !empty($_POST[$role_cap_id] ) ) {
85 $role->add_cap( $capkey );
86 } else {
87 $role->remove_cap( $capkey );
88 }
89 }
90 }
91 Groups_Controller::assure_capabilities();
92
93 if ( !$is_sitewide_plugin ) {
94 // delete data
95 if ( !empty( $_POST['delete-data'] ) ) {
96 Groups_Options::update_option( 'groups_delete_data', true );
97 } else {
98 Groups_Options::update_option( 'groups_delete_data', false );
99 }
100 }
101 }
102 }
103
104 $admin_override = get_option( GROUPS_ADMINISTRATOR_ACCESS_OVERRIDE, GROUPS_ADMINISTRATOR_ACCESS_OVERRIDE_DEFAULT );
105
106 $show_tree_view = Groups_Options::get_option( GROUPS_SHOW_TREE_VIEW, GROUPS_SHOW_TREE_VIEW_DEFAULT );
107
108 $rolenames = $wp_roles->get_names();
109 $caps_table = '<table class="groups-permissions">';
110 $caps_table .= '<thead>';
111 $caps_table .= '<tr>';
112 $caps_table .= '<td class="role">';
113 $caps_table .= __( 'Role', GROUPS_PLUGIN_DOMAIN );
114 $caps_table .= '</td>';
115 foreach ( $caps as $cap ) {
116 $caps_table .= '<td class="cap">';
117 $caps_table .= $cap;
118 $caps_table .= '</td>';
119 }
120
121 $caps_table .= '</tr>';
122 $caps_table .= '</thead>';
123 $caps_table .= '<tbody>';
124 foreach ( $rolenames as $rolekey => $rolename ) {
125 $role = $wp_roles->get_role( $rolekey );
126 $caps_table .= '<tr>';
127 $caps_table .= '<td>';
128 $caps_table .= translate_user_role( $rolename );
129 $caps_table .= '</td>';
130 foreach ( $caps as $capkey => $capname ) {
131
132 if ( $role->has_cap( $capkey ) ) {
133 $checked = ' checked="checked" ';
134 } else {
135 $checked = '';
136 }
137
138 $caps_table .= '<td class="checkbox">';
139 $role_cap_id = $rolekey.'-'.$capkey;
140 $caps_table .= '<input type="checkbox" name="' . $role_cap_id . '" id="' . $role_cap_id . '" ' . $checked . '/>';
141 $caps_table .= '</td>';
142 }
143 $caps_table .= '</tr>';
144 }
145 $caps_table .= '</tbody>';
146 $caps_table .= '</table>';
147
148 $delete_data = Groups_Options::get_option( 'groups_delete_data', false );
149
150 //
151 // print the options form
152 //
153 echo
154 '<form action="" name="options" method="post">' .
155 '<div>' .
156 '<h3>' . __( 'Administrator Access Override', GROUPS_PLUGIN_DOMAIN ) . '</h3>' .
157 '<p>' .
158 '<input name="' . GROUPS_ADMINISTRATOR_ACCESS_OVERRIDE . '" type="checkbox" ' . ( $admin_override ? 'checked="checked"' : '' ) . '/>' .
159 '<label for="' . GROUPS_ADMINISTRATOR_ACCESS_OVERRIDE . '">' . __( 'Administrators override all access permissions derived from Groups capabilities.', GROUPS_PLUGIN_DOMAIN ) . '</label>' .
160 '</p>';
161
162 echo
163 '<h3>' . __( 'Tree view', GROUPS_PLUGIN_DOMAIN ) . '</h3>' .
164 '<p>' .
165 '<input name="' . GROUPS_SHOW_TREE_VIEW . '" type="checkbox" ' . ( $show_tree_view ? 'checked="checked"' : '' ) . '/>' .
166 '<label for="' . GROUPS_SHOW_TREE_VIEW . '">' . __( 'Show the Groups tree view.', GROUPS_PLUGIN_DOMAIN ) . '</label>' .
167 '</p>';
168 echo
169 '<h3>' . __( 'Permissions', GROUPS_PLUGIN_DOMAIN ) . '</h3>' .
170 '<p>' . __( 'These permissions apply to Groups management. They do not apply to access permissions derived from Groups capabilities.', GROUPS_PLUGIN_DOMAIN ) . '</p>' .
171 $caps_table .
172 '<p class="description">' .
173 __( 'A minimum set of permissions will be preserved.', GROUPS_PLUGIN_DOMAIN ) .
174 '<br/>' .
175 __( 'If you lock yourself out, please ask an administrator to help.', GROUPS_PLUGIN_DOMAIN ) .
176 '</p>';
177 if ( !$is_sitewide_plugin ) {
178 echo
179 '<h3>' . __( 'Deactivation and data persistence', GROUPS_PLUGIN_DOMAIN ) . '</h3>' .
180 '<p>' .
181 '<input name="delete-data" type="checkbox" ' . ( $delete_data ? 'checked="checked"' : '' ) . '/>' .
182 '<label for="delete-data">' . __( 'Delete all Groups plugin data on deactivation', GROUPS_PLUGIN_DOMAIN ) . '</label>' .
183 '</p>' .
184 '<p class="description warning">' .
185 __( '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 ) .
186 '</p>';
187 }
188 echo
189 '<p>' .
190 wp_nonce_field( 'admin', GROUPS_ADMIN_OPTIONS_NONCE, true, false ) .
191 '<input type="submit" name="submit" value="' . __( 'Save', GROUPS_PLUGIN_DOMAIN ) . '"/>' .
192 '</p>' .
193 '</div>' .
194 '</form>';
195 Groups_Help::footer();
196 }
197
198 function groups_network_admin_options() {
199
200 if ( !current_user_can( GROUPS_ADMINISTER_OPTIONS ) ) {
201 wp_die( __( 'Access denied.', GROUPS_PLUGIN_DOMAIN ) );
202 }
203
204 echo
205 '<div>' .
206 '<h2>' .
207 __( 'Groups network options', GROUPS_PLUGIN_DOMAIN ) .
208 '</h2>' .
209 '</div>';
210
211 // handle options form submission
212 if ( isset( $_POST['submit'] ) ) {
213 if ( wp_verify_nonce( $_POST[GROUPS_ADMIN_OPTIONS_NONCE], 'admin' ) ) {
214 // delete data
215 if ( !empty( $_POST['delete-data'] ) ) {
216 Groups_Options::update_option( 'groups_network_delete_data', true );
217 } else {
218 Groups_Options::update_option( 'groups_network_delete_data', false );
219 }
220 }
221 }
222
223 $delete_data = Groups_Options::get_option( 'groups_network_delete_data', false );
224
225 // options form
226 echo
227 '<form action="" name="options" method="post">' .
228 '<div>' .
229 '<h3>' . __( 'Network deactivation and data persistence', GROUPS_PLUGIN_DOMAIN ) . '</h3>' .
230 '<p>' .
231 '<input name="delete-data" type="checkbox" ' . ( $delete_data ? 'checked="checked"' : '' ) . '/>' .
232 '<label for="delete-data">' . __( 'Delete all Groups plugin data for ALL sites on network deactivation', GROUPS_PLUGIN_DOMAIN ) . '</label>' .
233 '</p>' .
234 '<p class="description warning">' .
235 __( '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 ) .
236 '</p>' .
237 '<p>' .
238 wp_nonce_field( 'admin', GROUPS_ADMIN_OPTIONS_NONCE, true, false ) .
239 '<input type="submit" name="submit" value="' . __( 'Save', GROUPS_PLUGIN_DOMAIN ) . '"/>' .
240 '</p>' .
241 '</div>' .
242 '</form>';
243 Groups_Help::footer();
244 }