-
Notifications
You must be signed in to change notification settings - Fork 382
Expand file tree
/
Copy pathdelete-group.php
More file actions
38 lines (32 loc) · 1021 Bytes
/
delete-group.php
File metadata and controls
38 lines (32 loc) · 1021 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
// Get the group to delete
if ( isset( $_REQUEST['delete_name'] ) ) {
$delete_name = sanitize_text_field( $_REQUEST['delete_name'] );
// Get the current settings.
$current_settings = pmpro_get_user_fields_settings();
// Remove the group from the settings.
$new_settings = array();
$deleted = false;
foreach ( $current_settings as $group_setting ) {
if ( $group_setting->name === $delete_name ) {
$deleted = true;
} else {
$new_settings[] = $group_setting;
}
}
if ( $deleted ) {
// Save the new settings.
update_option( 'pmpro_user_fields_settings', $new_settings );
// Show a success message.
pmpro_setMessage( __( 'Group deleted.', 'paid-memberships-pro' ), 'success' );
// Redirect with javascript.
?>
<script>
window.location.href = '?page=pmpro-userfields&success_message=<?php echo urlencode( __( 'Group deleted.', 'paid-memberships-pro' ) ); ?>';
</script>
<?php
exit;
} else {
pmpro_setMessage( __( 'Group not found.', 'paid-memberships-pro' ), -1 );
}
}