0

I'm writing a function that will delete all blogs (except the main one) from a multisite, the function is dieing whenever I call wpmu_delete_blog and I've got no idea why.

$blogs = wp_get_sites( array('limit' => 0) );
array_shift($blogs); # removes first blog from the list
foreach ( $blogs as $blog ) {
    $blog_id = $blog['blog_id'];
    wpmu_delete_blog( $blog_id, true);
}

Really I just need to run this one time, I was trying to write a php script, load wordpress (which is done successfully and recognizes the script as admin). I also tried adding this to my blog-specific plugin and it failed in the same way.

I even added a print statement to the first line of wpmu_delete_blog, the print statement doesn't get executed and the script dies when it tries to call this function.

0

I was able to get a work around in place. Since I was deleting all blogs with no user interaction. I created two mysql queries and ran them. The first was to drop all tables associated with the given $blog_id the second was to remove that row from the wp_blogs table.

$blogs = wp_get_sites( array('limit' => 0) );
array_shift($blogs); # removes first blog from the list
global $wpdb;
foreach ( $blogs as $blog ) {
    $blog_id = $blog['blog_id'];

    $query = "DROP TABLES ";
    $query = "wp_{$blog_id}_commentmeta, ";
    $query = "wp_{$blog_id}_comments, ";
    $query = "wp_{$blog_id}_links, ";
    $query = "wp_{$blog_id}_options, ";
    $query = "wp_{$blog_id}_postmeta, ";
    $query = "wp_{$blog_id}_posts, ";
    $query = "wp_{$blog_id}_term_relationships, ";
    $query = "wp_{$blog_id}_term_taxonomy, ";
    $query = "wp_{$blog_id}_terms, ";

    $wpdb->query( $query );
    $wpdb->delete('wp_blogs', array( 'blog_id' => $blog_id ), array( '%d' ) );
}
| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.