4

When the WordPress Network Update script runs, if it gets to a site it "cannot resolve", the script stops there, and no sites are updated period. So if there is 1 site in a 1000 site MultiSite install that won't resolve (ie: domain expired) you cannot roll-out the update to any sites in your Network. You can of course go into Network admin and remove the site, but sometimes you don't have time, or you know the domain will be renewed (especially if it's your own domain).

I was once pointed to a work-around for this. But alas, no amount of Google searching has helped me find it again.

Does anyone know how to achieve this?

1
  • In a case like this, it's better to search directly in the Core :)
    – brasofilo
    Commented Oct 22, 2012 at 11:02

1 Answer 1

1

I'd say that's not possible to hook into that...

Here's the relevant part from /wp-admin/network/upgrade.php:

$blogs = $wpdb->get_results( "SELECT * FROM {$wpdb->blogs} WHERE site_id = '{$wpdb->siteid}' AND spam = '0' AND deleted = '0' AND archived = '0' ORDER BY registered DESC LIMIT {$n}, 5", ARRAY_A );
if ( empty( $blogs ) ) {
    echo '<p>' . __( 'All done!' ) . '</p>';
    break;
}
echo "<ul>";
foreach ( (array) $blogs as $details ) {
    $siteurl = get_blog_option( $details['blog_id'], 'siteurl' );
    echo "<li>$siteurl</li>";
    $response = wp_remote_get( trailingslashit( $siteurl ) . "wp-admin/upgrade.php?step=upgrade_db", array( 'timeout' => 120, 'httpversion' => '1.1' ) );
    if ( is_wp_error( $response ) )
        wp_die( sprintf( __( 'Warning! Problem updating %1$s. Your server may not be able to connect to sites running on it. Error message: <em>%2$s</em>' ), $siteurl, $response->get_error_message() ) );
    do_action( 'after_mu_upgrade', $response );
    do_action( 'wpmu_upgrade_site', $details[ 'blog_id' ] );
}

But from that we can make a little tool to list all dead blogs.
And an option to deactivate each one*.

*Copied from /wp-admin/includes/class-wp-ms-sites-list-table.php.

enter image description here

add_action( 'wp_network_dashboard_setup', 'wpse_52040_network_dashboard_setup' );

function wpse_52040_network_dashboard_setup() 
{
    wp_add_dashboard_widget( 'wpse_52040_dead_blogs_widget', __( 'Dead blogs' ), 'wpse_52040_dead_blogs' );
}

function wpse_52040_dead_blogs() 
{
    global $wpdb;
    $blogs = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->blogs} WHERE  spam = '0' AND deleted = '0' AND archived = '0' ORDER BY registered DESC, 5", ARRAY_A ) );

    if ( empty( $blogs ) ) 
    {
        echo '<p>No blogs!</p>';
        break;
    }

    echo "<ul>";
    foreach ( (array) $blogs as $details ) 
    {
        $siteurl = get_blog_option( $details->blog_id, 'siteurl' );
        $response = wp_remote_get( trailingslashit( $siteurl ) . "wp-admin/", array( 'timeout' => 120, 'httpversion' => '1.1' ) );
        if ( is_wp_error( $response ) )
        {
            $error = $response->get_error_message();
            echo "<li><strong>$siteurl</strong><br />";
            echo '<span class="activate"><a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=deactivateblog&amp;id=' . $details->blog_id . '&amp;msg=' . urlencode( sprintf( __( 'You are about to deactivate the site %s' ), $details->domain ) ) ), 'confirm') ) . '">' . __( 'Deactivate' ) . '</a></span><br />';
            echo "Response -&gt; $error</li>";
        }
    }
   echo "</ul>";
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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