Exemplo n.º 1
0
/**
 * Update the last_updated field for the current blog.
 *
 * @since MU
 */
function wpmu_update_blogs_date() {
	global $wpdb;

	update_blog_details( $wpdb->blogid, array('last_updated' => current_time('mysql', true)) );

	do_action( 'wpmu_blog_updated', $wpdb->blogid );
}
Exemplo n.º 2
0
 /**
  * Test the returned data from get_blogs_of_user()
  */
 function test_get_blogs_of_user()
 {
     $user1_id = $this->factory->user->create(array('role' => 'administrator'));
     // Maintain a list of 6 total sites and include the primary network site.
     $blog_ids = $this->factory->blog->create_many(5, array('user_id' => $user1_id));
     $blog_ids = array_merge(array(1), $blog_ids);
     // All sites are new and not marked as spam, archived, or deleted.
     $blog_ids_of_user = array_keys(get_blogs_of_user($user1_id));
     // User should be a member of the created sites and the network's initial site.
     $this->assertEquals($blog_ids, $blog_ids_of_user);
     $this->assertTrue(remove_user_from_blog($user1_id, $blog_ids[0]));
     $this->assertTrue(remove_user_from_blog($user1_id, $blog_ids[2]));
     $this->assertTrue(remove_user_from_blog($user1_id, $blog_ids[4]));
     unset($blog_ids[0]);
     unset($blog_ids[2]);
     unset($blog_ids[4]);
     sort($blog_ids);
     $blogs_of_user = get_blogs_of_user($user1_id, false);
     // The user should still be a member of all remaining sites.
     $blog_ids_of_user = array_keys($blogs_of_user);
     $this->assertEquals($blog_ids, $blog_ids_of_user);
     // Each site retrieved should match the expected structure.
     foreach ($blogs_of_user as $blog_id => $blog) {
         $this->assertEquals($blog_id, $blog->userblog_id);
         $this->assertTrue(isset($blog->userblog_id));
         $this->assertTrue(isset($blog->blogname));
         $this->assertTrue(isset($blog->domain));
         $this->assertTrue(isset($blog->path));
         $this->assertTrue(isset($blog->site_id));
         $this->assertTrue(isset($blog->siteurl));
         $this->assertTrue(isset($blog->archived));
         $this->assertTrue(isset($blog->spam));
         $this->assertTrue(isset($blog->deleted));
     }
     // Mark each remaining site as spam, archived, and deleted.
     update_blog_details($blog_ids[0], array('spam' => 1));
     update_blog_details($blog_ids[1], array('archived' => 1));
     update_blog_details($blog_ids[2], array('deleted' => 1));
     // Passing true as the second parameter should retrieve ALL sites, even if marked.
     $blogs_of_user = get_blogs_of_user($user1_id, true);
     $blog_ids_of_user = array_keys($blogs_of_user);
     $this->assertEquals($blog_ids, $blog_ids_of_user);
     // Check if sites are flagged as expected.
     $this->assertEquals(1, $blogs_of_user[$blog_ids[0]]->spam);
     $this->assertEquals(1, $blogs_of_user[$blog_ids[1]]->archived);
     $this->assertEquals(1, $blogs_of_user[$blog_ids[2]]->deleted);
     unset($blog_ids[0]);
     unset($blog_ids[1]);
     unset($blog_ids[2]);
     sort($blog_ids);
     // Passing false (the default) as the second parameter should retrieve only good sites.
     $blog_ids_of_user = array_keys(get_blogs_of_user($user1_id, false));
     $this->assertEquals($blog_ids, $blog_ids_of_user);
 }
Exemplo n.º 3
0
 /**
  * Update the URL of a site
  *
  * @synopsis <ID> <NEW_URL> [--force]
  *
  * @param array $args
  * @param array $assoc_args
  */
 public function update(array $args = [], array $assoc_args = [])
 {
     $site_id = (int) $args[0];
     $site = get_blog_details($site_id, TRUE);
     if (!$site) {
         WP_CLI::error("A site with ID {$site_id} does not exist");
     }
     if (is_main_site($site_id)) {
         WP_CLI::error("The given site is the main site of the network. This feature does not support updating the main site URL");
     }
     $new_url = $args[1];
     if (!filter_var($new_url, FILTER_VALIDATE_URL)) {
         WP_CLI::error("{$new_url} is not a valid url");
     }
     /**
      * Parse the new URL components
      */
     $url_components = parse_url($new_url);
     $existing_scheme = parse_url($site->siteurl, PHP_URL_SCHEME);
     $scheme = isset($url_components['scheme']) ? $url_components['scheme'] : $existing_scheme;
     $host = isset($url_components['host']) ? $url_components['host'] : '';
     $path = isset($url_components['path']) ? trailingslashit($url_components['path']) : '/';
     // WP core does not accept ports in the URL so we don't too
     $site_details = get_object_vars($site);
     $site_details['domain'] = $host;
     $site_details['path'] = $path;
     /**
      * Update the site details (goes to the wp_blogs table)
      */
     update_blog_details($site_id, $site_details);
     // update 'home' and 'siteurl' in the options table
     switch_to_blog($site_id);
     $existing_home = trailingslashit(get_option('home'));
     $new_home = esc_url_raw($scheme . '://' . $host . $path);
     $new_home = untrailingslashit($new_home);
     // check if the actual 'home' value matches the old site URL
     if ($site->domain === parse_url($existing_home, PHP_URL_HOST) && $site->path === parse_url($existing_home, PHP_URL_PATH)) {
         update_option('home', $new_home);
     }
     $existing_site_url = trailingslashit(get_option('siteurl'));
     if ($site->domain === parse_url($existing_site_url, PHP_URL_HOST) && $site->path === parse_url($existing_site_url, PHP_URL_PATH)) {
         update_option('siteurl', $new_home);
     }
     /**
      * WP core deletes rewrite rules during the URL updating process
      *
      * @see wp-admin/network/site-info.php
      */
     delete_option('rewrite_rules');
     restore_current_blog();
     $new_home = trailingslashit($new_home);
     // append trailing slash for success report to avoid confusion
     WP_CLI::success("Update site URL to {$new_home}");
 }
Exemplo n.º 4
0
/**
 * Update the last_updated field for the current blog.
 *
 * @since MU
 */
function wpmu_update_blogs_date()
{
    global $wpdb;
    update_blog_details($wpdb->blogid, array('last_updated' => current_time('mysql', true)));
    /**
     * Fires after the blog details are updated.
     *
     * @since MU
     *
     * @param int $blog_id Blog ID.
     */
    do_action('wpmu_blog_updated', $wpdb->blogid);
}
Exemplo n.º 5
0
	}

	// rewrite rules can't be flushed during switch to blog
	delete_option( 'rewrite_rules' );

	// update blogs table
	$blog_data = stripslashes_deep( $_POST['blog'] );
	$existing_details = get_blog_details( $id, false );
	$blog_data_checkboxes = array( 'public', 'archived', 'spam', 'mature', 'deleted' );
	foreach ( $blog_data_checkboxes as $c ) {
		if ( ! in_array( $existing_details->$c, array( 0, 1 ) ) )
			$blog_data[ $c ] = $existing_details->$c;
		else
			$blog_data[ $c ] = isset( $_POST['blog'][ $c ] ) ? 1 : 0;
	}
	update_blog_details( $id, $blog_data );

	restore_current_blog();
	wp_redirect( add_query_arg( array( 'update' => 'updated', 'id' => $id ), 'site-info.php') );
	exit;
}

if ( isset($_GET['update']) ) {
	$messages = array();
	if ( 'updated' == $_GET['update'] )
		$messages[] = __('Site info updated.');
}

$title = sprintf( __('Edit Site: %s'), get_blogaddress_by_id($id));
$parent_file = 'sites.php';
$submenu_file = 'sites.php';
Exemplo n.º 6
0
	function test_update_blog_details() {
		global $test_action_counter;

		$user_id = $this->factory->user->create( array( 'role' => 'administrator' ) );
		$blog_id = $this->factory->blog->create( array( 'user_id' => $user_id, 'path' => '/test_blogpath', 'title' => 'Test Title' ) );
		$this->assertInternalType( 'int', $blog_id );

		$result = update_blog_details( $blog_id, array('domain' => 'example.com', 'path' => 'my_path/') );
		$this->assertTrue( $result );

		$blog = get_blog_details( $blog_id );
		$this->assertEquals( 'example.com', $blog->domain );
		$this->assertEquals( 'my_path/', $blog->path );
		$this->assertEquals( '0', $blog->spam );

		$result = update_blog_details( $blog_id, array('domain' => 'example2.com','spam' => 1) );
		$this->assertTrue( $result );
		$blog = get_blog_details( $blog_id );
		$this->assertEquals( 'example2.com', $blog->domain );
		$this->assertEquals( 'my_path/', $blog->path );
		$this->assertEquals( '1', $blog->spam );

		$result = update_blog_details( $blog_id );
		$this->assertFalse( $result );
		$blog = get_blog_details( $blog_id );
		$this->assertEquals( 'example2.com', $blog->domain );
		$this->assertEquals( 'my_path/', $blog->path );
		$this->assertEquals( '1', $blog->spam );

		$test_action_counter = 0;

		add_action( 'make_ham_blog', array( $this, '_action_counter_cb' ), 10, 1 );
		$result = update_blog_details( $blog_id, array( 'spam' => 0 ) );
		$this->assertTrue( $result );
		$blog = get_blog_details( $blog_id );
		$this->assertEquals( '0', $blog->spam );
		$this->assertEquals( 1, $test_action_counter );

		// Same again
		$result = update_blog_details( $blog_id, array( 'spam' => 0 ) );
		$this->assertTrue( $result );
		$blog = get_blog_details( $blog_id );
		$this->assertEquals( '0', $blog->spam );
		$this->assertEquals( 1, $test_action_counter );
		remove_action( 'make_ham_blog', array( $this, '_action_counter_cb' ), 10, 1 );

		add_action( 'make_spam_blog', array( $this, '_action_counter_cb' ), 10, 1 );
		$result = update_blog_details( $blog_id, array( 'spam' => 1 ) );
		$this->assertTrue( $result );
		$blog = get_blog_details( $blog_id );
		$this->assertEquals( '1', $blog->spam );
		$this->assertEquals( 2, $test_action_counter );

		// Same again
		$result = update_blog_details( $blog_id, array( 'spam' => 1 ) );
		$this->assertTrue( $result );
		$blog = get_blog_details( $blog_id );
		$this->assertEquals( '1', $blog->spam );
		$this->assertEquals( 2, $test_action_counter );
		remove_action( 'make_spam_blog', array( $this, '_action_counter_cb' ), 10, 1 );

		add_action( 'archive_blog', array( $this, '_action_counter_cb' ), 10, 1 );
		$result = update_blog_details( $blog_id, array( 'archived' => 1 ) );
		$this->assertTrue( $result );
		$blog = get_blog_details( $blog_id );
		$this->assertEquals( '1', $blog->archived );
		$this->assertEquals( 3, $test_action_counter );

		// Same again
		$result = update_blog_details( $blog_id, array( 'archived' => 1 ) );
		$this->assertTrue( $result );
		$blog = get_blog_details( $blog_id );
		$this->assertEquals( '1', $blog->archived );
		$this->assertEquals( 3, $test_action_counter );
		remove_action( 'archive_blog', array( $this, '_action_counter_cb' ), 10, 1 );

		add_action( 'unarchive_blog', array( $this, '_action_counter_cb' ), 10, 1 );
		$result = update_blog_details( $blog_id, array( 'archived' => 0 ) );
		$this->assertTrue( $result );
		$blog = get_blog_details( $blog_id );
		$this->assertEquals( '0', $blog->archived );
		$this->assertEquals( 4, $test_action_counter );

		// Same again
		$result = update_blog_details( $blog_id, array( 'archived' => 0 ) );
		$this->assertTrue( $result );
		$blog = get_blog_details( $blog_id );
		$this->assertEquals( '0', $blog->archived );
		$this->assertEquals( 4, $test_action_counter );
		remove_action( 'unarchive_blog', array( $this, '_action_counter_cb' ), 10, 1 );

		add_action( 'make_delete_blog', array( $this, '_action_counter_cb' ), 10, 1 );
		$result = update_blog_details( $blog_id, array( 'deleted' => 1 ) );
		$this->assertTrue( $result );
		$blog = get_blog_details( $blog_id );
		$this->assertEquals( '1', $blog->deleted );
		$this->assertEquals( 5, $test_action_counter );

		// Same again
		$result = update_blog_details( $blog_id, array( 'deleted' => 1 ) );
		$this->assertTrue( $result );
		$blog = get_blog_details( $blog_id );
		$this->assertEquals( '1', $blog->deleted );
		$this->assertEquals( 5, $test_action_counter );
		remove_action( 'make_delete_blog', array( $this, '_action_counter_cb' ), 10, 1 );

		add_action( 'make_undelete_blog', array( $this, '_action_counter_cb' ), 10, 1 );
		$result = update_blog_details( $blog_id, array( 'deleted' => 0 ) );
		$this->assertTrue( $result );
		$blog = get_blog_details( $blog_id );
		$this->assertEquals( '0', $blog->deleted );
		$this->assertEquals( 6, $test_action_counter );

		// Same again
		$result = update_blog_details( $blog_id, array( 'deleted' => 0 ) );
		$this->assertTrue( $result );
		$blog = get_blog_details( $blog_id );
		$this->assertEquals( '0', $blog->deleted );
		$this->assertEquals( 6, $test_action_counter );
		remove_action( 'make_undelete_blog', array( $this, '_action_counter_cb' ), 10, 1 );

		add_action( 'mature_blog', array( $this, '_action_counter_cb' ), 10, 1 );
		$result = update_blog_details( $blog_id, array( 'mature' => 1 ) );
		$this->assertTrue( $result );
		$blog = get_blog_details( $blog_id );
		$this->assertEquals( '1', $blog->mature );
		$this->assertEquals( 7, $test_action_counter );

		// Same again
		$result = update_blog_details( $blog_id, array( 'mature' => 1 ) );
		$this->assertTrue( $result );
		$blog = get_blog_details( $blog_id );
		$this->assertEquals( '1', $blog->mature );
		$this->assertEquals( 7, $test_action_counter );
		remove_action( 'mature_blog', array( $this, '_action_counter_cb' ), 10, 1 );

		add_action( 'unmature_blog', array( $this, '_action_counter_cb' ), 10, 1 );
		$result = update_blog_details( $blog_id, array( 'mature' => 0 ) );
		$this->assertTrue( $result );
		$blog = get_blog_details( $blog_id );
		$this->assertEquals( '0', $blog->mature );
		$this->assertEquals( 8, $test_action_counter );

		// Same again
		$result = update_blog_details( $blog_id, array( 'mature' => 0 ) );
		$this->assertTrue( $result );
		$blog = get_blog_details( $blog_id );
		$this->assertEquals( '0', $blog->mature );
		$this->assertEquals( 8, $test_action_counter );
		remove_action( 'unmature_blog', array( $this, '_action_counter_cb' ), 10, 1 );
	}
 /**
  * When the path for a site is updated with update_blog_details(), the final path
  * should have a leading and trailing slash.
  *
  * @dataProvider data_single_directory_path
  */
 public function test_update_blog_details_single_directory_path($path, $expected)
 {
     update_blog_details(1, array('path' => $path));
     $site = get_site(1);
     $this->assertEquals($expected, $site->path);
 }
Exemplo n.º 8
0
 function test_update_blog_status_unmature_blog_action()
 {
     global $test_action_counter;
     $test_action_counter = 0;
     $blog_id = self::factory()->blog->create();
     update_blog_details($blog_id, array('mature' => 1));
     add_action('unmature_blog', array($this, '_action_counter_cb'), 10);
     update_blog_status($blog_id, 'mature', 0);
     $blog = get_blog_details($blog_id);
     $this->assertEquals('0', $blog->mature);
     $this->assertEquals(1, $test_action_counter);
     // The action should fire if the status of 'mature' stays the same.
     update_blog_status($blog_id, 'mature', 0);
     $blog = get_blog_details($blog_id);
     $this->assertEquals('0', $blog->mature);
     $this->assertEquals(2, $test_action_counter);
     remove_action('unmature_blog', array($this, '_action_counter_cb'), 10);
 }
 /**
  * @group get_order_by
  */
 public function test_get_order_by()
 {
     if (!is_multisite()) {
         return;
     }
     $old_user = get_current_user_id();
     $u = $this->factory->user->create();
     $this->set_current_user($u);
     $bs = array('foobar' => $this->factory->blog->create(array('title' => 'Foo Bar Blog', 'user_id' => $u, 'path' => '/path' . rand() . time() . '/')), 'barfoo' => $this->factory->blog->create(array('title' => 'Bar foo Blog', 'user_id' => $u, 'path' => '/path' . rand() . time() . '/')));
     bp_blogs_record_existing_blogs();
     // make the blog public or it won't turn up in generic results
     foreach ($bs as $b) {
         update_blog_option($b, 'blog_public', '1');
     }
     // Used to make sure barfoo is older than foobar
     $b_time = date_i18n('Y-m-d H:i:s', strtotime('-5 minutes'));
     /* Alphabetical */
     $blogs = BP_Blogs_Blog::get('alphabetical', false, false, $u);
     $blog_ids = wp_list_pluck($blogs['blogs'], 'blog_id');
     $this->assertEquals(array($bs['barfoo'], $bs['foobar']), $blog_ids);
     /* Newest */
     update_blog_details($bs['barfoo'], array('registered' => $b_time));
     $blogs = BP_Blogs_Blog::get('newest', false, false, $u);
     $blog_ids = wp_list_pluck($blogs['blogs'], 'blog_id');
     $this->assertEquals(array($bs['foobar'], $bs['barfoo']), $blog_ids);
     /* Active */
     bp_blogs_update_blogmeta($bs['barfoo'], 'last_activity', $b_time);
     $blogs = BP_Blogs_Blog::get('active', false, false, $u);
     $blog_ids = wp_list_pluck($blogs['blogs'], 'blog_id');
     $this->assertEquals(array($bs['foobar'], $bs['barfoo']), $blog_ids);
     /* Random */
     $blogs = BP_Blogs_Blog::get('random', false, false, $u);
     $this->assertTrue(2 == count($blogs['blogs']));
     $this->set_current_user($old_user);
 }
Exemplo n.º 10
0
 /**
  * Make this mapping the primary domain, eg. set the homeurl for the site
  *
  * @return bool|\WP_Error True if we created the old mapping or WP_Error if an error occurred
  */
 public function make_primary()
 {
     // Get current site details to update
     $site = $this->get_site();
     // Create a new mapping from the old canonical domain
     $mapping = self::create($site->blog_id, $site->domain, true);
     if (is_wp_error($mapping)) {
         return $mapping;
     }
     // Set the new home and siteurl etc to the current mapping
     update_blog_details($site->blog_id, array('domain' => $this->get_domain()));
     // These are just a visual update for the site admin
     $url = esc_url($this->get_domain());
     update_blog_option($site->blog_id, 'home', $url);
     update_blog_option($site->blog_id, 'siteurl', $url);
     // Remove current mapping
     $this->delete();
     /**
      * Fires after a mapping has set as primary.
      *
      * @param Mercator\Mapping $mapping The mapping object.
      */
     do_action('mercator.mapping.made_primary', $this);
     return true;
 }
Exemplo n.º 11
0
 /**
  * Applies the student's chosen pseudonym.
  *
  * This updates the student's user and blog information, then attempts to
  * update any references to the old URL, such as those used by media embedded
  * into posts on the blog whose URL is being changed.
  *
  * The inputs for this function will have already been validated by another
  * method, so it can be assumed that they are valid.
  *
  * @param  int    $user_id        the student's user ID
  * @param  int    $blog_id        the ID of the student's primary blog
  * @param  string $new_username   the student's new username
  *
  * @access private
  * @since 0.1
  */
 private function _apply_pseudonym($user_id, $blog_id, $new_username)
 {
     global $nxtdb;
     // Update the student's username
     $nxtdb->update($nxtdb->users, array('user_login' => $new_username), array('ID' => $user_id), array('%s'), array('%d'));
     // Deal with the implications of the updated username in multisite
     if (ClassBlogs_Utils::is_multisite()) {
         ClassBlogs_NXTClass::switch_to_blog($blog_id);
         $old_url = trailingslashit(home_url());
         // Update the blog URL to reflect their new username
         $site = get_current_site();
         $new_path = trailingslashit($site->path . $new_username);
         $new_url = 'http://' . $site->domain . $new_path;
         update_option('siteurl', $new_url);
         update_option('home', $new_url);
         update_blog_details($blog_id, array('path' => $new_path));
         delete_option('rewrite_rules');
         // Replace any occurrences of the old URL in the blog's posts
         $referring_posts = $nxtdb->get_results("\n\t\t\t\tSELECT ID, post_content FROM {$nxtdb->posts}\n\t\t\t\tWHERE post_content LIKE '%%" . like_escape($old_url) . "%%' ");
         foreach ($referring_posts as $post) {
             $nxtdb->update($nxtdb->posts, array('post_content' => str_replace($old_url, $new_url, $post->post_content)), array('ID' => $post->ID), array('%s'), array('%d'));
         }
         ClassBlogs_NXTClass::restore_current_blog();
     }
     // Flag that the user has changed their username
     $changed = $this->get_option('changed_users');
     $changed[$new_username] = true;
     $this->update_option('changed_users', $changed);
 }
Exemplo n.º 12
0
<?php

update_blog_details(2, array('deleted' => '0'));
Exemplo n.º 13
0
function ust_toolbar_ajax()
{
    if (!current_user_can('manage_sites')) {
        die(0);
    }
    // Just for super admins
    $blog_id = (int) @$_POST['blog_id'];
    $flag = @$_POST['flag'];
    $data = get_blog_details($blog_id);
    switch ($flag) {
        case "spam":
            $data->spam = $data->spam ? 0 : 1;
            break;
        case "archive":
            $data->archived = $data->archived ? 0 : 1;
            break;
    }
    $res = (int) update_blog_details($blog_id, $data);
    header('Content-type: application/json');
    echo json_encode(array('status' => $res ? 1 : 0));
    exit;
}
Exemplo n.º 14
0
 /**
  * @group update_blog_details
  */
 public function test_update_blog_details_should_purge_blogmeta_cache()
 {
     if (!is_multisite()) {
         return;
     }
     $u = $this->factory->user->create();
     $b1 = $this->factory->blog->create();
     bp_blogs_record_blog($b1, $u, true);
     // prime cache
     bp_blogs_get_blogmeta($b1, 'url');
     $this->assertNotEmpty(wp_cache_get($b1, 'blog_meta'));
     // updating blog details should purge cache
     update_blog_details($b1, array('domain' => 'awesome.com'));
     // assert cache is purged
     $this->assertEmpty(wp_cache_get($b1, 'blog_meta'));
 }
Exemplo n.º 15
0
 /**
  * @subcommand set-domain
  * @synopsis <domain>
  */
 public function set_domain($args, $assoc_args)
 {
     global $wpdb;
     $sites = wp_get_sites();
     list($domain) = $args;
     $network = wp_get_network($wpdb->siteid);
     if (empty($network)) {
         return;
     }
     $old_domain = $network->domain;
     if ($old_domain == $domain) {
         return;
     }
     $wpdb->update($wpdb->site, array('domain' => $domain), array('id' => $wpdb->siteid));
     update_site_option('siteurl', "http://{$domain}/");
     update_site_option('site_name', "{$domain} Sites");
     update_site_option('admin_email', "wordpress@{$domain}");
     foreach (wp_get_sites() as $site) {
         $blog_id = $site['blog_id'];
         switch_to_blog($blog_id);
         $blog_domain = str_replace($old_domain, $domain, $site['domain']);
         $blog_data = array('domain' => $blog_domain, 'siteurl' => 'http://' . $blog_domain, 'path' => '/');
         $blog_address = esc_url_raw($blog_data['siteurl']);
         if (get_option('siteurl') != $blog_address) {
             update_option('siteurl', $blog_address);
         }
         if (get_option('home') != $blog_address) {
             update_option('home', $blog_address);
         }
         update_blog_details($blog_id, $blog_data);
         restore_current_blog();
         WP_CLI::line("{$blog_data['domain']} -> {$blog_domain}");
     }
     if (file_exists(__DIR__ . '/hosts')) {
         $hosts = file_get_contents(__DIR__ . '/hosts');
         $hosts = preg_replace('/\\s' . preg_quote($old_domain) . '\\s/', " {$domain} ", $hosts);
         $hosts = preg_replace('/\\.' . preg_quote($old_domain) . '\\s/', ".{$domain} ", $hosts);
         file_put_contents(__DIR__ . '/hosts', $hosts);
     }
     if (file_exists(__DIR__ . '/server_hosts')) {
         $hosts = file_get_contents(__DIR__ . '/server_hosts');
         $hosts = preg_replace('/\\s' . preg_quote($old_domain) . '\\s/', " {$domain} ", $hosts);
         $hosts = preg_replace('/\\.' . preg_quote($old_domain) . '\\s/', ".{$domain} ", $hosts);
         file_put_contents(__DIR__ . '/server_hosts', $hosts);
     }
     if (file_exists('/etc/hosts')) {
         $hosts = file_get_contents('/etc/hosts');
         $hosts = preg_replace('/\\s' . preg_quote($old_domain) . '\\s/', " {$domain} ", $hosts);
         $hosts = preg_replace('/\\.' . preg_quote($old_domain) . '\\s/', ".{$domain} ", $hosts);
         file_put_contents('/etc/hosts', $hosts);
     }
     WP_CLI::success("{$old_domain} -> {$domain}");
 }