Advertisements

wpmu_delete_blog

Definition:
function wpmu_delete_blog( $blog_id, $drop = false ) {}

Delete a blog

Parameters

  • int $blog_id: Blog ID
  • bool $drop: True if blog’s table should be dropped. Default is false.

Defined filters

  • wpmu_drop_tables
    apply_filters( 'wpmu_drop_tables', $drop_tables )
  • wpmu_delete_blog_upload_dir
    apply_filters( 'wpmu_delete_blog_upload_dir', WP_CONTENT_DIR . "/blogs.dir/{$blog_id}/files/", $blog_id )

Defined actions

  • delete_blog
    do_action( 'delete_blog', $blog_id, $drop );

Source code

function wpmu_delete_blog( $blog_id, $drop = false ) {

	global $wpdb;



	$switch = false;

	if ( $blog_id != $wpdb->blogid ) {

		$switch = true;

		switch_to_blog( $blog_id );

	}



	$blog_prefix = $wpdb->get_blog_prefix( $blog_id );



	do_action( 'delete_blog', $blog_id, $drop );



	$users = get_users( array( 'blog_id' => $blog_id, 'fields' => 'ids' ) );



	// Remove users from this blog.

	if ( ! empty( $users ) ) {

		foreach ( $users as $user_id ) {

			remove_user_from_blog( $user_id, $blog_id) ;

		}

	}



	update_blog_status( $blog_id, 'deleted', 1 );



	if ( $drop ) {

		if ( substr( $blog_prefix, -1 ) == '_' )

			$blog_prefix =  substr( $blog_prefix, 0, -1 ) . '\_';



		$drop_tables = $wpdb->get_results( "SHOW TABLES LIKE '{$blog_prefix}%'", ARRAY_A );

		$drop_tables = apply_filters( 'wpmu_drop_tables', $drop_tables );



		reset( $drop_tables );

		foreach ( (array) $drop_tables as $drop_table) {

			$wpdb->query( "DROP TABLE IF EXISTS ". current( $drop_table ) ."" );

		}

		$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->blogs WHERE blog_id = %d", $blog_id ) );

		$dir = apply_filters( 'wpmu_delete_blog_upload_dir', WP_CONTENT_DIR . "/blogs.dir/{$blog_id}/files/", $blog_id );

3381

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: