Index: www/wp-includes/class-wp-object-type.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- www/wp-includes/class-wp-object-type.php	(revision )
+++ www/wp-includes/class-wp-object-type.php	(revision )
@@ -0,0 +1,502 @@
+<?php
+
+/**
+ * Class WP_Object_Type
+ *
+ * Object Type is an infrastructure class used to classify fields and forms with
+ * other potential classification use cases in the future.
+ *
+ * Registered fields are often intended to be for specific post types and as such
+ * post types need to be specified. However, Fields should not be specific to
+ * post types as fields would be beneficial for users, comments, options, and more.
+ *
+ * So the Object Type was designed to capture and allow developers to specify both
+ * the $type of object (i.e. 'post', 'user', 'comment', etc.) as well as the $subtype
+ * specific to the type, (i.e. 'post', 'page', 'attachment', etc. for Object Types
+ * of $class 'post.')
+ *
+ * Object Types literals are specified in string form with a colon separating $class
+ * from $subtype, which looks like this:
+ *
+ *    'post:post'
+ *    'post:page'
+ *    'post:attachment'
+ *    'post:my_post_type'
+ *
+ * Object can be comparied with $object_type where is_object($object_type) is
+ * true (because of the Object Type's __toString() method.):
+ *
+ *    $object_type = new WP_Object_Type( 'post:my_post_type' );
+ *
+ *    if ( 'post:my_post_type' == $object_type ) {
+ *       echo 'They *are* equal!'
+ *    }
+ *
+ * The 'any' subtype will match any item of the specified $class, and if subtype
+ * is ommitted then it implies 'any'. All of these are equivalent:
+ *
+ *    'post:any'
+ *    'post:'
+ *    'post'
+ *
+ * If the colon is ommitted from an Object Type string literal then the Object Type's
+ * $class is assumed to be 'post'
+ *
+ *    $object_type = new WP_Object_Type( 'my_post_type' );
+ *
+ *    if ( 'post:my_post_type' == $object_type ) {
+ *       echo 'This is equal too.'
+ *    }
+ *
+ * You can specify any other $subtype besides 'post', with or withouta colon. If there is no
+ * $subtype then it will default to 'any'. All of these groups of three are equivalent.
+ *
+ *    'term'
+ *    'term:'
+ *    'term:any'
+ *
+ *    'user'
+ *    'user:'
+ *    'user:any'
+ *
+ *    'comment'
+ *    'comment:'
+ *    'comment:any'
+ *
+ *
+ * Object Types can be reused by using the assign() method:
+ *
+ *    $post_types = get_post_types( array( '_builtin' => false ) );
+ *    $object_type = new WP_Object_Type()
+ *    foreach( $post_types as $post_type ) {
+ *        $object_type->assign( $post_type );
+ *        // Do something with $object_type
+ *    }
+ *
+ * It's also possible to instantiate an Object Type with an associative array:
+ *
+ *    $object_type = new WP_Object_Type( array(
+ *      'type' => 'post',
+ *      'subtype' => 'my_post_type',
+ *    );
+ *
+ */
+final class WP_Object_Type {
+
+	/**
+	 * The $type property is used to contain the type of object such as 'post',
+	 * 'user', 'comment', 'option', etc.
+	 *
+	 * @var null|string
+	 */
+	var $type = null;
+
+	/**
+	 * The $subtype property is to contain the 'type' relevant to the Object Type's
+	 * $class, i.e. for 'post' there is 'post', 'page', 'attachment' and whatever
+	 * custom post types have been defined.
+	 *
+	 * For $class values of 'user' we are currently assuming role will used for $subtype.
+	 *
+	 * For all other $class values the value of $subtype is TBD.
+	 *
+	 * @var null|string
+	 */
+	var $subtype = null;
+
+	/**
+	 * List of Short Types
+	 *
+	 * @var array
+	 */
+	protected static $_short_types = array(
+		'post'        => 'p',
+		'term'        => 't',
+		'user'        => 'u',
+		'comment'     => 'c',
+	);
+
+	/**
+	 * Initialize an Object Type object with an optional Object Type literal string passed
+	 * in to represent the object type:
+	 *
+	 * @example
+	 *
+	 *    $object_type = new WP_Object_Type( 'my_post_type' );
+	 *
+	 * An Object Type can effectively be cloned by passing an Object Type object instead
+	 * of a literal, i.e.
+	 *
+	 *    $object_type = new WP_Object_Type( 'my_post_type' );
+	 *    $object_type2 = new WP_Object_Type( $object_type );
+	 *
+	 *    if ( (string)$object_type == (string)$object_type2 ) {
+	 *       echo 'This is equal.'
+	 *    }
+	 *    if ( 'post:my_post_type' == $object_type ) {
+	 *       echo 'And this is equal.'
+	 *    }
+	 *    if ( 'post:my_post_type' == $object_type2 ) {
+	 *       echo 'And this is also equal.'
+	 *    }
+	 *    if ( $object_type === $object_type2 ) {
+	 *       echo 'But this is NOT equal.'
+	 *    }
+	 *
+	 * Passing in an object is useful in functions that might be called directly by
+	 * a developer with an object literal but might be also called indirectly where
+	 * the Object Type literal string had already been replaced with its object
+	 * equivalent.
+	 *
+	 * It's also possible to instantiate an Object Type with an associative array:
+	 *
+	 *    $object_type = new WP_Object_Type( array(
+	 *      'type' => 'post',
+	 *      'subtype' => 'my_post_type',
+	 *    );
+	 *
+	 * @param bool|string|array|object $object_type
+	 */
+	function __construct( $object_type = false ) {
+
+		if ( ! empty( $object_type ) ) {
+
+			$this->assign( $object_type );
+
+			if ( ! in_array( $object_type, self::object_types() ) ) {
+				_doing_it_wrong( __FUNCTION__, sprintf( __( 'Invalid object type: %s.' ), $object_type ), '4.6.0' );
+			}
+
+		}
+
+	}
+
+	/**
+	 * Validates and assigns a value to this Object Type
+	 *
+	 * @example:
+	 *
+	 *    $object_type = new WP_Object_Type();
+	 *    $object_type->assign( 'post:my_type' )
+	 *
+	 * Which is equivalent to:
+	 *
+	 *    $object_type = new WP_Object_Type( 'post:my_type' )
+	 *
+	 * @param bool|string|array|WP_Object_Type $object_type
+	 *
+	 * @todo Add error handling for invalid type.
+	 *
+	 */
+	function assign( $object_type = false ) {
+
+		do {
+
+			if ( empty( $object_type ) ) {
+
+				trigger_error( __METHOD__ . '() cannot be called with an empty or missing parameter.' );
+
+			}
+
+			if ( is_a( $object_type, __CLASS__ ) ) {
+
+				/**
+				 * If a WP_Object_Type object was passed in then copy it's values.
+				 *
+				 * @see The PHPDoc for __construct() to understand why accepting an
+				 *      object in addition to a string literal is useful.
+				 */
+				$this->type    = $object_type->type;
+
+				$this->subtype = $object_type->subtype;
+
+				break;
+
+			}
+
+			if ( is_object( $object_type ) ) {
+
+				/**
+				 * If another type object grab its ->type and ->subtype properties,
+				 * if it has them.
+				 *
+				 * @see The PHPDoc for __construct() to understand why accepting an
+				 *      object in addition to a string literal is useful.
+				 */
+				$this->type    = isset( $object_type->type )
+					? $object_type->type
+					: null;
+
+				$this->subtype = isset( $object_type->subtype ) && is_string( $object_type->subtype )
+					? $object_type->subtype
+					: null;
+
+				break;
+
+			}
+
+			if ( is_array( $object_type ) && 2 === count( $object_type ) && isset( $object_type[0] ) && isset( $object_type[1] ) ) {
+
+				/**
+				 * A 2 element numerically indexed array where the first element is
+				 * $class and the 2nd is $subtype. So assign it.
+				 */
+
+				list( $this->type, $this->subtype ) = $object_type;
+
+				break;
+
+			}
+
+			if ( is_array( $object_type ) ) {
+
+				/*
+				 * Assumes the $object_type passed in is either an associative array with 'type'
+				 * and 'subtype' properties or an object that is not of class WP_Object_Type with
+				 * $class and $subtype properties
+				 *
+				 * Not sure why an object not of type WP_Object_Type would ever be needed, but if
+				 * someone finds a need for it this this method will support initializing from its
+				 * property values.
+				 *
+				 * Convert the array to object and call recursively.
+				 */
+				$this->assign( (object) $object_type );
+				break;
+
+			}
+
+			if ( is_string( $object_type ) && false !== strpos( $object_type, ':' ) ) {
+
+				/**
+				 * Otherwise split the Object Type literal on a the colon and assign
+				 * to $class and $subtype, respectively.
+				 */
+				list( $this->type, $this->subtype ) = explode( ':', $object_type );
+
+				break;
+			}
+
+			if ( is_string( $object_type ) ) {
+
+				/**
+				 * And the literal contains no colon it is a type,
+				 * and its subtype is 'any'
+				 * and the string literal passed in is the $subtype (often used
+				 * with custom post types.)
+				 */
+				$this->type    = $object_type;
+				break;
+
+			}
+
+		} while ( false );
+
+
+
+		if ( $this->type && is_string( $this->type ) ) {
+
+			/**
+			 *  Ensure $class is sanitized to be a valid identifier
+			 */
+			$this->type = sanitize_title_with_dashes( $this->type );
+
+		}
+
+		if ( $this->subtype && is_string( $this->subtype ) ) {
+			/**
+			 *  Ensure $subtype is sanitized to be a valid identifier too, but only need to do if not empty.
+			 */
+			$this->subtype = sanitize_title_with_dashes( $this->subtype );
+
+		}
+
+		if ( $this->type && empty( $this->subtype ) ) {
+			/**
+			 * Lastly, if $subtype is still empty, set to 'any'.
+			 */
+			$this->subtype = 'any';
+
+		}
+
+
+		/**
+		 * Posts are the only object type with support for object sub types.
+		 *
+		 * @note Leaving this in because it was in 35658.4.diff patch but I don't feel it is needed.
+		 */
+		if ( 'post' !== $this->type ) {
+
+			/*
+			 * Set to 'any', even though we *could* support it
+			 * by just deleting these three lines
+			 */
+			$this->subtype = 'any';
+
+		}
+
+	}
+
+	/**
+	 * @return string[]
+	 */
+	static function object_types() {
+
+		return array_keys( self::$_short_types );
+
+	}
+
+	/**
+	 * @return string[]
+	 */
+	static function short_types() {
+
+		return self::$_short_types;
+
+	}
+
+	/**
+	 * @return bool
+	 */
+	function is_post_type() {
+
+		return 'post' === $this->type;
+
+	}
+
+	/**
+	 * @return bool
+	 */
+	function is_user_type() {
+
+		return 'user' === $this->type;
+
+	}
+
+	/**
+	 * @return bool
+	 */
+	function is_comment_type() {
+
+		return 'comment' === $this->type;
+
+	}
+
+	/**
+	 * @return bool
+	 */
+	function is_term_type() {
+
+		return 'term' === $this->type;
+
+	}
+
+	/**
+	 * Returns the shortest representation of type that is possible
+	 *
+	 * @return null|string
+	 */
+	function short_type() {
+
+		return ! empty( $this->type )
+			? self::$_short_types[ $this->type ]
+			: null;
+
+	}
+
+	/**
+	 * Returns a short representation of object type
+	 *
+	 * This is useful when you want to create a slug that idenfies a relationship
+	 * between two object_types but you have limited number of characters, such
+	 * as the wp_term_taxonomy->taxonomy field which is limited to 32 characters.
+	 *
+	 * @return null|string
+	 */
+	function short_object_type() {
+
+		if ( is_null( $this->subtype ) ) {
+
+			$short_object_type = $this->type;
+
+		} else if ( 'post' === $this->type ) {
+
+			if ( ! defined( 'WP_APP_PREFIX' ) ) {
+
+				$short_object_type = $this->subtype;
+
+			} else {
+
+				$regex = '#^' . preg_quote( WP_APP_PREFIX ) . '(.+)$#';
+				$short_object_type = preg_replace( $regex, '$1', $this->subtype );
+
+			}
+
+		} else {
+
+			$subtype = 'any' !== $this->subtype
+				? $this->subtype
+				: '';
+
+			$short_object_type = $this->short_type() . ":{$subtype}";
+
+		}
+
+		return $short_object_type;
+
+	}
+
+	/**
+	 * Check if the current Object Type is valid.
+	 *
+	 * Validity is determined by having a non-empty $type value.
+	 *
+	 * @return bool Is the Object Type valid?
+	 */
+	function is_valid() {
+
+		return ! empty( $this->type );
+
+	}
+
+	/**
+	 * Check if the current Object Type is equivalent to the one passed in.
+	 *
+	 * Equivalency is true if both objects have the same values for their $class and $subtype properties.
+	 *
+	 * If not parameter is passed then this method assume an object type based on the global $post object.
+	 *
+	 * @param WP_Object_Type|string|bool $object_type The Object Type to compare with $this.
+	 *
+	 * @return bool If $object_type is equivalent to $this.
+	 */
+	function is_equivalent( $object_type = false ) {
+
+		if ( ! is_a( $object_type, __CLASS__ ) ) {
+			/*
+			 * First check to see if the passed in parameter is a WP_Object_Type object.
+			 * If not, instantiate a new object with the passed $arg.
+			 */
+			$object_type = new self( $object_type );
+
+		}
+
+		/**
+		 * Check for object equivalency
+		 * Yes this is correct (if you thought it was not, like I did at first.)
+		 */
+		return $this == $object_type;
+
+	}
+
+	/**
+	 * Magic method to convert the Object Type into it's string literal form.
+	 *
+	 * @return string  An Object Type literal representing $this, the current Object Type.
+	 */
+	function __toString() {
+
+		return "{$this->type}:{$this->subtype}";
+
+	}
+}
Index: www/wp-includes/meta.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- www/wp-includes/meta.php	(revision 37822)
+++ www/wp-includes/meta.php	(revision )
@@ -17,7 +17,7 @@
  *
  * @global wpdb $wpdb WordPress database abstraction object.
  *
- * @param string $meta_type  Type of object metadata is for (e.g., comment, post, or user)
+ * @param WP_Object_Type|string $object_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.
@@ -27,10 +27,10 @@
  *                           no change will be made.
  * @return int|false The meta ID on success, false on failure.
  */
-function add_metadata($meta_type, $object_id, $meta_key, $meta_value, $unique = false) {
+function add_metadata( $object_type, $object_id, $meta_key, $meta_value, $unique = false ) {
 	global $wpdb;
 
-	if ( ! $meta_type || ! $meta_key || ! is_numeric( $object_id ) ) {
+	if ( ! $object_type || ! $meta_key || ! is_numeric( $object_id ) ) {
 		return false;
 	}
 
@@ -39,6 +39,12 @@
 		return false;
 	}
 
+	if ( ! $object_type instanceof WP_Object_Type ) {
+		$object_type = new WP_Object_Type( $object_type );
+	}
+
+	$meta_type = $object_type->type;
+
 	$table = _get_meta_table( $meta_type );
 	if ( ! $table ) {
 		return false;
@@ -66,8 +72,9 @@
 	 * @param mixed     $meta_value Meta value. Must be serializable if non-scalar.
 	 * @param bool      $unique     Whether the specified meta key should be unique
 	 *                              for the object. Optional. Default false.
+	 * @param WP_Object_Type    $object_type  Type and subtype of object
 	 */
-	$check = apply_filters( "add_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $unique );
+	$check = apply_filters( "add_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $unique, $object_type );
 	if ( null !== $check )
 		return $check;
 
@@ -90,8 +97,9 @@
 	 * @param int    $object_id  Object ID.
 	 * @param string $meta_key   Meta key.
 	 * @param mixed  $meta_value Meta value.
+	 * @param WP_Object_Type    $object_type  Type and subtype of object
 	 */
-	do_action( "add_{$meta_type}_meta", $object_id, $meta_key, $_meta_value );
+	do_action( "add_{$meta_type}_meta", $object_id, $meta_key, $_meta_value, $object_type );
 
 	$result = $wpdb->insert( $table, array(
 		$column => $object_id,
@@ -118,8 +126,9 @@
 	 * @param int    $object_id  Object ID.
 	 * @param string $meta_key   Meta key.
 	 * @param mixed  $meta_value Meta value.
+	 * @param WP_Object_Type    $object_type  Type and subtype of object
 	 */
-	do_action( "added_{$meta_type}_meta", $mid, $object_id, $meta_key, $_meta_value );
+	do_action( "added_{$meta_type}_meta", $mid, $object_id, $meta_key, $_meta_value, $object_type );
 
 	return $mid;
 }
@@ -132,7 +141,7 @@
  *
  * @global wpdb $wpdb WordPress database abstraction object.
  *
- * @param string $meta_type  Type of object metadata is for (e.g., comment, post, or user)
+ * @param WP_Object_Type|string $object_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.
@@ -140,10 +149,10 @@
  * 		                     the specified value. Otherwise, update all entries.
  * @return int|bool Meta ID if the key didn't exist, true on successful update, false on failure.
  */
-function update_metadata($meta_type, $object_id, $meta_key, $meta_value, $prev_value = '') {
+function update_metadata( $object_type, $object_id, $meta_key, $meta_value, $prev_value = '' ) {
 	global $wpdb;
 
-	if ( ! $meta_type || ! $meta_key || ! is_numeric( $object_id ) ) {
+	if ( ! $object_type || ! $meta_key || ! is_numeric( $object_id ) ) {
 		return false;
 	}
 
@@ -152,6 +161,12 @@
 		return false;
 	}
 
+	if ( ! $object_type instanceof WP_Object_Type ) {
+		$object_type = new WP_Object_Type( $object_type );
+	}
+
+	$meta_type = $object_type->type;
+
 	$table = _get_meta_table( $meta_type );
 	if ( ! $table ) {
 		return false;
@@ -183,8 +198,9 @@
 	 * @param mixed     $prev_value Optional. If specified, only update existing
 	 *                              metadata entries with the specified value.
 	 *                              Otherwise, update all entries.
+	 * @param WP_Object_Type    $object_type  Type and subtype of object
 	 */
-	$check = apply_filters( "update_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $prev_value );
+	$check = apply_filters( "update_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $prev_value, $object_type );
 	if ( null !== $check )
 		return (bool) $check;
 
@@ -226,8 +242,9 @@
 		 * @param int    $object_id  Object ID.
 		 * @param string $meta_key   Meta key.
 		 * @param mixed  $meta_value Meta value.
+		 * @param WP_Object_Type    $object_type  Type and subtype of object
 		 */
-		do_action( "update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value );
+		do_action( "update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value, $object_type );
 
 		if ( 'post' == $meta_type ) {
 			/**
@@ -239,8 +256,9 @@
 			 * @param int    $object_id  Object ID.
 			 * @param string $meta_key   Meta key.
 			 * @param mixed  $meta_value Meta value.
+			 * @param WP_Object_Type    $object_type  Type and subtype of object
 			 */
-			do_action( 'update_postmeta', $meta_id, $object_id, $meta_key, $meta_value );
+			do_action( 'update_postmeta', $meta_id, $object_id, $meta_key, $meta_value, $object_type );
 		}
 	}
 
@@ -263,8 +281,9 @@
 		 * @param int    $object_id  Object ID.
 		 * @param string $meta_key   Meta key.
 		 * @param mixed  $meta_value Meta value.
+		 * @param WP_Object_Type    $object_type  Type and subtype of object
 		 */
-		do_action( "updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value );
+		do_action( "updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value, $object_type );
 
 		if ( 'post' == $meta_type ) {
 			/**
@@ -276,8 +295,9 @@
 			 * @param int    $object_id  Object ID.
 			 * @param string $meta_key   Meta key.
 			 * @param mixed  $meta_value Meta value.
+			 * @param WP_Object_Type    $object_type  Type and subtype of object
 			 */
-			do_action( 'updated_postmeta', $meta_id, $object_id, $meta_key, $meta_value );
+			do_action( 'updated_postmeta', $meta_id, $object_id, $meta_key, $meta_value, $object_type );
 		}
 	}
 
@@ -291,7 +311,7 @@
  *
  * @global wpdb $wpdb WordPress database abstraction object.
  *
- * @param string $meta_type  Type of object metadata is for (e.g., comment, post, or user)
+ * @param WP_Object_Type|string $object_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
@@ -304,10 +324,10 @@
  *                           the specified object_id.
  * @return bool True on successful delete, false on failure.
  */
-function delete_metadata($meta_type, $object_id, $meta_key, $meta_value = '', $delete_all = false) {
+function delete_metadata( $object_type, $object_id, $meta_key, $meta_value = '', $delete_all = false ) {
 	global $wpdb;
 
-	if ( ! $meta_type || ! $meta_key || ! is_numeric( $object_id ) && ! $delete_all ) {
+	if ( ! $object_type || ! $meta_key || ! is_numeric( $object_id ) && ! $delete_all ) {
 		return false;
 	}
 
@@ -316,6 +336,12 @@
 		return false;
 	}
 
+	if ( ! $object_type instanceof WP_Object_Type ) {
+		$object_type = new WP_Object_Type( $object_type );
+	}
+
+	$meta_type = $object_type->type;
+
 	$table = _get_meta_table( $meta_type );
 	if ( ! $table ) {
 		return false;
@@ -343,8 +369,9 @@
 	 * @param bool      $delete_all Whether to delete the matching metadata entries
 	 *                              for all objects, ignoring the specified $object_id.
 	 *                              Default false.
+	 * @param WP_Object_Type    $object_type  Type and subtype of object
 	 */
-	$check = apply_filters( "delete_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $delete_all );
+	$check = apply_filters( "delete_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $delete_all, $object_type );
 	if ( null !== $check )
 		return (bool) $check;
 
@@ -384,8 +411,9 @@
 	 * @param int    $object_id  Object ID.
 	 * @param string $meta_key   Meta key.
 	 * @param mixed  $meta_value Meta value.
+	 * @param WP_Object_Type    $object_type  Type and subtype of object
 	 */
-	do_action( "delete_{$meta_type}_meta", $meta_ids, $object_id, $meta_key, $_meta_value );
+	do_action( "delete_{$meta_type}_meta", $meta_ids, $object_id, $meta_key, $_meta_value, $object_type );
 
 	// Old-style action.
 	if ( 'post' == $meta_type ) {
@@ -395,8 +423,9 @@
 		 * @since 2.9.0
 		 *
 		 * @param array $meta_ids An array of post metadata entry IDs to delete.
+		 * @param WP_Object_Type    $object_type  Type and subtype of object
 		 */
-		do_action( 'delete_postmeta', $meta_ids );
+		do_action( 'delete_postmeta', $meta_ids, $object_type );
 	}
 
 	$query = "DELETE FROM $table WHERE $id_column IN( " . implode( ',', $meta_ids ) . " )";
@@ -426,8 +455,9 @@
 	 * @param int    $object_id  Object ID.
 	 * @param string $meta_key   Meta key.
 	 * @param mixed  $meta_value Meta value.
+	 * @param WP_Object_Type    $object_type  Type and subtype of object
 	 */
-	do_action( "deleted_{$meta_type}_meta", $meta_ids, $object_id, $meta_key, $_meta_value );
+	do_action( "deleted_{$meta_type}_meta", $meta_ids, $object_id, $meta_key, $_meta_value, $object_type );
 
 	// Old-style action.
 	if ( 'post' == $meta_type ) {
@@ -437,8 +467,9 @@
 		 * @since 2.9.0
 		 *
 		 * @param array $meta_ids An array of deleted post metadata entry IDs.
+		 * @param WP_Object_Type    $object_type  Type and subtype of object
 		 */
-		do_action( 'deleted_postmeta', $meta_ids );
+		do_action( 'deleted_postmeta', $meta_ids, $object_type );
 	}
 
 	return true;
@@ -449,7 +480,7 @@
  *
  * @since 2.9.0
  *
- * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user)
+ * @param WP_Object_Type|string $object_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  Optional. Metadata key. If not specified, retrieve all metadata for
  * 		                    the specified object.
@@ -458,8 +489,9 @@
  *                          This parameter has no effect if meta_key is not specified.
  * @return mixed Single metadata value, or array of values
  */
-function get_metadata($meta_type, $object_id, $meta_key = '', $single = false) {
-	if ( ! $meta_type || ! is_numeric( $object_id ) ) {
+function get_metadata( $object_type, $object_id, $meta_key = '', $single = false ) {
+
+	if ( ! $object_type || ! is_numeric( $object_id ) ) {
 		return false;
 	}
 
@@ -468,6 +500,12 @@
 		return false;
 	}
 
+	if ( ! $object_type instanceof WP_Object_Type ) {
+		$object_type = new WP_Object_Type( $object_type );
+	}
+
+	$meta_type = $object_type->type;
+
 	/**
 	 * Filters whether to retrieve metadata of a specific type.
 	 *
@@ -482,8 +520,9 @@
 	 * @param int               $object_id Object ID.
 	 * @param string            $meta_key  Meta key.
 	 * @param bool              $single    Whether to return only the first value of the specified $meta_key.
+	 * @param WP_Object_Type    $object_type  Type and subtype of object
 	 */
-	$check = apply_filters( "get_{$meta_type}_metadata", null, $object_id, $meta_key, $single );
+	$check = apply_filters( "get_{$meta_type}_metadata", null, $object_id, $meta_key, $single, $object_type );
 	if ( null !== $check ) {
 		if ( $single && is_array( $check ) )
 			return $check[0];
@@ -520,13 +559,13 @@
  *
  * @since 3.3.0
  *
- * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user)
+ * @param WP_Object_Type|string $object_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.
  * @return bool True of the key is set, false if not.
  */
-function metadata_exists( $meta_type, $object_id, $meta_key ) {
-	if ( ! $meta_type || ! is_numeric( $object_id ) ) {
+function metadata_exists( $object_type, $object_id, $meta_key ) {
+	if ( ! $object_type || ! is_numeric( $object_id ) ) {
 		return false;
 	}
 
@@ -535,8 +574,14 @@
 		return false;
 	}
 
+	if ( ! $object_type instanceof WP_Object_Type ) {
+		$object_type = new WP_Object_Type( $object_type );
+	}
+
+	$meta_type = $object_type->type;
+
 	/** This filter is documented in wp-includes/meta.php */
-	$check = apply_filters( "get_{$meta_type}_metadata", null, $object_id, $meta_key, true );
+	$check = apply_filters( "get_{$meta_type}_metadata", null, $object_id, $meta_key, true , $object_type);
 	if ( null !== $check )
 		return (bool) $check;
 
@@ -560,14 +605,14 @@
  *
  * @global wpdb $wpdb WordPress database abstraction object.
  *
- * @param string $meta_type Type of object metadata is for (e.g., comment, post, term, or user).
+ * @param WP_Object_Type|string $object_type Type of object metadata is for (e.g., comment, post, or user)
  * @param int    $meta_id   ID for a specific meta row
  * @return object|false Meta object or false.
  */
-function get_metadata_by_mid( $meta_type, $meta_id ) {
+function get_metadata_by_mid( $object_type, $meta_id ) {
 	global $wpdb;
 
-	if ( ! $meta_type || ! is_numeric( $meta_id ) ) {
+	if ( ! $object_type || ! is_numeric( $meta_id ) ) {
 		return false;
 	}
 
@@ -576,6 +621,12 @@
 		return false;
 	}
 
+	if ( ! $object_type instanceof WP_Object_Type ) {
+		$object_type = new WP_Object_Type( $object_type );
+	}
+
+	$meta_type = $object_type->type;
+
 	$table = _get_meta_table( $meta_type );
 	if ( ! $table ) {
 		return false;
@@ -601,17 +652,17 @@
  *
  * @global wpdb $wpdb WordPress database abstraction object.
  *
- * @param string $meta_type  Type of object metadata is for (e.g., comment, post, or user)
+ * @param WP_Object_Type|string $object_type Type of object metadata is for (e.g., comment, post, or user)
  * @param int    $meta_id    ID for a specific meta row
  * @param string $meta_value Metadata value
- * @param string $meta_key   Optional, you can provide a meta key to update it
+ * @param string|bool $meta_key   Optional, you can provide a meta key to update it
  * @return bool True on successful update, false on failure.
  */
-function update_metadata_by_mid( $meta_type, $meta_id, $meta_value, $meta_key = false ) {
+function update_metadata_by_mid( $object_type, $meta_id, $meta_value, $meta_key = false ) {
 	global $wpdb;
 
 	// Make sure everything is valid.
-	if ( ! $meta_type || ! is_numeric( $meta_id ) ) {
+	if ( ! $object_type || ! is_numeric( $meta_id ) ) {
 		return false;
 	}
 
@@ -620,6 +671,12 @@
 		return false;
 	}
 
+	if ( ! $object_type instanceof WP_Object_Type ) {
+		$object_type = new WP_Object_Type( $object_type );
+	}
+
+	$meta_type = $object_type->type;
+
 	$table = _get_meta_table( $meta_type );
 	if ( ! $table ) {
 		return false;
@@ -657,11 +714,11 @@
 		$where[$id_column] = $meta_id;
 
 		/** This action is documented in wp-includes/meta.php */
-		do_action( "update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value );
+		do_action( "update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value, $object_type );
 
 		if ( 'post' == $meta_type ) {
 			/** This action is documented in wp-includes/meta.php */
-			do_action( 'update_postmeta', $meta_id, $object_id, $meta_key, $meta_value );
+			do_action( 'update_postmeta', $meta_id, $object_id, $meta_key, $meta_value, $object_type );
 		}
 
 		// Run the update query, all fields in $data are %s, $where is a %d.
@@ -673,11 +730,11 @@
 		wp_cache_delete($object_id, $meta_type . '_meta');
 
 		/** This action is documented in wp-includes/meta.php */
-		do_action( "updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value );
+		do_action( "updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value, $object_type );
 
 		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 );
+			do_action( 'updated_postmeta', $meta_id, $object_id, $meta_key, $meta_value, $object_type );
 		}
 
 		return true;
@@ -694,15 +751,15 @@
  *
  * @global wpdb $wpdb WordPress database abstraction object.
  *
- * @param string $meta_type Type of object metadata is for (e.g., comment, post, term, or user).
+ * @param WP_Object_Type|string $object_type Type of object metadata is for (e.g., comment, post, or user)
  * @param int    $meta_id   ID for a specific meta row
  * @return bool True on successful delete, false on failure.
  */
-function delete_metadata_by_mid( $meta_type, $meta_id ) {
+function delete_metadata_by_mid( $object_type, $meta_id ) {
 	global $wpdb;
 
 	// Make sure everything is valid.
-	if ( ! $meta_type || ! is_numeric( $meta_id ) ) {
+	if ( ! $object_type || ! is_numeric( $meta_id ) ) {
 		return false;
 	}
 
@@ -711,6 +768,12 @@
 		return false;
 	}
 
+	if ( ! $object_type instanceof WP_Object_Type ) {
+		$object_type = new WP_Object_Type( $object_type );
+	}
+
+	$meta_type = $object_type->type;
+
 	$table = _get_meta_table( $meta_type );
 	if ( ! $table ) {
 		return false;
@@ -725,7 +788,7 @@
 		$object_id = $meta->{$column};
 
 		/** This action is documented in wp-includes/meta.php */
-		do_action( "delete_{$meta_type}_meta", (array) $meta_id, $object_id, $meta->meta_key, $meta->meta_value );
+		do_action( "delete_{$meta_type}_meta", (array) $meta_id, $object_id, $meta->meta_key, $meta->meta_value, $object_type );
 
 		// Old-style action.
 		if ( 'post' == $meta_type || 'comment' == $meta_type ) {
@@ -738,8 +801,9 @@
 			 * @since 3.4.0
 			 *
 			 * @param int $meta_id ID of the metadata entry to delete.
+			 * @param WP_Object_Type    $object_type  Type and subtype of object
 			 */
-			do_action( "delete_{$meta_type}meta", $meta_id );
+			do_action( "delete_{$meta_type}meta", $meta_id, $object_type );
 		}
 
 		// Run the query, will return true if deleted, false otherwise
@@ -749,7 +813,7 @@
 		wp_cache_delete($object_id, $meta_type . '_meta');
 
 		/** 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 );
+		do_action( "deleted_{$meta_type}_meta", (array) $meta_id, $object_id, $meta->meta_key, $meta->meta_value, $object_type );
 
 		// Old-style action.
 		if ( 'post' == $meta_type || 'comment' == $meta_type ) {
@@ -762,8 +826,9 @@
 			 * @since 3.4.0
 			 *
 			 * @param int $meta_ids Deleted metadata entry ID.
+			 * @param WP_Object_Type    $object_type  Type and subtype of object
 			 */
-			do_action( "deleted_{$meta_type}meta", $meta_id );
+			do_action( "deleted_{$meta_type}meta", $meta_id, $object_type );
 		}
 
 		return $result;
@@ -781,17 +846,23 @@
  *
  * @global wpdb $wpdb WordPress database abstraction object.
  *
- * @param string    $meta_type  Type of object metadata is for (e.g., comment, post, or user)
+ * @param WP_Object_Type|string $object_type Type of object metadata is for (e.g., comment, post, or user)
  * @param int|array $object_ids Array or comma delimited list of object IDs to update cache for
  * @return array|false Metadata cache for the specified objects, or false on failure.
  */
-function update_meta_cache($meta_type, $object_ids) {
+function update_meta_cache( $object_type, $object_ids) {
 	global $wpdb;
 
-	if ( ! $meta_type || ! $object_ids ) {
+	if ( ! $object_type || ! $object_ids ) {
 		return false;
 	}
 
+	if ( ! $object_type instanceof WP_Object_Type ) {
+		$object_type = new WP_Object_Type( $object_type );
+	}
+
+	$meta_type = $object_type->type;
+
 	$table = _get_meta_table( $meta_type );
 	if ( ! $table ) {
 		return false;
@@ -894,14 +965,18 @@
  *
  * @global wpdb $wpdb WordPress database abstraction object.
  *
- * @param string $type Type of object to get metadata table for (e.g., comment, post, or user)
+ * @param WP_Object_Type|string $object_type Type of object metadata is for (e.g., comment, post, or user)
  * @return string|false Metadata table name, or false if no metadata table exists
  */
-function _get_meta_table($type) {
+function _get_meta_table( $object_type ) {
 	global $wpdb;
 
-	$table_name = $type . 'meta';
+	if ( ! $object_type instanceof WP_Object_Type ) {
+		$object_type = new WP_Object_Type( $object_type );
+	}
 
+	$table_name = $object_type->type . 'meta';
+
 	if ( empty($wpdb->$table_name) )
 		return false;
 
@@ -914,10 +989,10 @@
  * @since 3.1.3
  *
  * @param string      $meta_key Meta key
- * @param string|null $meta_type
+ * @param WP_Object_Type|string|null $object_type Type of object metadata is for (e.g., comment, post, or user)
  * @return bool True if the key is protected, false otherwise.
  */
-function is_protected_meta( $meta_key, $meta_type = null ) {
+function is_protected_meta( $meta_key, $object_type = null ) {
 	$protected = ( '_' == $meta_key[0] );
 
 	/**
@@ -929,21 +1004,27 @@
 	 * @param string $meta_key  Meta key.
 	 * @param string $meta_type Meta type.
 	 */
-	return apply_filters( 'is_protected_meta', $protected, $meta_key, $meta_type );
+	return apply_filters( 'is_protected_meta', $protected, $meta_key, $object_type->type, $object_type );
 }
 
 /**
  * Sanitize meta value.
  *
  * @since 3.1.3
+ * @since 4.6.0 Added the `$object_subtype` parameter.
  *
- * @param string $meta_key   Meta key
- * @param mixed  $meta_value Meta value to sanitize
- * @param string $meta_type  Type of meta
- * @return mixed Sanitized $meta_value
+ * @param string $meta_key       Meta key.
+ * @param mixed  $meta_value     Meta value to sanitize.
+ * @param WP_Object_Type|string $object_type  Type of object the meta is registered to.
+ *
+ * @return mixed Sanitized $meta_value.
  */
-function sanitize_meta( $meta_key, $meta_value, $meta_type ) {
+function sanitize_meta( $meta_key, $meta_value, $object_type ) {
 
+	if ( ! $object_type instanceof WP_Object_Type ) {
+		$object_type = new WP_Object_Type( $object_type );
+	}
+
 	/**
 	 * Filters the sanitization of a specific meta key of a specific meta type.
 	 *
@@ -958,30 +1039,244 @@
 	 * @param string $meta_key   Meta key.
 	 * @param string $meta_type  Meta type.
 	 */
-	return apply_filters( "sanitize_{$meta_type}_meta_{$meta_key}", $meta_value, $meta_key, $meta_type );
+	return apply_filters( "sanitize_{$object_type->type}_meta_{$meta_key}", $meta_value, $meta_key, $object_type );
 }
 
 /**
- * Register meta key
+ * Registers a meta key.
  *
  * @since 3.3.0
+ * @since 4.6.0 Modified to support an array of data to attach to registered meta keys. Previous arguments for
+ *              `$sanitize_callback` and `$auth_callback` have been folded into this array.
  *
- * @param string       $meta_type         Type of meta
- * @param string       $meta_key          Meta key
- * @param string|array $sanitize_callback A function or method to call when sanitizing the value of $meta_key.
- * @param string|array $auth_callback     Optional. A function or method to call when performing edit_post_meta, add_post_meta, and delete_post_meta capability checks.
+ * @param WP_Object_Type|string $object_type  Type of object the meta is registered to.
+ * @param string $meta_key                    Meta key to register.
+ * @param array  $args {
+ *     Data used to describe the meta key when registered.
+ *
+ *     @type string   $sanitize_callback A function or method to call when sanitizing `$meta_key` data.
+ *     @type string   $auth_callback     Optional. A function or method to call when performing edit_post_meta, add_post_meta, and delete_post_meta capability checks.
+ *     @type string   $type              The type of data associated with this meta key.
+ *     @type string   $description       A description of the data attached to this meta key.
+ *     @type bool     $show_in_rest      Whether data associated with this meta key can be considered public.
+ * }
  */
-function register_meta( $meta_type, $meta_key, $sanitize_callback, $auth_callback = null ) {
-	if ( is_callable( $sanitize_callback ) )
-		add_filter( "sanitize_{$meta_type}_meta_{$meta_key}", $sanitize_callback, 10, 3 );
+function register_meta( $object_type, $meta_key, $args ) {
+	global $wp_meta_keys;
 
-	if ( empty( $auth_callback ) ) {
-		if ( is_protected_meta( $meta_key, $meta_type ) )
-			$auth_callback = '__return_false';
-		else
-			$auth_callback = '__return_true';
+	if ( ! $object_type instanceof WP_Object_Type ) {
+		$object_type = new WP_Object_Type( $object_type );
 	}
 
-	if ( is_callable( $auth_callback ) )
-		add_filter( "auth_{$meta_type}_meta_{$meta_key}", $auth_callback, 10, 6 );
+	if ( ! is_array( $wp_meta_keys ) ) {
+		$wp_meta_keys = array();
+	}
+
+	$meta_args = (object) array(
+		'sanitize_callback' => null,
+		'old_sanitize_callback' => null,
+		'auth_callback' => null,
+		'old_auth_callback' => null,
+		'object_subtype' => '',
+		'type' => 'string',
+		'description' => '',
+		'show_in_rest' => false,
+	);
+
+	$passed_args = array_slice( func_get_args(), 2 );
+
+	if ( is_callable( $passed_args[0] ) ) {
+		$meta_args->old_sanitize_callback = $passed_args[0];
+	} elseif ( isset( $passed_args[0]['sanitize_callback'] ) ) {
+		$meta_args->sanitize_callback = $passed_args[0]['sanitize_callback'];
+	}
+
+	if ( isset( $passed_args[1] ) && is_callable( $passed_args[1] ) ) {
+		$meta_args->old_auth_callback = $passed_args[1];
+	} elseif ( isset( $passed_args[0]['auth_callback'] ) ) {
+		$meta_args->auth_callback = $passed_args[0]['auth_callback'];
+	}
+
+	if ( isset( $passed_args[0]['show_in_rest'] ) && $passed_args[0]['show_in_rest'] ) {
+		$meta_args->show_in_rest = true;
+	}
+
+	if ( isset( $passed_args[0]['type'] ) ) {
+		$meta_args->type = $passed_args[0]['type'];
+	}
+
+	if ( isset( $passed_args[0]['description'] ) ) {
+		$meta_args->description = $passed_args[0]['description'];
+	}
+
+	$wp_meta_keys[ $object_type->type ][ $object_type->subtype ][ $meta_key ] = $args;
+
+	if ( is_callable( $meta_args->old_sanitize_callback ) ) {
+		add_filter( "sanitize_{$object_type->type}_meta_{$meta_key}", $meta_args->old_sanitize_callback, 10, 3 );
+	}
+
+	if ( is_callable( $meta_args->sanitize_callback ) ) {
+		add_filter( "sanitize_{$object_type->type}_meta_{$meta_key}", $meta_args->sanitize_callback, 10, 3 );
+	}
+
+	// If neither new or legacy `auth_callback` is provided, fallback to `is_protected_meta()`.
+	if ( empty( $meta_args->auth_callback ) && empty( $meta_args->old_auth_callback ) ) {
+		if ( is_protected_meta( $meta_key, $object_type ) ) {
+			$meta_args->auth_callback = '__return_false';
+		} else {
+			$meta_args->auth_callback = '__return_true';
+		}
+	}
+
+	// The auth here is currently used to edit or add meta, not to view, and only for posts.
+	if ( 'post' === $object_type->type && is_callable( $meta_args->old_auth_callback ) ) {
+		add_filter( "auth_{$object_type->type}_meta_{$meta_key}", $meta_args->old_auth_callback, 10, 6 );
+	}
+
+	if ( 'post' === $object_type->type && is_callable( $meta_args->auth_callback ) ) {
+		add_filter( "auth_{$object_type->type}_meta_{$meta_key}", $meta_args->auth_callback, 10, 6 );
+	}
+}
+
+/**
+ * Checks if a meta key is registered.
+ *
+ * @since 4.6.0
+ *
+ * @param WP_Object_Type|string $object_type  Type of object the meta is registered to.
+ * @param string $meta_key
+ *
+ * @return bool True if the meta key is registered to the object type and subtype. False if not.
+ */
+function registered_meta_key_exists( $object_type, $meta_key ) {
+	global $wp_meta_keys;
+
+	if ( ! is_array( $wp_meta_keys ) ) {
+		return false;
+	}
+
+	if ( ! $object_type instanceof WP_Object_Type ) {
+		$object_type = new WP_Object_Type( $object_type );
+	}
+
+	if ( ! isset( $wp_meta_keys[ $object_type->type ] ) ) {
+		return false;
+	}
+
+	if ( ! isset( $wp_meta_keys[ $object_type->type ][ $object_type->subtype ] ) ) {
+		return false;
+	}
+
+	if ( isset( $wp_meta_keys[ $object_type->type ][ $object_type->subtype ][ $meta_key ] ) ) {
+		return true;
+	}
+
+	return false;
+}
+
+/**
+ * Unregisters a meta key from the list of registered keys.
+ *
+ * @since 4.6.0
+ *
+ * @param WP_Object_Type|string $object_type  Type of object the meta is registered to.
+ * @param string $meta_key       The meta key.
+ *
+ * @return bool|WP_Error True if successful. WP_Error if the meta key is invalid.
+ */
+function unregister_meta_key( $object_type, $meta_key ) {
+	global $wp_meta_keys;
+
+	if ( ! registered_meta_key_exists( $object_type, $meta_key ) ) {
+		return new WP_Error( 'invalid_meta_key', __( 'Invalid meta key' ) );
+	}
+
+	if ( ! $object_type instanceof WP_Object_Type ) {
+		$object_type = new WP_Object_Type( $object_type );
+	}
+
+	unset( $wp_meta_keys[ $object_type->type ][ $object_type->subtype ][ $meta_key ] );
+
+	return true;
+}
+
+/**
+ * Retrieves a list of registered meta keys for an object type and subtype.
+ *
+ * @since 4.6.0
+ *
+ * @param WP_Object_Type|string $object_type  Type of object the meta is registered to.
+ *
+ * @return array List of registered meta keys.
+ */
+function get_registered_meta_keys( $object_type ) {
+	global $wp_meta_keys;
+
+	if ( ! $object_type instanceof WP_Object_Type ) {
+		$object_type = new WP_Object_Type( $object_type );
+	}
+
+	if ( ! isset( $wp_meta_keys[ $object_type->type ] ) ) {
+		return array();
+	}
+
+	if ( ! isset( $wp_meta_keys[ $object_type->type ][ $object_type->subtype ] ) ) {
+		return array();
+	}
+
+	return $wp_meta_keys[ $object_type->type ][ $object_type->subtype ];
+}
+
+/**
+ * Retrieves registered metadata for a specified object.
+ *
+ * @since 4.6.0
+ *
+ * @param WP_Object_Type|string $object_type  Type of object to request metadata for. (e.g. comment, post, term, user)
+ * @param int    $object_id      ID of the object the metadata is for.
+ * @param string $meta_key       Optional. Registered metadata key. If not specified, retrieve all registered
+ *                               metadata for the specified object.
+ *
+ * @return mixed|WP_Error
+ */
+function get_registered_metadata( $object_type, $object_id, $meta_key = '' ) {
+	global $wp_meta_keys;
+	
+	if ( ! is_array( $wp_meta_keys ) ) {
+		return new WP_Error( 'invalid_meta_key', __( 'Invalid meta key. Not registered.' ) );
+	}
+
+	if ( ! $object_type instanceof WP_Object_Type ) {
+		$object_type = new WP_Object_Type( $object_type );
+	}
+	
+	if ( 'post' === $object_type->type ) {
+		$object_type->subtype = get_post_type( $object_id );
+	}
+
+	if( ! empty( $meta_key ) ) {
+		if ( ! registered_meta_key_exists( $object_type, $meta_key ) ) {
+			return new WP_Error( 'invalid_meta_key', __( 'Invalid meta key. Not registered.' ) );
+		}
+		$meta_keys = get_registered_meta_keys( $object_type );
+		$meta_key_data = $meta_keys[ $object_type->type ][ $object_type->subtype ][ $meta_key ];
+
+		$data = get_metadata( $object_type, $object_id, $meta_key, $meta_key_data->single );
+
+		return $data;
+	}
+
+	$data = get_metadata( $object_type->type, $object_id, $meta_key );
+
+	$meta_keys = get_registered_meta_keys( $object_type );
+
+    $registered_data = array();
+
+	foreach( $meta_keys as $k => $v ) {
+		if ( isset( $data[ $k ] ) ) {
+			$registered_data[ $k ] = $data[ $k ];
+		}
+	}
+
+	return $registered_data;
 }
