Index: src/wp-includes/comment.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/wp-includes/comment.php	(revision 43435)
+++ src/wp-includes/comment.php	(date 1531068183000)
@@ -441,11 +441,7 @@
  * @return int|bool Meta ID on success, false on failure.
  */
 function add_comment_meta( $comment_id, $meta_key, $meta_value, $unique = false ) {
-	$added = add_metadata( 'comment', $comment_id, $meta_key, $meta_value, $unique );
-	if ( $added ) {
-		wp_cache_set( 'last_changed', microtime(), 'comment' );
-	}
-	return $added;
+	return add_metadata( 'comment', $comment_id, $meta_key, $meta_value, $unique );
 }
 
 /**
@@ -464,11 +460,7 @@
  * @return bool True on success, false on failure.
  */
 function delete_comment_meta( $comment_id, $meta_key, $meta_value = '' ) {
-	$deleted = delete_metadata( 'comment', $comment_id, $meta_key, $meta_value );
-	if ( $deleted ) {
-		wp_cache_set( 'last_changed', microtime(), 'comment' );
-	}
-	return $deleted;
+	return delete_metadata( 'comment', $comment_id, $meta_key, $meta_value );
 }
 
 /**
@@ -505,11 +497,7 @@
  * @return int|bool Meta ID if the key didn't exist, true on successful update, false on failure.
  */
 function update_comment_meta( $comment_id, $meta_key, $meta_value, $prev_value = '' ) {
-	$updated = update_metadata( 'comment', $comment_id, $meta_key, $meta_value, $prev_value );
-	if ( $updated ) {
-		wp_cache_set( 'last_changed', microtime(), 'comment' );
-	}
-	return $updated;
+	return update_metadata( 'comment', $comment_id, $meta_key, $meta_value, $prev_value );
 }
 
 /**
Index: src/wp-includes/default-filters.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/wp-includes/default-filters.php	(revision 43435)
+++ src/wp-includes/default-filters.php	(date 1531070093000)
@@ -97,6 +97,20 @@
 
 // Meta
 add_filter( 'register_meta_args', '_wp_register_meta_args_whitelist', 10, 2 );
+add_action( 'add_metadata', 'clean_object_last_changed', 10, 2 );
+add_action( 'update_metadata', 'clean_object_last_changed', 10, 2 );
+add_action( 'delete_metadata', 'clean_object_last_changed', 10, 2 );
+
+add_filter( 'update_term_metadata', '_disable_term_meta', 10, 1 );
+add_filter( 'add_term_metadata', '_disable_term_meta', 10, 1 );
+add_filter( 'delete_term_metadata', '_disable_term_meta', 10, 1 );
+add_filter( 'get_term_metadata', '_disable_term_meta', 10, 1 );
+add_filter( 'update_term_meta_cache', '_disable_term_meta', 10, 1 );
+
+add_filter( 'update_term_metadata', '_check_shared_term_meta', 10, 2 );
+add_filter( 'add_term_metadata', '_check_shared_term_meta', 10, 2 );
+add_filter( 'delete_term_metadata', '_check_shared_term_meta', 10, 2 );
+
 
 // Places to balance tags on input
 foreach ( array( 'content_save_pre', 'excerpt_save_pre', 'comment_save_pre', 'pre_comment_content' ) as $filter ) {
Index: src/wp-includes/functions.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/wp-includes/functions.php	(revision 43435)
+++ src/wp-includes/functions.php	(date 1531069035000)
@@ -4798,6 +4798,19 @@
 	return (bool) $supported;
 }
 
+
+/**
+ * Determines whether term meta is enabled.
+ *
+ * @since x.x.x
+
+ *
+ * @return bool True if term meta is supported, false otherwise.
+ */
+function is_term_meta_supported() {
+	return ( get_option( 'db_version' ) < 34370 );
+}
+
 /**
  * gmt_offset modification for smart timezone handling.
  *
Index: src/wp-includes/meta.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/wp-includes/meta.php	(revision 43435)
+++ src/wp-includes/meta.php	(date 1531071484000)
@@ -131,6 +131,23 @@
 	 */
 	do_action( "added_{$meta_type}_meta", $mid, $object_id, $meta_key, $_meta_value );
 
+	/**
+	 * Fires immediately after meta of a specific type is added.
+	 *
+	 *
+	 * @since x.x.x
+	 *
+	 * @param string $meta_type  Type of object metadata is for (e.g., comment, post, or user)
+	 * @param int    $object_id  ID of the object metadata is for
+	 * @param string $meta_key   Metadata key
+	 * @param mixed  $meta_value Metadata value. Must be serializable if non-scalar.
+	 * @param bool   $unique     Optional, default is false.
+	 *                           Whether the specified metadata key should be unique for the object.
+	 *                           If true, and the object already has a value for the specified metadata key,
+	 *                           no change will be made.
+	 */
+	do_action( "add_metadata", $meta_type, $object_id, $meta_key, $meta_value, $unique );
+
 	return $mid;
 }
 
@@ -299,6 +316,18 @@
 		}
 	}
 
+	/**
+	 * Fires immediately after updating metadata of a specific type.
+	 *
+	 * @since x.x.x
+	 *
+	 * @param string $meta_type  Type of object metadata is for (e.g., comment, post, or user)
+	 * @param int    $object_id  ID of the object metadata is for
+	 * @param string $meta_key   Metadata key
+	 * @param mixed  $meta_value Metadata value. Must be serializable if non-scalar.
+	 */
+	do_action( "update_metadata", $meta_type, $object_id, $meta_key, $_meta_value );
+
 	return true;
 }
 
@@ -463,6 +492,25 @@
 		do_action( 'deleted_postmeta', $meta_ids );
 	}
 
+	/**
+	 * Fires immediately after deleting metadata of a specific type.
+	 *
+	 * @since x.x.x
+	 *
+	 * @param string $meta_type  Type of object metadata is for (e.g., comment, post, or user)
+	 * @param int    $object_id  ID of the object metadata is for
+	 * @param string $meta_key   Metadata key
+	 * @param mixed  $meta_value Optional. Metadata value. Must be serializable if non-scalar. If specified, only delete
+	 *                           metadata entries with this value. Otherwise, delete all entries with the specified meta_key.
+	 *                           Pass `null`, `false`, or an empty string to skip this check. (For backward compatibility,
+	 *                           it is not possible to pass an empty string to delete those entries with an empty string
+	 *                           for a value.)
+	 * @param bool   $delete_all Optional, default is false. If true, delete matching metadata entries for all objects,
+	 *                           ignoring the specified object_id. Otherwise, only delete matching metadata entries for
+	 *                           the specified object_id.
+	 */
+	do_action( "delete_metadata", $meta_type, $object_id, $meta_key, $meta_value, $delete_all );
+
 	return true;
 }
 
@@ -707,6 +755,9 @@
 		/** This action is documented in wp-includes/meta.php */
 		do_action( "updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value );
 
+		/** This action is documented in wp-includes/meta.php */
+		do_action( "update_metadata", $meta_type, $object_id, $meta_key, $_meta_value );
+
 		if ( 'post' == $meta_type ) {
 			/** This action is documented in wp-includes/meta.php */
 			do_action( 'updated_postmeta', $meta_id, $object_id, $meta_key, $meta_value );
@@ -783,6 +834,9 @@
 		/** This action is documented in wp-includes/meta.php */
 		do_action( "deleted_{$meta_type}_meta", (array) $meta_id, $object_id, $meta->meta_key, $meta->meta_value );
 
+		/** This action is documented in wp-includes/meta.php */
+		do_action( "delete_metadata", $meta_type, $object_id, $meta->meta_key, $meta->meta_value , false );
+
 		// Old-style action.
 		if ( 'post' == $meta_type || 'comment' == $meta_type ) {
 			/**
@@ -841,12 +895,25 @@
 	$cache_key = $meta_type . '_meta';
 	$ids       = array();
 	$cache     = array();
-	foreach ( $object_ids as $id ) {
-		$cached_object = wp_cache_get( $id, $cache_key );
+	foreach ( $object_ids as $object_id ) {
+		/**
+		 * Filters whether to update metadata cache of a specific type.
+		 *
+		 * @since x.x.x
+		 *
+		 * @param null|bool $check      Whether to allow updating metadata cache for the given type.
+		 * @param int       $object_id  Object ID.
+		 **/
+		$check = apply_filters( "update_{$meta_type}_meta_cache", null, $object_id );
+		if ( null !== $check ) {
+			return (bool) $check;
+		}
+
+		$cached_object = wp_cache_get( $object_id, $cache_key );
 		if ( false === $cached_object ) {
-			$ids[] = $id;
+			$ids[] = $object_id;
 		} else {
-			$cache[ $id ] = $cached_object;
+			$cache[ $object_id ] = $cached_object;
 		}
 	}
 
@@ -1360,3 +1427,51 @@
 	 */
 	return apply_filters( "get_object_subtype_{$object_type}", $object_subtype, $object_id );
 }
+
+
+/**
+ *
+ * @since x.x.x
+ *
+ * @param  string $meta_type   Type of object metadata is for (e.g., comment, post, or user)
+ * @param  int    $object_id   ID of the object.
+ * @return bool
+ */
+function clean_object_last_changed( $meta_type, $object_id = 0 ) {
+	switch ( $meta_type ) {
+		case 'blog':
+			$group = 'sites';
+			break;
+		case 'user':
+			$group = 'users';
+			break;
+		case 'term':
+			$group = 'terms';
+			break;
+		case 'comment':
+			$group = 'comment';
+			break;
+		case 'post':
+			$group = 'posts';
+			break;
+		default:
+			$group = false;
+			break;
+	}
+
+	/**
+	 *
+	 * @since x.x.x
+	 *
+	 * @param string $group      Group string to override.
+	 * @param string $meta_type  Type of object metadata is for (e.g., comment, post, or user)
+	 * @param int    $object_id  ID of the object to get the subtype for.
+	 */
+	$group = apply_filters( "get_object_cache_group", $group, $meta_type, $object_id );
+
+	if ( ! $group ) {
+		return false;
+	}
+
+	return wp_cache_set( 'last_changed', microtime(), $group );
+}
\ No newline at end of file
Index: src/wp-includes/ms-blogs.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/wp-includes/ms-blogs.php	(revision 43435)
+++ src/wp-includes/ms-blogs.php	(date 1531070899000)
@@ -618,11 +618,20 @@
  * @return array|false Returns false if there is nothing to update. Returns an array of metadata on success.
  */
 function update_sitemeta_cache( $site_ids ) {
+	return update_meta_cache( 'blog', $site_ids );
+}
+
+/**
+ * @param $value
+ *
+ * @return mixed
+ */
+function _disable_site_meta( $value ) {
 	if ( ! is_site_meta_supported() ) {
 		return false;
 	}
 
-	return update_meta_cache( 'blog', $site_ids );
+	return $value;
 }
 
 /**
@@ -838,21 +847,7 @@
  * @return int|false Meta ID on success, false on failure.
  */
 function add_site_meta( $site_id, $meta_key, $meta_value, $unique = false ) {
-	// Bail if site meta table is not installed.
-	if ( ! is_site_meta_supported() ) {
-		/* translators: %s: database table name */
-		_doing_it_wrong( __FUNCTION__, sprintf( __( 'The %s table is not installed. Please run the network database upgrade.' ), $GLOBALS['wpdb']->blogmeta ), '5.0.0' );
-		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;
+	return add_metadata( 'blog', $site_id, $meta_key, $meta_value, $unique );
 }
 
 /**
@@ -871,21 +866,7 @@
  * @return bool True on success, false on failure.
  */
 function delete_site_meta( $site_id, $meta_key, $meta_value = '' ) {
-	// Bail if site meta table is not installed.
-	if ( ! is_site_meta_supported() ) {
-		/* translators: %s: database table name */
-		_doing_it_wrong( __FUNCTION__, sprintf( __( 'The %s table is not installed. Please run the network database upgrade.' ), $GLOBALS['wpdb']->blogmeta ), '5.0.0' );
-		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;
+	return delete_metadata( 'blog', $site_id, $meta_key, $meta_value );
 }
 
 /**
@@ -901,13 +882,6 @@
  *               field if $single is true.
  */
 function get_site_meta( $site_id, $key = '', $single = false ) {
-	// Bail if site meta table is not installed.
-	if ( ! is_site_meta_supported() ) {
-		/* translators: %s: database table name */
-		_doing_it_wrong( __FUNCTION__, sprintf( __( 'The %s table is not installed. Please run the network database upgrade.' ), $GLOBALS['wpdb']->blogmeta ), '5.0.0' );
-		return false;
-	}
-
 	return get_metadata( 'blog', $site_id, $key, $single );
 }
 
@@ -930,21 +904,7 @@
  *                  false on failure.
  */
 function update_site_meta( $site_id, $meta_key, $meta_value, $prev_value = '' ) {
-	// Bail if site meta table is not installed.
-	if ( ! is_site_meta_supported() ) {
-		/* translators: %s: database table name */
-		_doing_it_wrong( __FUNCTION__, sprintf( __( 'The %s table is not installed. Please run the network database upgrade.' ), $GLOBALS['wpdb']->blogmeta ), '5.0.0' );
-		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;
+	return update_metadata( 'blog', $site_id, $meta_key, $meta_value, $prev_value );
 }
 
 /**
@@ -956,21 +916,7 @@
  * @return bool Whether the site meta key was deleted from the database.
  */
 function delete_site_meta_by_key( $meta_key ) {
-	// Bail if site meta table is not installed.
-	if ( ! is_site_meta_supported() ) {
-		/* translators: %s: database table name */
-		_doing_it_wrong( __FUNCTION__, sprintf( __( 'The %s table is not installed. Please run the network database upgrade.' ), $GLOBALS['wpdb']->blogmeta ), '5.0.0' );
-		return false;
-	}
-
-	$deleted = delete_metadata( 'blog', null, $meta_key, '', true );
-
-	// Bust site query cache.
-	if ( $deleted ) {
-		wp_cache_set( 'last_changed', microtime(), 'sites' );
-	}
-
-	return $deleted;
+	return delete_metadata( 'blog', null, $meta_key, '', true );
 }
 
 /**
Index: src/wp-includes/ms-default-filters.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/wp-includes/ms-default-filters.php	(revision 43435)
+++ src/wp-includes/ms-default-filters.php	(date 1531070983000)
@@ -42,6 +42,13 @@
 add_action( 'wpmu_activate_blog', 'wpmu_welcome_notification', 10, 5 );
 add_action( 'after_signup_site', 'wpmu_signup_blog_notification', 10, 7 );
 
+// Meta
+add_filter( 'update_blog_metadata', '_disable_site_meta', 10, 1 );
+add_filter( 'add_blog_metadata', '_disable_site_meta', 10, 1 );
+add_filter( 'delete_blog_metadata', '_disable_site_meta', 10, 1 );
+add_filter( 'get_blog_metadata', '_disable_site_meta', 10, 1 );
+add_filter( 'update_blog_meta_cache', '_disable_site_meta', 10, 1 );
+
 // Register Nonce
 add_action( 'signup_hidden_fields', 'signup_nonce_fields' );
 
Index: src/wp-includes/post.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/wp-includes/post.php	(revision 43435)
+++ src/wp-includes/post.php	(date 1531067944000)
@@ -1917,11 +1917,7 @@
 		$post_id = $the_post;
 	}
 
-	$deleted = delete_metadata( 'post', $post_id, $meta_key, $meta_value );
-	if ( $deleted ) {
-		wp_cache_set( 'last_changed', microtime(), 'posts' );
-	}
-	return $deleted;
+	return delete_metadata( 'post', $post_id, $meta_key, $meta_value );
 }
 
 /**
@@ -1966,11 +1962,7 @@
 		$post_id = $the_post;
 	}
 
-	$updated = update_metadata( 'post', $post_id, $meta_key, $meta_value, $prev_value );
-	if ( $updated ) {
-		wp_cache_set( 'last_changed', microtime(), 'posts' );
-	}
-	return $updated;
+	return update_metadata( 'post', $post_id, $meta_key, $meta_value, $prev_value );
 }
 
 /**
@@ -1982,11 +1974,7 @@
  * @return bool Whether the post meta key was deleted from the database.
  */
 function delete_post_meta_by_key( $post_meta_key ) {
-	$deleted = delete_metadata( 'post', null, $post_meta_key, '', true );
-	if ( $deleted ) {
-		wp_cache_set( 'last_changed', microtime(), 'posts' );
-	}
-	return $deleted;
+	return delete_metadata( 'post', null, $post_meta_key, '', true );
 }
 
 /**
Index: src/wp-includes/taxonomy.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/wp-includes/taxonomy.php	(revision 43435)
+++ src/wp-includes/taxonomy.php	(date 1531070690000)
@@ -1180,23 +1180,7 @@
  *                           False on failure.
  */
 function add_term_meta( $term_id, $meta_key, $meta_value, $unique = false ) {
-	// Bail if term meta table is not installed.
-	if ( get_option( 'db_version' ) < 34370 ) {
-		return false;
-	}
-
-	if ( wp_term_is_shared( $term_id ) ) {
-		return new WP_Error( 'ambiguous_term_id', __( 'Term meta cannot be added to terms that are shared between taxonomies.' ), $term_id );
-	}
-
-	$added = add_metadata( 'term', $term_id, $meta_key, $meta_value, $unique );
-
-	// Bust term query cache.
-	if ( $added ) {
-		wp_cache_set( 'last_changed', microtime(), 'terms' );
-	}
-
-	return $added;
+	return add_metadata( 'term', $term_id, $meta_key, $meta_value, $unique );
 }
 
 /**
@@ -1210,19 +1194,7 @@
  * @return bool True on success, false on failure.
  */
 function delete_term_meta( $term_id, $meta_key, $meta_value = '' ) {
-	// Bail if term meta table is not installed.
-	if ( get_option( 'db_version' ) < 34370 ) {
-		return false;
-	}
-
-	$deleted = delete_metadata( 'term', $term_id, $meta_key, $meta_value );
-
-	// Bust term query cache.
-	if ( $deleted ) {
-		wp_cache_set( 'last_changed', microtime(), 'terms' );
-	}
-
-	return $deleted;
+	return delete_metadata( 'term', $term_id, $meta_key, $meta_value );
 }
 
 /**
@@ -1237,11 +1209,6 @@
  * @return mixed If `$single` is false, an array of metadata values. If `$single` is true, a single metadata value.
  */
 function get_term_meta( $term_id, $key = '', $single = false ) {
-	// Bail if term meta table is not installed.
-	if ( get_option( 'db_version' ) < 34370 ) {
-		return false;
-	}
-
 	return get_metadata( 'term', $term_id, $key, $single );
 }
 
@@ -1262,23 +1229,7 @@
  *                           WP_Error when term_id is ambiguous between taxonomies. False on failure.
  */
 function update_term_meta( $term_id, $meta_key, $meta_value, $prev_value = '' ) {
-	// Bail if term meta table is not installed.
-	if ( get_option( 'db_version' ) < 34370 ) {
-		return false;
-	}
-
-	if ( wp_term_is_shared( $term_id ) ) {
-		return new WP_Error( 'ambiguous_term_id', __( 'Term meta cannot be added to terms that are shared between taxonomies.' ), $term_id );
-	}
-
-	$updated = update_metadata( 'term', $term_id, $meta_key, $meta_value, $prev_value );
-
-	// Bust term query cache.
-	if ( $updated ) {
-		wp_cache_set( 'last_changed', microtime(), 'terms' );
-	}
-
-	return $updated;
+	return update_metadata( 'term', $term_id, $meta_key, $meta_value, $prev_value );
 }
 
 /**
@@ -1293,11 +1244,6 @@
  * @return array|false Returns false if there is nothing to update. Returns an array of metadata on success.
  */
 function update_termmeta_cache( $term_ids ) {
-	// Bail if term meta table is not installed.
-	if ( get_option( 'db_version' ) < 34370 ) {
-		return;
-	}
-
 	return update_meta_cache( 'term', $term_ids );
 }
 
@@ -1313,7 +1259,7 @@
  */
 function has_term_meta( $term_id ) {
 	// Bail if term meta table is not installed.
-	if ( get_option( 'db_version' ) < 34370 ) {
+	if ( ! is_term_meta_supported() ) {
 		return false;
 	}
 
@@ -1355,6 +1301,33 @@
 	return unregister_meta_key( 'term', $meta_key, $taxonomy );
 }
 
+/**
+ * @param $value
+ *
+ * @return mixed
+ */
+function _disable_term_meta( $value ) {
+	if ( ! is_term_meta_supported() ) {
+		return false;
+	}
+
+	return $value;
+}
+
+/**
+ * @param $value
+ * @param $term_id
+ *
+ * @return mixed
+ */
+function _check_shared_term_meta( $value, $term_id ) {
+	if ( wp_term_is_shared( $term_id ) ) {
+		return new WP_Error( 'ambiguous_term_id', __( 'Term meta cannot be added to terms that are shared between taxonomies.' ), $term_id );
+	}
+
+	return $value;
+}
+
 /**
  * Determines whether a term exists.
  *
Index: src/wp-includes/user.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/wp-includes/user.php	(revision 43435)
+++ src/wp-includes/user.php	(date 1531068470000)
@@ -1357,6 +1357,8 @@
 	wp_cache_delete( $user->user_email, 'useremail' );
 	wp_cache_delete( $user->user_nicename, 'userslugs' );
 
+	wp_cache_set( 'last_changed', microtime(), 'users' );
+
 	/**
 	 * Fires immediately after the given user's cache is cleaned.
 	 *
