PluginProbe
Groups – Memberships and Access Control / trunk
Groups – Memberships and Access Control vtrunk
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 1.13.1 1.2.0 All 129 releases
groups / lib / admin / groups-admin-groups-remove.php

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

192 lines 6.4 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 *
29 * @param int $group_id group id
30 */
31 function groups_admin_groups_remove( $group_id ) {
32
33 if ( !Groups_User::current_user_can( GROUPS_ADMINISTER_GROUPS ) ) {
34 wp_die( esc_html__( 'Access denied.', 'groups' ) );
35 }
36
37 $group = Groups_Group::read( intval( $group_id ) );
38
39 if ( empty( $group ) ) { // @phpstan-ignore empty.variable
40 wp_die( esc_html__( 'No such group.', 'groups' ) );
41 }
42
43 $current_url = groups_get_current_url();
44 $current_url = remove_query_arg( 'action', $current_url );
45 $current_url = remove_query_arg( 'group_id', $current_url );
46
47 $output = '<div class="manage-groups wrap">';
48 $output .= '<h1>';
49 $output .= esc_html__( 'Remove a group', 'groups' );
50 $output .= '</h1>';
51 $output .= sprintf( '<form id="remove-group" action="%s" method="post">', esc_url( $current_url ) );
52 $output .= '<div class="group remove">';
53 $output .= sprintf( '<input id="group-id-field" name="group-id-field" type="hidden" value="%s"/>', esc_attr( intval( $group->group_id ) ) );
54 $output .= '<ul>';
55 $output .= '<li>';
56 $output .= sprintf( '%s : <strong>%s</strong> [%d]', esc_html__( 'Group', 'groups' ), stripslashes( wp_filter_nohtml_kses( $group->name ) ), esc_html( $group->group_id ) );
57 $output .= '</li>';
58 $output .= '</ul> ';
59 $output .= wp_nonce_field( 'groups-remove', GROUPS_ADMIN_GROUPS_NONCE, true, false );
60 $output .= sprintf( '<input class="button button-primary" type="submit" value="%s"/>', esc_attr__( 'Remove', 'groups' ) );
61 $output .= '<input type="hidden" value="remove" name="action"/>';
62 $output .= sprintf( '<a class="cancel button" href="%s">%s</a>', esc_url( $current_url ), esc_html__( 'Cancel', 'groups' ) );
63 $output .= '</div>'; // .group.remove
64 $output .= '</form>';
65 $output .= '</div>'; // .manage-groups
66
67 echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
68 } // function groups_admin_groups_remove
69
70 /**
71 * Handle remove form submission.
72 *
73 * @return int|false group ID if successful, otherwise false
74 */
75 function groups_admin_groups_remove_submit() {
76
77 $result = false;
78
79 if ( !Groups_User::current_user_can( GROUPS_ADMINISTER_GROUPS ) ) {
80 wp_die( esc_html__( 'Access denied.', 'groups' ) );
81 }
82
83 if ( !groups_verify_post_nonce( GROUPS_ADMIN_GROUPS_NONCE, 'groups-remove' ) ) {
84 wp_die( esc_html__( 'Access denied.', 'groups' ) );
85 }
86
87 $group_id = groups_sanitize_post( 'group-id-field' );
88 $group = Groups_Group::read( $group_id );
89 if ( $group ) {
90 if ( $group->name !== Groups_Registered::REGISTERED_GROUP_NAME ) {
91 $result = Groups_Group::delete( $group_id );
92 }
93 }
94 return $result;
95 } // function groups_admin_groups_remove_submit
96
97 /**
98 * Shows form to confirm bulk-removal of groups.
99 */
100 function groups_admin_groups_bulk_remove() {
101
102 $output = '';
103
104 if ( !Groups_User::current_user_can( GROUPS_ADMINISTER_GROUPS ) ) {
105 wp_die( esc_html__( 'Access denied.', 'groups' ) );
106 }
107
108 $group_ids = groups_sanitize_post( 'group_ids' );
109 if ( $group_ids === null || !is_array( $group_ids ) ) {
110 wp_die( esc_html__( 'No such groups.', 'groups' ) );
111 }
112
113 $groups = array();
114 foreach ( $group_ids as $group_id ) {
115 $group = Groups_Group::read( intval( $group_id ) );
116 if ( $group ) {
117 $groups[] = $group;
118 }
119 }
120
121 $current_url = groups_get_current_url();
122 $current_url = remove_query_arg( 'action', $current_url );
123 $current_url = remove_query_arg( 'group_id', $current_url );
124
125 $output .= '<div class="manage-groups wrap">';
126 $output .= '<h1>';
127 $output .= esc_html__( 'Remove groups', 'groups' );
128 $output .= '</h1>';
129
130 $output .= '<form id="groups-action" method="post" action="">';
131 $output .= '<div class="group remove">';
132
133 $output .= '<p>';
134 $output .= esc_html__( 'Please confirm removal of the following groups. This action cannot be undone.', 'groups' );
135 $output .= '</p>';
136
137 $output .= '<ul class="groups-group-bulk-remove">';
138 foreach ( $groups as $group ) {
139 $output .= sprintf( '<input id="group_ids" name="group_ids[]" type="hidden" value="%s"/>', esc_attr( intval( $group->group_id ) ) );
140 $output .= '<li>';
141 $output .= sprintf( '<strong>%s</strong> [%d]', stripslashes( wp_filter_nohtml_kses( $group->name ) ), esc_html( $group->group_id ) );
142 $output .= '</li>';
143 }
144 $output .= '</ul>';
145 $output .= sprintf( '<input class="button button-primary" type="submit" name="bulk" value="%s"/>', esc_attr__( 'Remove', 'groups' ) );
146 $output .= sprintf( '<a class="cancel button" href="%s">%s</a>', esc_url( $current_url ), esc_html__( 'Cancel', 'groups' ) );
147
148 $output .= '<input type="hidden" name="action" value="groups-action"/>';
149 $output .= '<input type="hidden" name="bulk-action" value="remove-group"/>';
150 $output .= '<input type="hidden" name="confirm" value="1"/>';
151 $output .= wp_nonce_field( 'admin', GROUPS_ADMIN_GROUPS_ACTION_NONCE, true, false );
152
153 $output .= '</div>';
154 $output .= '</form>';
155 $output .= '</div>';
156
157 echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
158 } // function groups_admin_groups_bulk_remove
159
160 /**
161 * Handle remove form submission.
162 *
163 * @return array of deleted groups' ids
164 */
165 function groups_admin_groups_bulk_remove_submit() {
166
167 $result = array();
168 if ( !Groups_User::current_user_can( GROUPS_ADMINISTER_GROUPS ) ) {
169 wp_die( esc_html__( 'Access denied.', 'groups' ) );
170 }
171
172 if ( !groups_verify_post_nonce( GROUPS_ADMIN_GROUPS_ACTION_NONCE, 'admin' ) ) {
173 wp_die( esc_html__( 'Access denied.', 'groups' ) );
174 }
175
176 $group_ids = groups_sanitize_post( 'group_ids' );
177 if ( $group_ids !== null && is_array( $group_ids ) ) {
178 foreach ( $group_ids as $group_id ) {
179 $group = Groups_Group::read( $group_id );
180 if ( $group ) {
181 if ( $group->name !== Groups_Registered::REGISTERED_GROUP_NAME ) {
182 if ( Groups_Group::delete( $group_id ) ) {
183 $result[] = $group->group_id;
184 }
185 }
186 }
187 }
188 }
189
190 return $result;
191 } // function groups_admin_groups_bulk_remove_submit
192