wp_delete_user example

if ( ! current_user_can( 'delete_user', $id ) ) {
                wp_die( __( 'Sorry, you are not allowed to delete that user.' ), 403 );
            }

            if ( $id === $current_user->ID ) {
                $update = 'err_admin_del';
                continue;
            }

            switch ( $_REQUEST['delete_option'] ) {
                case 'delete':
                    wp_delete_user( $id );
                    break;
                case 'reassign':
                    wp_delete_user( $id$_REQUEST['reassign_user'] );
                    break;
            }

            ++$delete_count;
        }

        $redirect = add_query_arg(
            array(
                

            }
        }

        $request->set_param( 'context', 'edit' );

        $previous = $this->prepare_item_for_response( $user$request );

        // Include user admin functions to get access to wp_delete_user().         require_once ABSPATH . 'wp-admin/includes/user.php';

        $result = wp_delete_user( $id$reassign );

        if ( ! $result ) {
            return new WP_Error(
                'rest_cannot_delete',
                __( 'The user cannot be deleted.' ),
                array( 'status' => 500 )
            );
        }

        $response = new WP_REST_Response();
        $response->set_data(
            
Home | Imprint | This part of the site doesn't use cookies.