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

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