Index: src/wp-admin/includes/ms.php
===================================================================
--- src/wp-admin/includes/ms.php	(revision 40306)
+++ src/wp-admin/includes/ms.php	(working copy)
@@ -127,6 +127,13 @@
 			$wpdb->query( "DROP TABLE IF EXISTS `$table`" );
 		}
 
+		if ( is_site_meta_supported() ) {
+			$blog_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->blogmeta WHERE blog_id = %d ", $blog_id ) );
+			foreach ( $blog_meta_ids as $mid ) {
+				delete_metadata_by_mid( 'blog', $mid );
+			}
+		}
+
 		$wpdb->delete( $wpdb->blogs, array( 'blog_id' => $blog_id ) );
 
 		/**
Index: src/wp-admin/includes/schema.php
===================================================================
--- src/wp-admin/includes/schema.php	(revision 40306)
+++ src/wp-admin/includes/schema.php	(working copy)
@@ -265,6 +265,15 @@
   PRIMARY KEY  (blog_id),
   KEY db_version (db_version)
 ) $charset_collate;
+CREATE TABLE $wpdb->blogmeta (
+  meta_id bigint(20) NOT NULL auto_increment,
+  blog_id bigint(20) NOT NULL default '0',
+  meta_key varchar(255) default NULL,
+  meta_value longtext,
+  PRIMARY KEY  (meta_id),
+  KEY meta_key (meta_key($max_index_length)),
+  KEY blog_id (blog_id)
+) $charset_collate;
 CREATE TABLE $wpdb->registration_log (
   ID bigint(20) NOT NULL auto_increment,
   email varchar(255) NOT NULL default '',
Index: src/wp-includes/class-wp-site-query.php
===================================================================
--- src/wp-includes/class-wp-site-query.php	(revision 40306)
+++ src/wp-includes/class-wp-site-query.php	(working copy)
@@ -42,6 +42,24 @@
 	);
 
 	/**
+	 * Metadata query container.
+	 *
+	 * @since 4.8.0
+	 * @access public
+	 * @var object WP_Meta_Query
+	 */
+	public $meta_query = false;
+
+	/**
+	 * Metadata query clauses.
+	 *
+	 * @since 4.8.0
+	 * @access protected
+	 * @var array
+	 */
+	protected $meta_query_clauses = array();
+
+	/**
 	 * Date query container.
 	 *
 	 * @since 4.6.0
@@ -99,81 +117,99 @@
 	 * Sets up the site query, based on the query vars passed.
 	 *
 	 * @since 4.6.0
+	 * @since 4.8.0 Introduced the `update_site_meta_cache`, `meta_query`, `meta_key`,
+	 *              `meta_value`, `meta_type` and `meta_compare` parameters.
 	 * @access public
 	 *
 	 * @param string|array $query {
 	 *     Optional. Array or query string of site query parameters. Default empty.
 	 *
-	 *     @type array        $site__in          Array of site IDs to include. Default empty.
-	 *     @type array        $site__not_in      Array of site IDs to exclude. Default empty.
-	 *     @type bool         $count             Whether to return a site count (true) or array of site objects.
-	 *                                           Default false.
-	 *     @type array        $date_query        Date query clauses to limit sites by. See WP_Date_Query.
-	 *                                           Default null.
-	 *     @type string       $fields            Site fields to return. Accepts 'ids' (returns an array of site IDs)
-	 *                                           or empty (returns an array of complete site objects). Default empty.
-	 *     @type int          $ID                A site ID to only return that site. Default empty.
-	 *     @type int          $number            Maximum number of sites to retrieve. Default 100.
-	 *     @type int          $offset            Number of sites to offset the query. Used to build LIMIT clause.
-	 *                                           Default 0.
-	 *     @type bool         $no_found_rows     Whether to disable the `SQL_CALC_FOUND_ROWS` query. Default true.
-	 *     @type string|array $orderby           Site status or array of statuses. Accepts 'id', 'domain', 'path',
-	 *                                           'network_id', 'last_updated', 'registered', 'domain_length',
-	 *                                           'path_length', 'site__in' and 'network__in'. Also accepts false,
-	 *                                           an empty array, or 'none' to disable `ORDER BY` clause.
-	 *                                           Default 'id'.
-	 *     @type string       $order             How to order retrieved sites. Accepts 'ASC', 'DESC'. Default 'ASC'.
-	 *     @type int          $network_id        Limit results to those affiliated with a given network ID. If 0,
-	 *                                           include all networks. Default 0.
-	 *     @type array        $network__in       Array of network IDs to include affiliated sites for. Default empty.
-	 *     @type array        $network__not_in   Array of network IDs to exclude affiliated sites for. Default empty.
-	 *     @type string       $domain            Limit results to those affiliated with a given domain. Default empty.
-	 *     @type array        $domain__in        Array of domains to include affiliated sites for. Default empty.
-	 *     @type array        $domain__not_in    Array of domains to exclude affiliated sites for. Default empty.
-	 *     @type string       $path              Limit results to those affiliated with a given path. Default empty.
-	 *     @type array        $path__in          Array of paths to include affiliated sites for. Default empty.
-	 *     @type array        $path__not_in      Array of paths to exclude affiliated sites for. Default empty.
-	 *     @type int          $public            Limit results to public sites. Accepts '1' or '0'. Default empty.
-	 *     @type int          $archived          Limit results to archived sites. Accepts '1' or '0'. Default empty.
-	 *     @type int          $mature            Limit results to mature sites. Accepts '1' or '0'. Default empty.
-	 *     @type int          $spam              Limit results to spam sites. Accepts '1' or '0'. Default empty.
-	 *     @type int          $deleted           Limit results to deleted sites. Accepts '1' or '0'. Default empty.
-	 *     @type string       $search            Search term(s) to retrieve matching sites for. Default empty.
-	 *     @type array        $search_columns    Array of column names to be searched. Accepts 'domain' and 'path'.
-	 *                                           Default empty array.
-	 *     @type bool         $update_site_cache Whether to prime the cache for found sites. Default false.
+	 *     @type array        $site__in               Array of site IDs to include. Default empty.
+	 *     @type array        $site__not_in           Array of site IDs to exclude. Default empty.
+	 *     @type bool         $count                  Whether to return a site count (true) or array of site objects.
+	 *                                                Default false.
+	 *     @type array        $date_query             Date query clauses to limit sites by. See WP_Date_Query.
+	 *                                                Default null.
+	 *     @type string       $fields                 Site fields to return. Accepts 'ids' (returns an array of site IDs)
+	 *                                                or empty (returns an array of complete site objects). Default empty.
+	 *     @type int          $ID                     A site ID to only return that site. Default empty.
+	 *     @type int          $number                 Maximum number of sites to retrieve. Default 100.
+	 *     @type int          $offset                 Number of sites to offset the query. Used to build LIMIT clause.
+	 *                                                Default 0.
+	 *     @type bool         $no_found_rows          Whether to disable the `SQL_CALC_FOUND_ROWS` query. Default true.
+	 *     @type string|array $orderby                Site status or array of statuses. Accepts 'id', 'domain', 'path',
+	 *                                                'network_id', 'last_updated', 'registered', 'domain_length',
+	 *                                                'path_length', 'site__in' and 'network__in'. Also accepts false,
+	 *                                                an empty array, or 'none' to disable `ORDER BY` clause.
+	 *                                                Default 'id'.
+	 *     @type string       $order                  How to order retrieved sites. Accepts 'ASC', 'DESC'. Default 'ASC'.
+	 *     @type int          $network_id             Limit results to those affiliated with a given network ID. If 0,
+	 *                                                include all networks. Default 0.
+	 *     @type array        $network__in            Array of network IDs to include affiliated sites for. Default empty.
+	 *     @type array        $network__not_in        Array of network IDs to exclude affiliated sites for. Default empty.
+	 *     @type string       $domain                 Limit results to those affiliated with a given domain. Default empty.
+	 *     @type array        $domain__in             Array of domains to include affiliated sites for. Default empty.
+	 *     @type array        $domain__not_in         Array of domains to exclude affiliated sites for. Default empty.
+	 *     @type string       $path                   Limit results to those affiliated with a given path. Default empty.
+	 *     @type array        $path__in               Array of paths to include affiliated sites for. Default empty.
+	 *     @type array        $path__not_in           Array of paths to exclude affiliated sites for. Default empty.
+	 *     @type int          $public                 Limit results to public sites. Accepts '1' or '0'. Default empty.
+	 *     @type int          $archived               Limit results to archived sites. Accepts '1' or '0'. Default empty.
+	 *     @type int          $mature                 Limit results to mature sites. Accepts '1' or '0'. Default empty.
+	 *     @type int          $spam                   Limit results to spam sites. Accepts '1' or '0'. Default empty.
+	 *     @type int          $deleted                Limit results to deleted sites. Accepts '1' or '0'. Default empty.
+	 *     @type string       $search                 Search term(s) to retrieve matching sites for. Default empty.
+	 *     @type array        $search_columns         Array of column names to be searched. Accepts 'domain' and 'path'.
+	 *                                                Default empty array.
+	 *     @type bool         $update_site_cache      Whether to prime the cache for found sites. Default false.
+	 *     @type bool         $update_site_meta_cache Whether to prime meta caches for matched sites. Default true.
+	 *     @type array        $meta_query             Optional. Meta query clauses to limit retrieved sites by.
+	 *                                                See `WP_Meta_Query`. Default empty.
+	 *     @type string       $meta_key               Limit sites to those matching a specific metadata key.
+	 *                                                Can be used in conjunction with `$meta_value`. Default empty.
+	 *     @type string       $meta_value             Limit sites to those matching a specific metadata value.
+	 *                                                Usually used in conjunction with `$meta_key`. Default empty.
+	 *     @type string       $meta_type              Type of object metadata is for (e.g., comment, post, or user).
+	 *                                                Default empty.
+	 *     @type string       $meta_compare           Comparison operator to test the 'meta_value'. Default empty.
 	 * }
 	 */
 	public function __construct( $query = '' ) {
 		$this->query_var_defaults = array(
-			'fields'            => '',
-			'ID'                => '',
-			'site__in'          => '',
-			'site__not_in'      => '',
-			'number'            => 100,
-			'offset'            => '',
-			'no_found_rows'     => true,
-			'orderby'           => 'id',
-			'order'             => 'ASC',
-			'network_id'        => 0,
-			'network__in'       => '',
-			'network__not_in'   => '',
-			'domain'            => '',
-			'domain__in'        => '',
-			'domain__not_in'    => '',
-			'path'              => '',
-			'path__in'          => '',
-			'path__not_in'      => '',
-			'public'            => null,
-			'archived'          => null,
-			'mature'            => null,
-			'spam'              => null,
-			'deleted'           => null,
-			'search'            => '',
-			'search_columns'    => array(),
-			'count'             => false,
-			'date_query'        => null, // See WP_Date_Query
-			'update_site_cache' => true,
+			'fields'                 => '',
+			'ID'                     => '',
+			'site__in'               => '',
+			'site__not_in'           => '',
+			'number'                 => 100,
+			'offset'                 => '',
+			'no_found_rows'          => true,
+			'orderby'                => 'id',
+			'order'                  => 'ASC',
+			'network_id'             => 0,
+			'network__in'            => '',
+			'network__not_in'        => '',
+			'domain'                 => '',
+			'domain__in'             => '',
+			'domain__not_in'         => '',
+			'path'                   => '',
+			'path__in'               => '',
+			'path__not_in'           => '',
+			'public'                 => null,
+			'archived'               => null,
+			'mature'                 => null,
+			'spam'                   => null,
+			'deleted'                => null,
+			'search'                 => '',
+			'search_columns'         => array(),
+			'count'                  => false,
+			'date_query'             => null, // See WP_Date_Query
+			'update_site_cache'      => true,
+			'update_site_meta_cache' => true,
+			'meta_query'             => '',
+			'meta_key'               => '',
+			'meta_value'             => '',
+			'meta_type'              => '',
+			'meta_compare'           => '',
 		);
 
 		if ( ! empty( $query ) ) {
@@ -229,11 +265,21 @@
 	 * @since 4.6.0
 	 * @access public
 	 *
+	 * @global wpdb $wpdb WordPress database abstraction object.
+	 *
 	 * @return array|int List of sites, or number of sites when 'count' is passed as a query var.
 	 */
 	public function get_sites() {
+		global $wpdb;
+
 		$this->parse_query();
 
+		// Set up meta_query so it's available to 'pre_get_sites'.
+		if ( class_exists( 'WP_Meta_Query' ) ) {
+			$this->meta_query = new WP_Meta_Query();
+			$this->meta_query->parse_query_vars( $this->query_vars );
+		}
+
 		/**
 		 * Fires before sites are retrieved.
 		 *
@@ -243,6 +289,14 @@
 		 */
 		do_action_ref_array( 'pre_get_sites', array( &$this ) );
 
+		// Reparse query vars, in case they were modified in a 'pre_get_comments' callback.
+		if ( $this->meta_query ) {
+			$this->meta_query->parse_query_vars( $this->query_vars );
+			if ( is_site_meta_supported() && ! empty( $this->meta_query->queries ) ) {
+				$this->meta_query_clauses = $this->meta_query->get_sql( 'blog', $wpdb->blogs, 'blog_id', $this );
+			}
+		}
+
 		// $args can include anything. Only use the args defined in the query_var_defaults to compute the key.
 		$key = md5( serialize( wp_array_slice_assoc( $this->query_vars, array_keys( $this->query_var_defaults ) ) ) );
 		$last_changed = wp_cache_get_last_changed( 'sites' );
@@ -286,7 +340,11 @@
 
 		// Prime site network caches.
 		if ( $this->query_vars['update_site_cache'] ) {
-			_prime_site_caches( $site_ids );
+			if ( $this->meta_query ) {
+				_prime_site_caches( $site_ids, $this->query_vars['update_site_meta_cache'] );
+			} else {
+				_prime_site_caches( $site_ids, false );
+			}
 		}
 
 		// Fetch full site objects from the primed cache.
@@ -366,7 +424,7 @@
 
 			$orderby = implode( ', ', $orderby_array );
 		} else {
-			$orderby = "blog_id $order";
+			$orderby = "$wpdb->blogs.blog_id $order";
 		}
 
 		$number = absint( $this->query_vars['number'] );
@@ -383,23 +441,23 @@
 		if ( $this->query_vars['count'] ) {
 			$fields = 'COUNT(*)';
 		} else {
-			$fields = 'blog_id';
+			$fields = "$wpdb->blogs.blog_id";
 		}
 
 		// Parse site IDs for an IN clause.
 		$site_id = absint( $this->query_vars['ID'] );
 		if ( ! empty( $site_id ) ) {
-			$this->sql_clauses['where']['ID'] = $wpdb->prepare( 'blog_id = %d', $site_id );
+			$this->sql_clauses['where']['ID'] = $wpdb->prepare( "$wpdb->blogs.blog_id = %d", $site_id );
 		}
 
 		// Parse site IDs for an IN clause.
 		if ( ! empty( $this->query_vars['site__in'] ) ) {
-			$this->sql_clauses['where']['site__in'] = "blog_id IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['site__in'] ) ) . ' )';
+			$this->sql_clauses['where']['site__in'] = "$wpdb->blogs.blog_id IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['site__in'] ) ) . ' )';
 		}
 
 		// Parse site IDs for a NOT IN clause.
 		if ( ! empty( $this->query_vars['site__not_in'] ) ) {
-			$this->sql_clauses['where']['site__not_in'] = "blog_id NOT IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['site__not_in'] ) ) . ' )';
+			$this->sql_clauses['where']['site__not_in'] = "$wpdb->blogs.blog_id NOT IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['site__not_in'] ) ) . ' )';
 		}
 
 		$network_id = absint( $this->query_vars['network_id'] );
@@ -507,6 +565,17 @@
 
 		$join = '';
 
+		if ( ! empty( $this->meta_query_clauses ) ) {
+			$join .= $this->meta_query_clauses['join'];
+
+			// Strip leading 'AND'.
+			$this->sql_clauses['where']['meta_query'] = preg_replace( '/^\s*AND\s*/', '', $this->meta_query_clauses['where'] );
+
+			if ( ! $this->query_vars['count'] ) {
+				$groupby = "{$wpdb->blogs}.blog_id";
+			}
+		}
+
 		$where = implode( ' AND ', $this->sql_clauses['where'] );
 
 		$pieces = array( 'fields', 'join', 'where', 'orderby', 'limits', 'groupby' );
@@ -659,10 +728,28 @@
 				$parsed = 'CHAR_LENGTH(path)';
 				break;
 			case 'id':
-				$parsed = 'blog_id';
+				$parsed = "$wpdb->blogs.blog_id";
 				break;
 		}
 
+		if ( ! $parsed && is_site_meta_supported() && $this->meta_query ) {
+			switch ( $orderby ) {
+				case $this->query_vars['meta_key']:
+				case 'meta_value':
+					$parsed = "$wpdb->blogmeta.meta_value";
+					break;
+				case 'meta_value_num':
+					$parsed = "$wpdb->blogmeta.meta_value+0";
+					break;
+				default:
+					$meta_query_clauses = $this->meta_query->get_clauses();
+					if ( $meta_query_clauses && isset( $meta_query_clauses[ $orderby ] ) ) {
+						$meta_clause = $meta_query_clauses[ $orderby ];
+						$parsed = sprintf( "CAST(%s.meta_value AS %s)", esc_sql( $meta_clause['alias'] ), esc_sql( $meta_clause['cast'] ) );
+					}
+			}
+		}
+
 		return $parsed;
 	}
 
Index: src/wp-includes/load.php
===================================================================
--- src/wp-includes/load.php	(revision 40306)
+++ src/wp-includes/load.php	(working copy)
@@ -515,7 +515,7 @@
 	}
 
 	if ( function_exists( 'wp_cache_add_global_groups' ) ) {
-		wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'site-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites' ) );
+		wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'site-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'blog_meta' ) );
 		wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) );
 	}
 }
Index: src/wp-includes/ms-blogs.php
===================================================================
--- src/wp-includes/ms-blogs.php	(revision 40306)
+++ src/wp-includes/ms-blogs.php	(working copy)
@@ -457,6 +457,7 @@
 	wp_cache_delete( 'current_blog_' . $blog->domain, 'site-options' );
 	wp_cache_delete( 'current_blog_' . $blog->domain . $blog->path, 'site-options' );
 	wp_cache_delete( $domain_path_key, 'blog-id-cache' );
+	wp_cache_delete( $blog_id, 'blog_meta' );
 
 	/**
 	 * Fires immediately after a site has been removed from the object cache.
@@ -534,14 +535,18 @@
  * Adds any sites from the given ids to the cache that do not already exist in cache.
  *
  * @since 4.6.0
+ * @since 4.8.0 The $update_meta_cache parameter was added.
  * @access private
  *
  * @see update_site_cache()
+ * @see update_sitemeta_cache()
+ *
  * @global wpdb $wpdb WordPress database abstraction object.
  *
- * @param array $ids ID list.
+ * @param array $ids               ID list.
+ * @param bool  $update_meta_cache Optional. Whether to update the meta cache. Default true.
  */
-function _prime_site_caches( $ids ) {
+function _prime_site_caches( $ids, $update_meta_cache = true ) {
 	global $wpdb;
 
 	$non_cached_ids = _get_non_cached_ids( $ids, 'sites' );
@@ -549,6 +554,10 @@
 		$fresh_sites = $wpdb->get_results( sprintf( "SELECT * FROM $wpdb->blogs WHERE blog_id IN (%s)", join( ",", array_map( 'intval', $non_cached_ids ) ) ) );
 
 		update_site_cache( $fresh_sites );
+
+		if ( $update_meta_cache ) {
+			update_sitemeta_cache( $non_cached_ids );
+		}
 	}
 }
 
@@ -571,6 +580,26 @@
 }
 
 /**
+ * Updates metadata cache for list of site IDs.
+ *
+ * Performs SQL query to retrieve all metadata for the sites matching `$site_ids` and stores them in the cache.
+ * Subsequent calls to `get_site_meta()` will not need to query the database.
+ *
+ * @since 4.8.0
+ *
+ * @param array $site_ids List of site IDs.
+ * @return array|false Returns false if there is nothing to update. Returns an array of metadata on success.
+ */
+function update_sitemeta_cache( $site_ids ) {
+	// Bail if site meta table is not installed.
+	if ( ! is_site_meta_supported() ) {
+		return;
+	}
+
+	return update_meta_cache( 'blog', $site_ids );
+}
+
+/**
  * Retrieves a list of sites matching requested arguments.
  *
  * @since 4.6.0
@@ -628,6 +657,196 @@
 }
 
 /**
+ * Add meta data field to a site.
+ *
+ * Site meta data is called "Custom Fields" on the Administration Screen.
+ *
+ * @since 4.8.0
+ *
+ * @param int    $site_id    Site ID.
+ * @param string $meta_key   Metadata name.
+ * @param mixed  $meta_value Metadata value. Must be serializable if non-scalar.
+ * @param bool   $unique     Optional. Whether the same key should not be added.
+ *                           Default false.
+ * @return int|false Meta ID on success, false on failure.
+ */
+function add_site_meta( $site_id, $meta_key, $meta_value, $unique = false ) {
+	if ( ! is_site_meta_supported() || is_core_site_meta_key( $meta_key ) ) {
+		return false;
+	}
+
+	$added = add_metadata( 'blog', $site_id, $meta_key, $meta_value, $unique );
+
+	// Bust site query cache.
+	if ( $added ) {
+		wp_cache_set( 'last_changed', microtime(), 'sites' );
+	}
+
+	return $added;
+}
+
+/**
+ * Remove metadata matching criteria from a site.
+ *
+ * You can match based on the key, or key and value. Removing based on key and
+ * value, will keep from removing duplicate metadata with the same key. It also
+ * allows removing all metadata matching key, if needed.
+ *
+ * @since 4.8.0
+ *
+ * @param int    $site_id    Site ID.
+ * @param string $meta_key   Metadata name.
+ * @param mixed  $meta_value Optional. Metadata value. Must be serializable if
+ *                           non-scalar. Default empty.
+ * @return bool True on success, false on failure.
+ */
+function delete_site_meta( $site_id, $meta_key, $meta_value = '' ) {
+	if ( ! is_site_meta_supported() || is_core_site_meta_key( $meta_key ) ) {
+		return false;
+	}
+
+	$deleted = delete_metadata( 'blog', $site_id, $meta_key, $meta_value );
+
+	// Bust site query cache.
+	if ( $deleted ) {
+		wp_cache_set( 'last_changed', microtime(), 'sites' );
+	}
+
+	return $deleted;
+}
+
+/**
+ * Retrieve site meta field for a site.
+ *
+ * @since 4.8.0
+ *
+ * @param int    $site_id Site ID.
+ * @param string $key     Optional. The meta key to retrieve. By default, returns
+ *                        data for all keys. Default empty.
+ * @param bool   $single  Optional. Whether to return a single value. Default false.
+ * @return mixed Will be an array if $single is false. Will be value of meta data
+ *               field if $single is true.
+ */
+function get_site_meta( $site_id, $key = '', $single = false ) {
+	if ( ! is_site_meta_supported() ) {
+		if ( ! empty( $key ) && $single ) {
+			return '';
+		}
+
+		return array();
+	}
+
+	return get_metadata( 'blog', $site_id, $key, $single );
+}
+
+/**
+ * Update site meta field based on site ID.
+ *
+ * Use the $prev_value parameter to differentiate between meta fields with the
+ * same key and site ID.
+ *
+ * If the meta field for the site does not exist, it will be added.
+ *
+ * @since 4.8.0
+ *
+ * @param int    $site_id    Site ID.
+ * @param string $meta_key   Metadata key.
+ * @param mixed  $meta_value Metadata value. Must be serializable if non-scalar.
+ * @param mixed  $prev_value Optional. Previous value to check before removing.
+ *                           Default empty.
+ * @return int|bool Meta ID if the key didn't exist, true on successful update,
+ *                  false on failure.
+ */
+function update_site_meta( $site_id, $meta_key, $meta_value, $prev_value = '' ) {
+	if ( ! is_site_meta_supported() || is_core_site_meta_key( $meta_key ) ) {
+		return false;
+	}
+
+	$updated = update_metadata( 'blog', $site_id, $meta_key, $meta_value, $prev_value );
+
+	// Bust site query cache.
+	if ( $updated ) {
+		wp_cache_set( 'last_changed', microtime(), 'sites' );
+	}
+
+	return $updated;
+}
+
+/**
+ * Delete everything from site meta matching meta key.
+ *
+ * @since 4.8.0
+ *
+ * @param string $meta_key Metadata key to search for when deleting.
+ * @return bool Whether the site meta key was deleted from the database.
+ */
+function delete_site_meta_by_key( $meta_key ) {
+	if ( ! is_site_meta_supported() || is_core_site_meta_key( $meta_key ) ) {
+		return false;
+	}
+
+	return delete_metadata( 'blog', null, $meta_key, '', true );
+}
+
+/**
+ * Returns whether a given site meta key is one of the core site meta keys.
+ *
+ * @since 4.8.0
+ *
+ * @param string $meta_key Metadata key to check.
+ * @return bool True if the metadata key is one of the core site meta keys,
+ *              otherwise false.
+ */
+function is_core_site_meta_key( $meta_key ) {
+	return in_array( $meta_key, get_core_site_meta_keys(), true );
+}
+
+/**
+ * Returns the list of core site meta keys.
+ *
+ * @since 4.8.0
+ *
+ * @return array Core site meta keys.
+ */
+function get_core_site_meta_keys() {
+	return array(
+		 'blogname',
+		 'siteurl',
+		 'post_count',
+		 'home',
+		 'blog_public',
+		 'WPLANG',
+		 'blogdescription',
+		 'admin_email',
+		 'db_version'
+	);
+}
+
+/**
+ * Returns whether site meta is supported by this installation.
+ *
+ * By default this depends on the database version, however site meta can
+ * optionally be disabled completely using the {@see 'site_meta_supported'}
+ * filter.
+ *
+ * @since 4.8.0
+ *
+ * @return bool True if site meta is supported, otherwise false.
+ */
+function is_site_meta_supported() {
+	$supported = get_option( 'db_version' ) >= 40000;
+
+	/**
+	 * Filters whether site meta is supported by this installation.
+	 *
+	 * @since 4.8.0
+	 *
+	 * @param bool $supported Whether site meta is supported.
+	 */
+	return apply_filters( 'site_meta_supported', $supported );
+}
+
+/**
  * Retrieve option value for a given blog id based on name of option.
  *
  * If the option does not exist or does not have a value, then the return value
@@ -831,7 +1050,7 @@
 			if ( is_array( $global_groups ) ) {
 				wp_cache_add_global_groups( $global_groups );
 			} else {
-				wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site-details' ) );
+				wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site-details', 'blog_meta' ) );
 			}
 			wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) );
 		}
@@ -905,7 +1124,7 @@
 			if ( is_array( $global_groups ) ) {
 				wp_cache_add_global_groups( $global_groups );
 			} else {
-				wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site-details' ) );
+				wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site-details', 'blog_meta' ) );
 			}
 			wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) );
 		}
Index: src/wp-includes/version.php
===================================================================
--- src/wp-includes/version.php	(revision 40306)
+++ src/wp-includes/version.php	(working copy)
@@ -11,7 +11,7 @@
  *
  * @global int $wp_db_version
  */
-$wp_db_version = 38590;
+$wp_db_version = 40000;
 
 /**
  * Holds the TinyMCE version
Index: src/wp-includes/wp-db.php
===================================================================
--- src/wp-includes/wp-db.php	(revision 40306)
+++ src/wp-includes/wp-db.php	(working copy)
@@ -298,7 +298,7 @@
 	 * @see wpdb::tables()
 	 * @var array
 	 */
-	var $ms_global_tables = array( 'blogs', 'signups', 'site', 'sitemeta',
+	var $ms_global_tables = array( 'blogs', 'blogmeta', 'signups', 'site', 'sitemeta',
 		'sitecategories', 'registration_log', 'blog_versions' );
 
 	/**
@@ -423,6 +423,15 @@
 	public $blogs;
 
 	/**
+	 * Multisite Blog Metadata table
+	 *
+	 * @since 4.8.0
+	 * @access public
+	 * @var string
+	 */
+	public $blogmeta;
+
+	/**
 	 * Multisite Blog Versions table
 	 *
 	 * @since 3.0.0
Index: tests/phpunit/tests/multisite/siteMeta.php
===================================================================
--- tests/phpunit/tests/multisite/siteMeta.php	(nonexistent)
+++ tests/phpunit/tests/multisite/siteMeta.php	(working copy)
@@ -0,0 +1,374 @@
+<?php
+
+if ( is_multisite() ) :
+/**
+ * @group ms-site
+ * @group multisite
+ * @group meta
+ * @ticket 37923
+ */
+class Tests_Multisite_Site_Meta extends WP_UnitTestCase {
+	protected static $site_id;
+	protected static $site_id2;
+
+	public static function wpSetUpBeforeClass( $factory ) {
+		self::$site_id = $factory->blog->create( array( 'domain' => 'wordpress.org', 'path' => '/' ) );
+		self::$site_id2 = $factory->blog->create( array( 'domain' => 'wordpress.org', 'path' => '/foo/' ) );
+	}
+
+	public static function wpTearDownAfterClass() {
+		wpmu_delete_blog( self::$site_id, true );
+		wpmu_delete_blog( self::$site_id2, true );
+
+		wp_update_network_site_counts();
+	}
+
+	public function test_add() {
+		if ( ! is_site_meta_supported() ) {
+			$this->markTestSkipped( 'Test only runs when site meta is supported' );
+		}
+
+		$this->assertNotEmpty( add_site_meta( self::$site_id, 'foo', 'bar' ) );
+	}
+
+	public function test_add_unique() {
+		if ( ! is_site_meta_supported() ) {
+			$this->markTestSkipped( 'Test only runs when site meta is supported' );
+		}
+
+		$this->assertNotEmpty( add_site_meta( self::$site_id, 'foo', 'bar' ) );
+		$this->assertFalse( add_site_meta( self::$site_id, 'foo', 'bar', true ) );
+	}
+
+	public function test_delete() {
+		if ( ! is_site_meta_supported() ) {
+			$this->markTestSkipped( 'Test only runs when site meta is supported' );
+		}
+
+		add_site_meta( self::$site_id, 'foo', 'bar' );
+
+		$this->assertTrue( delete_site_meta( self::$site_id, 'foo' ) );
+	}
+
+	public function test_delete_with_invalid_meta_key_should_return_false() {
+		if ( ! is_site_meta_supported() ) {
+			$this->markTestSkipped( 'Test only runs when site meta is supported' );
+		}
+
+		$this->assertFalse( delete_site_meta( self::$site_id, 'foo' ) );
+	}
+
+	public function test_delete_should_respect_meta_value() {
+		if ( ! is_site_meta_supported() ) {
+			$this->markTestSkipped( 'Test only runs when site meta is supported' );
+		}
+
+		add_site_meta( self::$site_id, 'foo', 'bar' );
+		add_site_meta( self::$site_id, 'foo', 'baz' );
+
+		$this->assertTrue( delete_site_meta( self::$site_id, 'foo', 'bar' ) );
+
+		$metas = get_site_meta( self::$site_id, 'foo', false );
+		$this->assertSame( array( 'baz' ), $metas );
+	}
+
+	public function test_get_with_no_key_should_fetch_all_keys() {
+		if ( ! is_site_meta_supported() ) {
+			$this->markTestSkipped( 'Test only runs when site meta is supported' );
+		}
+
+		add_site_meta( self::$site_id, 'foo', 'bar' );
+		add_site_meta( self::$site_id, 'foo1', 'baz' );
+
+		$found = get_site_meta( self::$site_id );
+		$expected = array(
+			'foo' => array( 'bar' ),
+			'foo1' => array( 'baz' ),
+		);
+
+		$this->assertEqualSets( $expected, $found );
+	}
+
+	public function test_get_with_key_should_fetch_all_for_key() {
+		if ( ! is_site_meta_supported() ) {
+			$this->markTestSkipped( 'Test only runs when site meta is supported' );
+		}
+
+		add_site_meta( self::$site_id, 'foo', 'bar' );
+		add_site_meta( self::$site_id, 'foo', 'baz' );
+		add_site_meta( self::$site_id, 'foo1', 'baz' );
+
+		$found = get_site_meta( self::$site_id, 'foo' );
+		$expected = array( 'bar', 'baz' );
+
+		$this->assertEqualSets( $expected, $found );
+	}
+
+	public function test_get_should_respect_single_true() {
+		if ( ! is_site_meta_supported() ) {
+			$this->markTestSkipped( 'Test only runs when site meta is supported' );
+		}
+
+		add_site_meta( self::$site_id, 'foo', 'bar' );
+		add_site_meta( self::$site_id, 'foo', 'baz' );
+
+		$found = get_site_meta( self::$site_id, 'foo', true );
+		$this->assertEquals( 'bar', $found );
+	}
+
+	public function test_update_should_pass_to_add_when_no_value_exists_for_key() {
+		if ( ! is_site_meta_supported() ) {
+			$this->markTestSkipped( 'Test only runs when site meta is supported' );
+		}
+
+		$actual = update_site_meta( self::$site_id, 'foo', 'bar' );
+		$this->assertInternalType( 'int', $actual );
+		$this->assertNotEmpty( $actual );
+
+		$meta = get_site_meta( self::$site_id, 'foo', true );
+		$this->assertSame( 'bar', $meta );
+	}
+
+	public function test_update_should_return_true_when_updating_existing_value_for_key() {
+		if ( ! is_site_meta_supported() ) {
+			$this->markTestSkipped( 'Test only runs when site meta is supported' );
+		}
+
+		add_site_meta( self::$site_id, 'foo', 'bar' );
+
+		$actual = update_site_meta( self::$site_id, 'foo', 'baz' );
+		$this->assertTrue( $actual );
+
+		$meta = get_site_meta( self::$site_id, 'foo', true );
+		$this->assertSame( 'baz', $meta );
+	}
+
+	public function test_delete_by_key() {
+		if ( ! is_site_meta_supported() ) {
+			$this->markTestSkipped( 'Test only runs when site meta is supported' );
+		}
+
+		add_site_meta( self::$site_id, 'unique_delete_by_key', 'value', true );
+		add_site_meta( self::$site_id2, 'unique_delete_by_key', 'value', true );
+
+		$this->assertEquals( 'value', get_site_meta( self::$site_id, 'unique_delete_by_key', true ) );
+		$this->assertEquals( 'value', get_site_meta( self::$site_id2, 'unique_delete_by_key', true ) );
+
+		$this->assertTrue( delete_site_meta_by_key( 'unique_delete_by_key' ) );
+
+		$this->assertEquals( '', get_site_meta( self::$site_id, 'unique_delete_by_key', true ) );
+		$this->assertEquals( '', get_site_meta( self::$site_id2, 'unique_delete_by_key', true ) );
+	}
+
+	/**
+	 * @dataProvider data_get_core_keys
+	 */
+	public function test_add_fails_for_core_key( $key ) {
+		if ( ! is_site_meta_supported() ) {
+			$this->markTestSkipped( 'Test only runs when site meta is supported' );
+		}
+
+		$this->assertFalse( add_site_meta( self::$site_id, $key, 'foo' ) );
+	}
+
+	/**
+	 * @dataProvider data_get_core_keys
+	 */
+	public function test_update_fails_for_core_key( $key ) {
+		if ( ! is_site_meta_supported() ) {
+			$this->markTestSkipped( 'Test only runs when site meta is supported' );
+		}
+
+		$this->assertFalse( update_site_meta( self::$site_id, $key, 'foo' ) );
+	}
+
+	/**
+	 * @dataProvider data_get_core_keys
+	 */
+	public function test_delete_fails_for_core_key( $key ) {
+		if ( ! is_site_meta_supported() ) {
+			$this->markTestSkipped( 'Test only runs when site meta is supported' );
+		}
+
+		$this->assertFalse( delete_site_meta( self::$site_id, $key ) );
+	}
+
+	/**
+	 * @dataProvider data_get_core_keys
+	 */
+	public function test_delete_by_key_fails_for_core_key( $key ) {
+		if ( ! is_site_meta_supported() ) {
+			$this->markTestSkipped( 'Test only runs when site meta is supported' );
+		}
+
+		$this->assertFalse( delete_site_meta_by_key( $key ) );
+	}
+
+	public function data_get_core_keys() {
+		return array(
+			array( 'blogname' ),
+			array( 'siteurl' ),
+			array( 'post_count' ),
+			array( 'home' ),
+			array( 'blog_public' ),
+			array( 'WPLANG' ),
+			array( 'blogdescription' ),
+			array( 'admin_email' ),
+			array( 'db_version' ),
+		);
+	}
+
+	public function test_adding_site_meta_should_bust_get_sites_cache() {
+		if ( ! is_site_meta_supported() ) {
+			$this->markTestSkipped( 'Test only runs when site meta is supported' );
+		}
+
+		add_site_meta( self::$site_id, 'foo', 'bar' );
+
+		// Prime cache.
+		$found = get_sites( array(
+			'fields' => 'ids',
+			'meta_query' => array(
+				array(
+					'key' => 'foo',
+					'value' => 'bar',
+				),
+			),
+		) );
+
+		$this->assertEqualSets( array( self::$site_id ), $found );
+
+		add_site_meta( self::$site_id2, 'foo', 'bar' );
+
+		$found = get_sites( array(
+			'fields' => 'ids',
+			'meta_query' => array(
+				array(
+					'key' => 'foo',
+					'value' => 'bar',
+				),
+			),
+		) );
+
+		$this->assertEqualSets( array( self::$site_id, self::$site_id2 ), $found );
+	}
+
+	public function test_updating_site_meta_should_bust_get_sites_cache() {
+		if ( ! is_site_meta_supported() ) {
+			$this->markTestSkipped( 'Test only runs when site meta is supported' );
+		}
+
+		add_site_meta( self::$site_id, 'foo', 'bar' );
+		add_site_meta( self::$site_id2, 'foo', 'baz' );
+
+		// Prime cache.
+		$found = get_sites( array(
+			'fields' => 'ids',
+			'meta_query' => array(
+				array(
+					'key' => 'foo',
+					'value' => 'bar',
+				),
+			),
+		) );
+
+		$this->assertEqualSets( array( self::$site_id ), $found );
+
+		update_site_meta( self::$site_id2, 'foo', 'bar' );
+
+		$found = get_sites( array(
+			'fields' => 'ids',
+			'meta_query' => array(
+				array(
+					'key' => 'foo',
+					'value' => 'bar',
+				),
+			),
+		) );
+
+		$this->assertEqualSets( array( self::$site_id, self::$site_id2 ), $found );
+	}
+
+	public function test_deleting_site_meta_should_bust_get_sites_cache() {
+		if ( ! is_site_meta_supported() ) {
+			$this->markTestSkipped( 'Test only runs when site meta is supported' );
+		}
+
+		add_site_meta( self::$site_id, 'foo', 'bar' );
+		add_site_meta( self::$site_id2, 'foo', 'bar' );
+
+		// Prime cache.
+		$found = get_sites( array(
+			'fields' => 'ids',
+			'meta_query' => array(
+				array(
+					'key' => 'foo',
+					'value' => 'bar',
+				),
+			),
+		) );
+
+		$this->assertEqualSets( array( self::$site_id, self::$site_id2 ), $found );
+
+		delete_site_meta( self::$site_id2, 'foo', 'bar' );
+
+		$found = get_sites( array(
+			'fields' => 'ids',
+			'meta_query' => array(
+				array(
+					'key' => 'foo',
+					'value' => 'bar',
+				),
+			),
+		) );
+
+		$this->assertEqualSets( array( self::$site_id ), $found );
+	}
+
+	public function test_get_sites_bypass_meta_query_without_site_meta_support() {
+		add_filter( 'site_meta_supported', '__return_false' );
+
+		$found = get_sites( array(
+			'fields' => 'ids',
+			'domain' => 'wordpress.org',
+			'path'   => '/',
+			'meta_query' => array(
+				array(
+					'key' => 'foo',
+					'value' => 'baz',
+				),
+			),
+		) );
+
+		remove_filter( 'site_meta_supported', '__return_false' );
+
+		$this->assertEqualSets( array( self::$site_id ), $found );
+	}
+
+	public function test_site_meta_should_be_deleted_when_term_is_deleted() {
+		$site_id = self::factory()->blog->create( array( 'domain' => 'foo.org', 'path' => '/' ) );
+
+		add_site_meta( $site_id, 'foo', 'bar' );
+		add_site_meta( $site_id, 'foo1', 'bar' );
+
+		$this->assertSame( 'bar', get_site_meta( $site_id, 'foo', true ) );
+		$this->assertSame( 'bar', get_site_meta( $site_id, 'foo1', true ) );
+
+		wpmu_delete_blog( $site_id, true );
+
+		$this->assertSame( '', get_site_meta( $site_id, 'foo', true ) );
+		$this->assertSame( '', get_site_meta( $site_id, 'foo1', true ) );
+	}
+
+	public function test_site_meta_supported() {
+		add_filter( 'site_meta_supported', '__return_false' );
+
+		$result = is_site_meta_supported();
+
+		remove_filter( 'site_meta_supported', '__return_false' );
+
+		$this->assertFalse( $result );
+	}
+}
+
+endif;
