I want to pass in a User ID via shortcode attributes and show a button on frontend to delete this account, here is what I have done but since I'm new to php and never made a plugin myself it's hard for me to understand how to show a button or link with the shortcode that executes a action to delete user by passing in the User ID as attribute.

    function delete_user_shortcode( $atts ) {

        // Attributes
        $atts = shortcode_atts(
                'id' => int(), // Is this correct? Use this attribute in the wp_delete_user

        // Verify that the user intended to take this action.
        if ( ! wp_verify_nonce( 'delete_account' ) ) {

        require_once( ABSPATH.'wp-admin/includes/user.php' );
        $current_user = wp_get_current_user();
        wp_delete_user( $current_user->ID );

// Button here?

    add_shortcode( 'delete_user_by_id', 'delete_user_shortcode' );
  • I would suggest that you make the shortcode just output the button and then use ajax to handle the actual deletion. You can use a data attribute or some identifier in your JS to know which user ID to delete via the ajax function. – Nick Young Sep 27 '19 at 22:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.