'; $output .= '

'; $output .= esc_html__( 'Remove a group', 'groups' ); $output .= '

'; $output .= sprintf( '
', esc_url( $current_url ) ); $output .= '
'; $output .= sprintf( '', esc_attr( intval( $group->group_id ) ) ); $output .= ' '; $output .= wp_nonce_field( 'groups-remove', GROUPS_ADMIN_GROUPS_NONCE, true, false ); $output .= sprintf( '', esc_attr__( 'Remove', 'groups' ) ); $output .= ''; $output .= sprintf( '%s', esc_url( $current_url ), esc_html__( 'Cancel', 'groups' ) ); $output .= '
'; // .group.remove $output .= '
'; $output .= ''; // .manage-groups echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } // function groups_admin_groups_remove /** * Handle remove form submission. * * @return int|false group ID if successful, otherwise false */ function groups_admin_groups_remove_submit() { $result = false; if ( !Groups_User::current_user_can( GROUPS_ADMINISTER_GROUPS ) ) { wp_die( esc_html__( 'Access denied.', 'groups' ) ); } if ( !groups_verify_post_nonce( GROUPS_ADMIN_GROUPS_NONCE, 'groups-remove' ) ) { wp_die( esc_html__( 'Access denied.', 'groups' ) ); } $group_id = groups_sanitize_post( 'group-id-field' ); $group = Groups_Group::read( $group_id ); if ( $group ) { if ( $group->name !== Groups_Registered::REGISTERED_GROUP_NAME ) { $result = Groups_Group::delete( $group_id ); } } return $result; } // function groups_admin_groups_remove_submit /** * Shows form to confirm bulk-removal of groups. */ function groups_admin_groups_bulk_remove() { $output = ''; if ( !Groups_User::current_user_can( GROUPS_ADMINISTER_GROUPS ) ) { wp_die( esc_html__( 'Access denied.', 'groups' ) ); } $group_ids = groups_sanitize_post( 'group_ids' ); if ( $group_ids === null || !is_array( $group_ids ) ) { wp_die( esc_html__( 'No such groups.', 'groups' ) ); } $groups = array(); foreach ( $group_ids as $group_id ) { $group = Groups_Group::read( intval( $group_id ) ); if ( $group ) { $groups[] = $group; } } $current_url = groups_get_current_url(); $current_url = remove_query_arg( 'action', $current_url ); $current_url = remove_query_arg( 'group_id', $current_url ); $output .= '
'; $output .= '

'; $output .= esc_html__( 'Remove groups', 'groups' ); $output .= '

'; $output .= '
'; $output .= '
'; $output .= '

'; $output .= esc_html__( 'Please confirm removal of the following groups. This action cannot be undone.', 'groups' ); $output .= '

'; $output .= '
    '; foreach ( $groups as $group ) { $output .= sprintf( '', esc_attr( intval( $group->group_id ) ) ); $output .= '
  • '; $output .= sprintf( '%s [%d]', stripslashes( wp_filter_nohtml_kses( $group->name ) ), esc_html( $group->group_id ) ); $output .= '
  • '; } $output .= '
'; $output .= sprintf( '', esc_attr__( 'Remove', 'groups' ) ); $output .= sprintf( '%s', esc_url( $current_url ), esc_html__( 'Cancel', 'groups' ) ); $output .= ''; $output .= ''; $output .= ''; $output .= wp_nonce_field( 'admin', GROUPS_ADMIN_GROUPS_ACTION_NONCE, true, false ); $output .= '
'; $output .= '
'; $output .= '
'; echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } // function groups_admin_groups_bulk_remove /** * Handle remove form submission. * * @return array of deleted groups' ids */ function groups_admin_groups_bulk_remove_submit() { $result = array(); if ( !Groups_User::current_user_can( GROUPS_ADMINISTER_GROUPS ) ) { wp_die( esc_html__( 'Access denied.', 'groups' ) ); } if ( !groups_verify_post_nonce( GROUPS_ADMIN_GROUPS_ACTION_NONCE, 'admin' ) ) { wp_die( esc_html__( 'Access denied.', 'groups' ) ); } $group_ids = groups_sanitize_post( 'group_ids' ); if ( $group_ids !== null && is_array( $group_ids ) ) { foreach ( $group_ids as $group_id ) { $group = Groups_Group::read( $group_id ); if ( $group ) { if ( $group->name !== Groups_Registered::REGISTERED_GROUP_NAME ) { if ( Groups_Group::delete( $group_id ) ) { $result[] = $group->group_id; } } } } } return $result; } // function groups_admin_groups_bulk_remove_submit