Advertisements

wpmu_delete_user

Definition:
function wpmu_delete_user( $id ) {}

Parameters

  • $id

Defined actions

  • wpmu_delete_user
    do_action( 'wpmu_delete_user', $id );
  • deleted_user
    do_action( 'deleted_user', $id );

Source code

function wpmu_delete_user( $id ) {

	global $wpdb;



	$id = (int) $id;



	do_action( 'wpmu_delete_user', $id );



	$blogs = get_blogs_of_user( $id );



	if ( ! empty( $blogs ) ) {

		foreach ( $blogs as $blog ) {

			switch_to_blog( $blog->userblog_id );

			remove_user_from_blog( $id, $blog->userblog_id );



			$post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_author = %d", $id ) );

			foreach ( (array) $post_ids as $post_id ) {

				wp_delete_post( $post_id );

			}



			// Clean links

			$link_ids = $wpdb->get_col( $wpdb->prepare( "SELECT link_id FROM $wpdb->links WHERE link_owner = %d", $id ) );



			if ( $link_ids ) {

				foreach ( $link_ids as $link_id )

					wp_delete_link( $link_id );

			}



			restore_current_blog();

		}

	}



	$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->users WHERE ID = %d", $id ) );

	$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->usermeta WHERE user_id = %d", $id ) );



	clean_user_cache( $id );



	// allow for commit transaction

	do_action( 'deleted_user', $id );



	return true;

}

3383

Advertisements

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: