PluginProbe
Groups – Memberships and Access Control / 1.11.0
Groups – Memberships and Access Control v1.11.0
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-groups-remove.php

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

200 lines 6.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * groups-admin-groups-remove.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.1.0
20 */
21
22 if ( !defined( 'ABSPATH' ) ) {
23 exit;
24 }
25
26 /**
27 * Shows form to confirm removal of a group.
28 * @param int $group_id group id
29 */
30 function groups_admin_groups_remove( $group_id ) {
31
32 global $wpdb;
33
34 if ( !current_user_can( GROUPS_ADMINISTER_GROUPS ) ) {
35 wp_die( __( 'Access denied.', GROUPS_PLUGIN_DOMAIN ) );
36 }
37
38 $group = Groups_Group::read( intval( $group_id ) );
39
40 if ( empty( $group ) ) {
41 wp_die( __( 'No such group.', GROUPS_PLUGIN_DOMAIN ) );
42 }
43
44 $group_table = _groups_get_tablename( 'group' );
45
46 $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
47 $current_url = remove_query_arg( 'action', $current_url );
48 $current_url = remove_query_arg( 'group_id', $current_url );
49
50 $output =
51 '<div class="manage-groups wrap">' .
52 '<h1>' .
53 __( 'Remove a group', GROUPS_PLUGIN_DOMAIN ) .
54 '</h1>' .
55 '<form id="remove-group" action="' . esc_url( $current_url ) . '" method="post">' .
56 '<div class="group remove">' .
57 '<input id="group-id-field" name="group-id-field" type="hidden" value="' . esc_attr( intval( $group->group_id ) ) . '"/>' .
58 '<ul>' .
59 '<li>' . sprintf( __( 'Group Name : %s', GROUPS_PLUGIN_DOMAIN ), stripslashes( wp_filter_nohtml_kses( $group->name ) ) ) . '</li>' .
60 '</ul> ' .
61 wp_nonce_field( 'groups-remove', GROUPS_ADMIN_GROUPS_NONCE, true, false ) .
62 '<input class="button button-primary" type="submit" value="' . __( 'Remove', GROUPS_PLUGIN_DOMAIN ) . '"/>' .
63 '<input type="hidden" value="remove" name="action"/>' .
64 '<a class="cancel button" href="' . esc_url( $current_url ) . '">' . __( 'Cancel', GROUPS_PLUGIN_DOMAIN ) . '</a>' .
65 '</div>' .
66 '</div>' . // .group.remove
67 '</form>' .
68 '</div>'; // .manage-groups
69
70 echo $output;
71 } // function groups_admin_groups_remove
72
73 /**
74 * Handle remove form submission.
75 */
76 function groups_admin_groups_remove_submit() {
77
78 global $wpdb;
79
80 $result = false;
81
82 if ( !current_user_can( GROUPS_ADMINISTER_GROUPS ) ) {
83 wp_die( __( 'Access denied.', GROUPS_PLUGIN_DOMAIN ) );
84 }
85
86 if ( !wp_verify_nonce( $_POST[GROUPS_ADMIN_GROUPS_NONCE], 'groups-remove' ) ) {
87 wp_die( __( 'Access denied.', GROUPS_PLUGIN_DOMAIN ) );
88 }
89
90 $group_id = isset( $_POST['group-id-field'] ) ? $_POST['group-id-field'] : null;
91 $group = Groups_Group::read( $group_id );
92 if ( $group ) {
93 if ( $group->name !== Groups_Registered::REGISTERED_GROUP_NAME ) {
94 $result = Groups_Group::delete( $group_id );
95 }
96 }
97 return $result;
98 } // function groups_admin_groups_remove_submit
99
100 /**
101 * Shows form to confirm bulk-removal of groups.
102 */
103 function groups_admin_groups_bulk_remove() {
104
105 global $wpdb;
106
107 $output = '';
108
109 if ( !current_user_can( GROUPS_ADMINISTER_GROUPS ) ) {
110 wp_die( __( 'Access denied.', GROUPS_PLUGIN_DOMAIN ) );
111 }
112
113 $group_ids = isset( $_POST['group_ids'] ) ? $_POST['group_ids'] : null;
114
115 if ( ! $group_ids ) {
116 wp_die( __( 'No such groups.', GROUPS_PLUGIN_DOMAIN ) );
117 }
118
119 $groups = array();
120 foreach ( $group_ids as $group_id ) {
121 $group = Groups_Group::read( intval( $group_id ) );
122 if ( $group ) {
123 $groups[] = $group;
124 }
125 }
126
127 $group_table = _groups_get_tablename( 'group' );
128
129 $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
130 $current_url = remove_query_arg( 'action', $current_url );
131 $current_url = remove_query_arg( 'group_id', $current_url );
132
133 $output .= '<div class="manage-groups wrap">';
134 $output .= '<h1>';
135 $output .= __( 'Remove groups', GROUPS_PLUGIN_DOMAIN );
136 $output .= '</h1>';
137
138 $output .= '<form id="groups-action" method="post" action="">';
139 $output .= '<div class="group remove">';
140
141 $output .= '<p>';
142 $output .= __( 'Please confirm removal of the following groups. This action cannot be undone.', GROUPS_PLUGIN_DOMAIN );
143 $output .= '</p>';
144
145 foreach ( $groups as $group ) {
146 $output .= '<input id="group_ids" name="group_ids[]" type="hidden" value="' . esc_attr( intval( $group->group_id ) ) . '"/>';
147 $output .= '<ul>';
148 $output .= '<li>';
149 $output .= sprintf( __( '<strong>%s</strong>', GROUPS_PLUGIN_DOMAIN ), wp_filter_nohtml_kses( $group->name ) );
150 $output .= '</li>';
151 $output .= '</ul>';
152 }
153 $output .= '<input class="button button-primary" type="submit" name="bulk" value="' . __( "Remove", GROUPS_PLUGIN_DOMAIN ) . '"/>';
154 $output .= '<a class="cancel button" href="' . esc_url( $current_url ) . '">' . __( 'Cancel', GROUPS_PLUGIN_DOMAIN ) . '</a>';
155
156 $output .= '<input type="hidden" name="action" value="groups-action"/>';
157 $output .= '<input type="hidden" name="bulk-action" value="remove-group"/>';
158 $output .= '<input type="hidden" name="confirm" value="1"/>';
159 $output .= wp_nonce_field( 'admin', GROUPS_ADMIN_GROUPS_ACTION_NONCE, true, false );
160
161 $output .= '</div>';
162 $output .= '</form>';
163 $output .= '</div>';
164
165 echo $output;
166 } // function groups_admin_groups_bulk_remove
167
168 /**
169 * Handle remove form submission.
170 * @return array of deleted groups' ids
171 */
172 function groups_admin_groups_bulk_remove_submit() {
173 global $wpdb;
174
175 $result = array();
176 if ( !current_user_can( GROUPS_ADMINISTER_GROUPS ) ) {
177 wp_die( __( 'Access denied.', GROUPS_PLUGIN_DOMAIN ) );
178 }
179
180 if ( !wp_verify_nonce( $_POST[GROUPS_ADMIN_GROUPS_ACTION_NONCE], 'admin' ) ) {
181 wp_die( __( 'Access denied.', GROUPS_PLUGIN_DOMAIN ) );
182 }
183
184 $group_ids = isset( $_POST['group_ids'] ) ? $_POST['group_ids'] : null;
185 if ( $group_ids ) {
186 foreach ( $group_ids as $group_id ) {
187 $group = Groups_Group::read( $group_id );
188 if ( $group ) {
189 if ( $group->name !== Groups_Registered::REGISTERED_GROUP_NAME ) {
190 if ( Groups_Group::delete( $group_id ) ) {
191 $result[] = $group->group_id;
192 }
193 }
194 }
195 }
196 }
197
198 return $result;
199 } // function groups_admin_groups_bulk_remove_submit
200