<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[38095] trunk: Meta: Remove object subtype handling from `register_meta()`.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/38095">38095</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/38095","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>jeremyfelt</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2016-07-18 21:15:37 +0000 (Mon, 18 Jul 2016)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Meta: Remove object subtype handling from `register_meta()`.
Registration is now based solely on object type, which allows the code around this to be simplified significantly.
In the process of making this adjustment:
* `register_meta()`, `unregister_meta_key()`, `get_registered_metadata()`, and `registered_meta_key_exists()` no longer return `WP_Error` objects.
* The recently introduced `wp_object_type_exists()` function and the restriction on object type has been removed.
Note: No guarantee of uniqueness is made across object subtypes. Registered meta keys should be uniquely prefixed to avoid conflict.
Fixes <a href="https://core.trac.wordpress.org/ticket/35658">#35658</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesfunctionsphp">trunk/src/wp-includes/functions.php</a></li>
<li><a href="#trunksrcwpincludesmetaphp">trunk/src/wp-includes/meta.php</a></li>
<li><a href="#trunktestsphpunittestsmetaregisterMetaphp">trunk/tests/phpunit/tests/meta/registerMeta.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesfunctionsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/functions.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/functions.php 2016-07-18 19:42:48 UTC (rev 38094)
+++ trunk/src/wp-includes/functions.php 2016-07-18 21:15:37 UTC (rev 38095)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5358,31 +5358,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Check if an object type exists. By default, these are `post`, `comment`, `user`, and `term`.
- *
- * @since 4.6.0
- *
- * @param string $object_type Object type to check.
- * @return bool True if the object type exists, false if not.
- */
-function wp_object_type_exists( $object_type ) {
- /**
- * Filters WordPress object types.
- *
- * @since 4.6.0
- *
- * @param array $types Array of object types.
- */
- $types = apply_filters( 'wp_object_types', array( 'post', 'comment', 'user', 'term' ) );
-
- if ( in_array( $object_type, $types ) ) {
- return true;
- }
-
- return false;
-}
-
-/**
</del><span class="cx" style="display: block; padding: 0 10px"> * Attempts to raise the PHP memory limit for memory intensive processes.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * Only allows raising the existing limit and prevents lowering it.
</span></span></pre></div>
<a id="trunksrcwpincludesmetaphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/meta.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/meta.php 2016-07-18 19:42:48 UTC (rev 38094)
+++ trunk/src/wp-includes/meta.php 2016-07-18 21:15:37 UTC (rev 38095)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -936,34 +936,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Sanitize meta value.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 3.1.3
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @since 4.6.0 Added the `$object_subtype` parameter.
</del><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $meta_key Meta key.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param mixed $meta_value Meta value to sanitize.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $object_type Type of object the meta is registered to.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param string $object_subtype Optional. Subtype of object. Will inherit the object type by default.
</del><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @return mixed Sanitized $meta_value.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-function sanitize_meta( $meta_key, $meta_value, $object_type, $object_subtype = '' ) {
- if ( ! empty( $object_subtype ) ) {
- /**
- * Filters the sanitization of a specific meta key of a specific meta type and subtype.
- *
- * The dynamic portions of the hook name, `$meta_type`, `$meta_subtype`,
- * and `$meta_key`, refer to the metadata object type (comment, post, or user)
- * the object subtype, and the meta key value, respectively.
- *
- * @since 4.6.0
- *
- * @param mixed $meta_value Meta value to sanitize.
- * @param string $meta_key Meta key.
- * @param string $object_type Object type.
- * @param string $object_subtype Object subtype.
- */
- $meta_value = apply_filters( "sanitize_{$object_type}_{$object_subtype}_meta_{$meta_key}", $meta_value, $meta_key, $object_type, $object_subtype );
- }
-
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+function sanitize_meta( $meta_key, $meta_value, $object_type ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Filters the sanitization of a specific meta key of a specific meta type.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -972,14 +952,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * key value, respectively.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 3.3.0
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @since 4.6.0 Added the `$object_subtype` parameter.
</del><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param mixed $meta_value Meta value to sanitize.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $meta_key Meta key.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $object_type Object type.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param string $object_subtype Object subtype.
</del><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return apply_filters( "sanitize_{$object_type}_meta_{$meta_key}", $meta_value, $meta_key, $object_type, $object_subtype );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return apply_filters( "sanitize_{$object_type}_meta_{$meta_key}", $meta_value, $meta_key, $object_type );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -995,7 +973,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $args {
</span><span class="cx" style="display: block; padding: 0 10px"> * Data used to describe the meta key when registered.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @type string $object_subtype A subtype; e.g. if the object type is "post", the post type.
</del><span class="cx" style="display: block; padding: 0 10px"> * @type string $type The type of data associated with this meta key.
</span><span class="cx" style="display: block; padding: 0 10px"> * @type string $description A description of the data attached to this meta key.
</span><span class="cx" style="display: block; padding: 0 10px"> * @type bool $single Whether the meta key has one value per object, or an array of values per object.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1005,9 +982,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * }
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string|array $deprecated Deprecated. Use `$args` instead.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return bool|WP_error True if the meta key was successfully registered in the global array, WP_Error if not.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return bool True if the meta key was successfully registered in the global array, false if not.
</ins><span class="cx" style="display: block; padding: 0 10px"> * Registering a meta key with distinct sanitize and auth callbacks will fire those
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * callbacks, but will not add to the global registry as it requires a subtype.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * callbacks, but will not add to the global registry.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function register_meta( $object_type, $meta_key, $args, $deprecated = null ) {
</span><span class="cx" style="display: block; padding: 0 10px"> global $wp_meta_keys;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1016,12 +993,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $wp_meta_keys = array();
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! wp_object_type_exists( $object_type ) ) {
- return new WP_Error( 'register_meta_failed', __( 'Meta can only be registered against a core object type.' ) );
- }
-
</del><span class="cx" style="display: block; padding: 0 10px"> $defaults = array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'object_subtype' => '',
</del><span class="cx" style="display: block; padding: 0 10px"> 'type' => 'string',
</span><span class="cx" style="display: block; padding: 0 10px"> 'description' => '',
</span><span class="cx" style="display: block; padding: 0 10px"> 'single' => false,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1049,8 +1021,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $has_old_auth_cb = true;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $args = wp_parse_args( $args, $defaults );
-
</del><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Filters the registration arguments when registering meta.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1062,12 +1032,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $meta_key Meta key.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> $args = apply_filters( 'register_meta_args', $args, $defaults, $object_type, $meta_key );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $args = wp_parse_args( $args, $defaults );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Object subtype is required if using the args style of registration
- if ( ! $has_old_sanitize_cb && ! $has_old_auth_cb && empty( $args['object_subtype'] ) ) {
- return new WP_Error( 'register_meta_failed', __( 'Meta must be registered against an object subtype.' ) );
- }
-
</del><span class="cx" style="display: block; padding: 0 10px"> // If `auth_callback` is not provided, fall back to `is_protected_meta()`.
</span><span class="cx" style="display: block; padding: 0 10px"> if ( empty( $args['auth_callback'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( is_protected_meta( $meta_key, $object_type ) ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1077,39 +1043,23 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $object_subtype = '';
-
- if ( ! empty( $args['object_subtype'] ) ) {
- $object_subtype = $args['object_subtype'];
- }
-
</del><span class="cx" style="display: block; padding: 0 10px"> // Back-compat: old sanitize and auth callbacks are applied to all of an object type.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( $has_old_sanitize_cb && is_callable( $args['sanitize_callback'] ) ) {
- add_filter( "sanitize_{$object_type}_meta_{$meta_key}", $args['sanitize_callback'], 10, 4 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( is_callable( $args['sanitize_callback'] ) ) {
+ add_filter( "sanitize_{$object_type}_meta_{$meta_key}", $args['sanitize_callback'], 10, 3 );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( $has_old_auth_cb && is_callable( $args['auth_callback'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( is_callable( $args['auth_callback'] ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> add_filter( "auth_{$object_type}_meta_{$meta_key}", $args['auth_callback'], 10, 6 );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! $has_old_auth_cb && ! $has_old_sanitize_cb) {
- if ( is_callable( $args['sanitize_callback'] ) ) {
- add_filter( "sanitize_{$object_type}_{$object_subtype}_meta_{$meta_key}", $args['sanitize_callback'], 10, 4 );
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Global registry only contains meta keys registered with the array of arguments added in 4.6.0.
+ if ( ! $has_old_auth_cb && ! $has_old_sanitize_cb ) {
+ $wp_meta_keys[ $object_type ][ $meta_key ] = $args;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( is_callable( $args['auth_callback'] ) ) {
- add_filter( "auth_{$object_type}_{$object_subtype}_meta_{$meta_key}", $args['auth_callback'], 10, 6 );
- }
- }
-
- // Global registry only contains meta keys registered in the new way with a subtype.
- if ( ! empty( $object_subtype ) ) {
- $wp_meta_keys[ $object_type ][ $object_subtype ][ $meta_key ] = $args;
-
</del><span class="cx" style="display: block; padding: 0 10px"> return true;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return new WP_Error( 'register_meta_failed', __( 'Sanitize and auth callbacks registered; meta key not registered.' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return false;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1118,33 +1068,22 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 4.6.0
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $object_type The type of object.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param string $object_subtype The subtype of the object type.
</del><span class="cx" style="display: block; padding: 0 10px"> * @param string $meta_key The meta key.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return bool|WP_error True if the meta key is registered to the object type and subtype. False if not.
- * WP_Error if an invalid object type is passed.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return bool True if the meta key is registered to the object type. False if not.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-function registered_meta_key_exists( $object_type, $object_subtype, $meta_key ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+function registered_meta_key_exists( $object_type, $meta_key ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> global $wp_meta_keys;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! is_array( $wp_meta_keys ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return false;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Only specific core object types are supported.
- if ( ! wp_object_type_exists( $object_type ) ) {
- return new WP_Error( 'invalid_meta_key', __( 'Invalid meta key. Not a core object type.' ) );
- }
-
</del><span class="cx" style="display: block; padding: 0 10px"> if ( ! isset( $wp_meta_keys[ $object_type ] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return false;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! isset( $wp_meta_keys[ $object_type ][ $object_subtype ] ) ) {
- return false;
- }
-
- if ( isset( $wp_meta_keys[ $object_type ][ $object_subtype ][ $meta_key ] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( isset( $wp_meta_keys[ $object_type ][ $meta_key ] ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return true;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1157,35 +1096,30 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 4.6.0
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $object_type The type of object.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param string $object_subtype The subtype of the object type.
</del><span class="cx" style="display: block; padding: 0 10px"> * @param string $meta_key The meta key.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return bool|WP_Error True if successful. WP_Error if the meta key is invalid.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return bool True if successful. False if the meta key was not registered.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-function unregister_meta_key( $object_type, $object_subtype, $meta_key ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+function unregister_meta_key( $object_type, $meta_key ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> global $wp_meta_keys;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! registered_meta_key_exists( $object_type, $object_subtype, $meta_key ) ) {
- return new WP_Error( 'invalid_meta_key', __( 'Invalid meta key' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! registered_meta_key_exists( $object_type, $meta_key ) ) {
+ return false;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $args = $wp_meta_keys[ $object_type ][ $object_subtype ][ $meta_key ];
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $args = $wp_meta_keys[ $object_type ][ $meta_key ];
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( isset( $args['sanitize_callback'] ) && is_callable( $args['sanitize_callback'] ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- remove_filter( "sanitize_{$object_type}_{$object_subtype}_meta_{$meta_key}", $args['sanitize_callback'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ remove_filter( "sanitize_{$object_type}_meta_{$meta_key}", $args['sanitize_callback'] );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( isset( $args['auth_callback'] ) && is_callable( $args['auth_callback'] ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- remove_filter( "auth_{$object_type}_{$object_subtype}_meta_{$meta_key}", $args['auth_callback'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ remove_filter( "auth_{$object_type}_meta_{$meta_key}", $args['auth_callback'] );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- unset( $wp_meta_keys[ $object_type ][ $object_subtype ][ $meta_key ] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ unset( $wp_meta_keys[ $object_type ][ $meta_key ] );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Do some clean up
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( empty( $wp_meta_keys[ $object_type ][ $object_subtype ] ) ) {
- unset( $wp_meta_keys[ $object_type ][ $object_subtype ] );
- }
-
</del><span class="cx" style="display: block; padding: 0 10px"> if ( empty( $wp_meta_keys[ $object_type ] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> unset( $wp_meta_keys[ $object_type ] );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1194,31 +1128,22 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Retrieves a list of registered meta keys for an object type and optionally subtype.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Retrieves a list of registered meta keys for an object type.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 4.6.0
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param string $object_type The type of object. Post, comment, user, term.
- * @param string $object_subtype Optional. A subtype of the object (e.g. custom post type).
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param string $object_type The type of object. Post, comment, user, term.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @return array List of registered meta keys.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-function get_registered_meta_keys( $object_type, $object_subtype = '' ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+function get_registered_meta_keys( $object_type ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> global $wp_meta_keys;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! isset( $wp_meta_keys[ $object_type ] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return array();
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( empty( $object_subtype ) && isset( $wp_meta_keys[ $object_type ] ) ) {
- return $wp_meta_keys[ $object_type ];
- }
-
- if ( ! isset( $wp_meta_keys[ $object_type ][ $object_subtype ] ) ) {
- return array();
- }
-
- return $wp_meta_keys[ $object_type ][ $object_subtype ];
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return $wp_meta_keys[ $object_type ];
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1226,30 +1151,20 @@
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 4.6.0
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param string $object_type Type of object to request metadata for. (e.g. comment, post, term, user)
- * @param string $object_subtype The subtype of the object's type to request metadata for. (e.g. custom post type)
- * @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.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param 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.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return mixed|WP_Error
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return mixed A single value or array of values for a key if specified. An array of all registered keys
+ * and values for an object ID if not.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-function get_registered_metadata( $object_type, $object_subtype, $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 ( ! wp_object_type_exists( $object_type ) ) {
- return new WP_Error( 'invalid_meta_key', __( 'Invalid meta key. Not a core object type.' ) );
- }
-
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+function get_registered_metadata( $object_type, $object_id, $meta_key = '' ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! empty( $meta_key ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! registered_meta_key_exists( $object_type, $object_subtype, $meta_key ) ) {
- return new WP_Error( 'invalid_meta_key', __( 'Invalid meta key. Not registered.' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! registered_meta_key_exists( $object_type, $meta_key ) ) {
+ return false;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $meta_keys = get_registered_meta_keys( $object_type, $object_subtype );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $meta_keys = get_registered_meta_keys( $object_type );
</ins><span class="cx" style="display: block; padding: 0 10px"> $meta_key_data = $meta_keys[ $meta_key ];
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $data = get_metadata( $object_type, $object_id, $meta_key, $meta_key_data['single'] );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1259,7 +1174,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $data = get_metadata( $object_type, $object_id );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $meta_keys = get_registered_meta_keys( $object_type, $object_subtype );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $meta_keys = get_registered_meta_keys( $object_type );
</ins><span class="cx" style="display: block; padding: 0 10px"> $registered_data = array();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Someday, array_filter()
</span></span></pre></div>
<a id="trunktestsphpunittestsmetaregisterMetaphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/meta/registerMeta.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/meta/registerMeta.php 2016-07-18 19:42:48 UTC (rev 38094)
+++ trunk/tests/phpunit/tests/meta/registerMeta.php 2016-07-18 21:15:37 UTC (rev 38095)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3,32 +3,21 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @group meta
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> class Tests_Meta_Register_Meta extends WP_UnitTestCase {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- protected static $editor_id;
</del><span class="cx" style="display: block; padding: 0 10px"> protected static $post_id;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- protected static $comment_id;
</del><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> public static function wpSetUpBeforeClass( $factory ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- self::$editor_id = $factory->user->create( array( 'role' => 'editor' ) );
</del><span class="cx" style="display: block; padding: 0 10px"> self::$post_id = $factory->post->create();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- self::$comment_id = $factory->comment->create( array( 'comment_post_ID' => self::$post_id ) );
</del><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> public static function wpTearDownAfterClass() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- self::delete_user( self::$editor_id );
- wp_delete_comment( self::$comment_id, true );
</del><span class="cx" style="display: block; padding: 0 10px"> wp_delete_post( self::$post_id, true );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- function setUp() {
- parent::setUp();
- wp_set_current_user( self::$editor_id );
- }
-
</del><span class="cx" style="display: block; padding: 0 10px"> public function _old_sanitize_meta_cb( $meta_value, $meta_key, $meta_type ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return $meta_key . ' old sanitized';
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public function _new_sanitize_meta_cb( $meta_value, $meta_key, $object_type, $object_subtype ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function _new_sanitize_meta_cb( $meta_value, $meta_key, $object_type ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return $meta_key . ' new sanitized';
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -68,32 +57,29 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( array( 'auth' => 10, 'sanitize' => 10 ), $has_filters );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public function test_register_meta_with_valid_object_type_and_object_subtype_returns_true() {
- $result = register_meta( 'post', 'flight_number', array( 'object_subtype' => 'post' ) );
- unregister_meta_key( 'post', 'post', 'flight_number' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function test_register_meta_with_post_object_type_returns_true() {
+ $result = register_meta( 'post', 'flight_number', array() );
+ unregister_meta_key( 'post', 'flight_number' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertTrue( $result );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public function test_register_meta_with_post_object_type_and_subtype_populates_wp_meta_keys() {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function test_register_meta_with_post_object_type_populates_wp_meta_keys() {
</ins><span class="cx" style="display: block; padding: 0 10px"> global $wp_meta_keys;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- register_meta( 'post', 'flight_number', array( 'object_subtype' => 'post' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ register_meta( 'post', 'flight_number', array() );
</ins><span class="cx" style="display: block; padding: 0 10px"> $actual = $wp_meta_keys;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- unregister_meta_key( 'post', 'post', 'flight_number' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ unregister_meta_key( 'post', 'flight_number' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $expected = array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'post' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'post' => array(
- 'flight_number' => array(
- 'object_subtype' => 'post',
- 'type' => 'string',
- 'description' => '',
- 'single' => false,
- 'sanitize_callback' => null,
- 'auth_callback' => '__return_true',
- 'show_in_rest' => false,
- ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'flight_number' => array(
+ 'type' => 'string',
+ 'description' => '',
+ 'single' => false,
+ 'sanitize_callback' => null,
+ 'auth_callback' => '__return_true',
+ 'show_in_rest' => false,
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -101,50 +87,21 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( $actual, $expected );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public function test_register_meta_with_post_object_type_and_unregistered_subtype_populates_wp_meta_keys() {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function test_register_meta_with_term_object_type_populates_wp_meta_keys() {
</ins><span class="cx" style="display: block; padding: 0 10px"> global $wp_meta_keys;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
- register_meta( 'post', 'flight_number', array( 'object_subtype' => 'not_a_post_type' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ register_meta( 'term', 'category_icon', array() );
</ins><span class="cx" style="display: block; padding: 0 10px"> $actual = $wp_meta_keys;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- unregister_meta_key( 'post', 'not_a_post_type', 'flight_number' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ unregister_meta_key( 'term', 'category_icon' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $expected = array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'post' => array(
- 'not_a_post_type' => array(
- 'flight_number' => array(
- 'object_subtype' => 'not_a_post_type',
- 'type' => 'string',
- 'description' => '',
- 'single' => false,
- 'sanitize_callback' => null,
- 'auth_callback' => '__return_true',
- 'show_in_rest' => false,
- ),
- ),
- ),
- );
-
- $this->assertEquals( $actual, $expected );
- }
-
- public function test_register_meta_with_term_object_type_and_category_subtype_populates_wp_meta_keys() {
- global $wp_meta_keys;
- register_meta( 'term', 'category_icon', array( 'object_subtype' => 'category' ) );
- $actual = $wp_meta_keys;
- unregister_meta_key( 'term', 'category', 'category_icon' );
-
- $expected = array(
</del><span class="cx" style="display: block; padding: 0 10px"> 'term' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'category' => array(
- 'category_icon' => array(
- 'object_subtype' => 'category',
- 'type' => 'string',
- 'description' => '',
- 'single' => false,
- 'sanitize_callback' => null,
- 'auth_callback' => '__return_true',
- 'show_in_rest' => false,
- ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'category_icon' => array(
+ 'type' => 'string',
+ 'description' => '',
+ 'single' => false,
+ 'sanitize_callback' => null,
+ 'auth_callback' => '__return_true',
+ 'show_in_rest' => false,
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -152,31 +109,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( $actual, $expected );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public function test_register_meta_with_comment_object_type_and_subtype_populates_wp_meta_keys() {
- global $wp_meta_keys;
- register_meta( 'comment', 'comment_rating', array( 'object_subtype' => 'comment' ) );
- $actual = $wp_meta_keys;
- unregister_meta_key( 'comment', 'comment', 'comment_rating' );
-
- $expected = array(
- 'comment' => array(
- 'comment' => array(
- 'comment_rating' => array(
- 'object_subtype' => 'comment',
- 'type' => 'string',
- 'description' => '',
- 'single' => false,
- 'sanitize_callback' => null,
- 'auth_callback' => '__return_true',
- 'show_in_rest' => false,
- ),
- ),
- ),
- );
-
- $this->assertEquals( $actual, $expected );
- }
-
</del><span class="cx" style="display: block; padding: 0 10px"> public function test_register_meta_with_deprecated_sanitize_callback_does_not_populate_wp_meta_keys() {
</span><span class="cx" style="display: block; padding: 0 10px"> global $wp_meta_keys;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -188,14 +120,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( array(), $actual );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public function test_register_meta_with_deprecated_sanitize_callback_param_returns_wp_error() {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function test_register_meta_with_deprecated_sanitize_callback_param_returns_false() {
</ins><span class="cx" style="display: block; padding: 0 10px"> $actual = register_meta( 'post', 'flight_number', array( $this, '_old_sanitize_meta_cb' ) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> remove_filter( 'sanitize_post_meta_flight_number', array( $this, '_old_sanitize_meta_cb') );
</span><span class="cx" style="display: block; padding: 0 10px"> remove_filter( 'auth_post_meta_flight_number', '__return_true');
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->assertWPError( $actual );
- $this->assertEquals( 'register_meta_failed', $actual->get_error_code() );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->assertFalse( $actual );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_register_meta_with_deprecated_sanitize_callback_parameter_passes_through_filter() {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -210,22 +141,19 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_register_meta_with_current_sanitize_callback_populates_wp_meta_keys() {
</span><span class="cx" style="display: block; padding: 0 10px"> global $wp_meta_keys;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- register_meta( 'post', 'flight_number', array( 'object_subtype' => 'post', 'sanitize_callback' => array( $this, '_new_sanitize_meta_cb' ) ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ register_meta( 'post', 'flight_number', array( 'sanitize_callback' => array( $this, '_new_sanitize_meta_cb' ) ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> $actual = $wp_meta_keys;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- unregister_meta_key( 'post', 'post', 'flight_number' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ unregister_meta_key( 'post', 'flight_number' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $expected = array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'post' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'post' => array(
- 'flight_number' => array(
- 'object_subtype' => 'post',
- 'type' => 'string',
- 'description' => '',
- 'single' => false,
- 'sanitize_callback' => array( $this, '_new_sanitize_meta_cb' ),
- 'auth_callback' => '__return_true',
- 'show_in_rest' => false,
- ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'flight_number' => array(
+ 'type' => 'string',
+ 'description' => '',
+ 'single' => false,
+ 'sanitize_callback' => array( $this, '_new_sanitize_meta_cb' ),
+ 'auth_callback' => '__return_true',
+ 'show_in_rest' => false,
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -233,178 +161,143 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_register_meta_with_current_sanitize_callback_returns_true() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $result = register_meta( 'post', 'flight_number', array( 'object_subtype' => 'post', 'sanitize_callback' => array( $this, '_new_sanitize_meta_cb' ) ) );
- unregister_meta_key( 'post', 'post', 'flight_number' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $result = register_meta( 'post', 'flight_number', array( 'sanitize_callback' => array( $this, '_new_sanitize_meta_cb' ) ) );
+ unregister_meta_key( 'post', 'flight_number' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertTrue( $result );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_register_meta_with_new_sanitize_callback_parameter() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- register_meta( 'post', 'new_sanitized_key', array( 'object_subtype' => 'post', 'sanitize_callback' => array( $this, '_new_sanitize_meta_cb' ) ) );
- $meta = sanitize_meta( 'new_sanitized_key', 'unsanitized', 'post', 'post' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ register_meta( 'post', 'new_sanitized_key', array( 'sanitize_callback' => array( $this, '_new_sanitize_meta_cb' ) ) );
+ $meta = sanitize_meta( 'new_sanitized_key', 'unsanitized', 'post' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- unregister_meta_key( 'post', 'post', 'new_sanitized_key' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ unregister_meta_key( 'post', 'new_sanitized_key' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( 'new_sanitized_key new sanitized', $meta );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_register_meta_unregistered_meta_key_removes_sanitize_filter() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- register_meta( 'post', 'new_sanitized_key', array( 'object_subtype' => 'post', 'sanitize_callback' => array( $this, '_new_sanitize_meta_cb' ) ) );
- unregister_meta_key( 'post', 'post', 'new_sanitized_key' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ register_meta( 'post', 'new_sanitized_key', array( 'sanitize_callback' => array( $this, '_new_sanitize_meta_cb' ) ) );
+ unregister_meta_key( 'post', 'new_sanitized_key' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $has_filter = has_filter( 'sanitize_post_post_meta_new_sanitized_key', array( $this, '_new_sanitize_meta_cb' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $has_filter = has_filter( 'sanitize_post_meta_new_sanitized_key', array( $this, '_new_sanitize_meta_cb' ) );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertFalse( $has_filter );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_register_meta_unregistered_meta_key_removes_auth_filter() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- register_meta( 'post', 'new_auth_key', array( 'object_subtype' => 'post', 'auth_callback' => array( $this, '_new_auth_meta_cb' ) ) );
- unregister_meta_key( 'post', 'post', 'new_auth_key' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ register_meta( 'post', 'new_auth_key', array( 'auth_callback' => array( $this, '_new_auth_meta_cb' ) ) );
+ unregister_meta_key( 'post', 'new_auth_key' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $has_filter = has_filter( 'auth_post_post_meta_new_auth_key', array( $this, '_new_auth_meta_cb' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $has_filter = has_filter( 'auth_post_meta_new_auth_key', array( $this, '_new_auth_meta_cb' ) );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertFalse( $has_filter );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_unregister_meta_key_clears_key_from_wp_meta_keys() {
</span><span class="cx" style="display: block; padding: 0 10px"> global $wp_meta_keys;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- register_meta( 'post', 'registered_key', array( 'object_subtype' => 'post' ) );
- unregister_meta_key( 'post', 'post', 'registered_key' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ register_meta( 'post', 'registered_key', array() );
+ unregister_meta_key( 'post', 'registered_key' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( array(), $wp_meta_keys );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public function test_unregister_meta_key_with_invalid_key_returns_wp_error() {
- $this->assertWPError( unregister_meta_key( 'post', 'post', 'not_a_registered_key' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function test_unregister_meta_key_with_invalid_key_returns_false() {
+ $this->assertFalse( unregister_meta_key( 'post', 'not_a_registered_key' ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_get_registered_meta_keys() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- register_meta( 'post', 'registered_key1', array( 'object_subtype' => 'post' ) );
- register_meta( 'post', 'registered_key2', array( 'object_subtype' => 'post' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ register_meta( 'post', 'registered_key1', array() );
+ register_meta( 'post', 'registered_key2', array() );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $meta_keys = get_registered_meta_keys( 'post', 'post' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $meta_keys = get_registered_meta_keys( 'post' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- unregister_meta_key( 'post', 'post', 'registered_key1' );
- unregister_meta_key( 'post', 'post', 'registered_key2' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ unregister_meta_key( 'post', 'registered_key1' );
+ unregister_meta_key( 'post', 'registered_key2' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertArrayHasKey( 'registered_key1', $meta_keys );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertArrayHasKey( 'registered_key2', $meta_keys );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public function test_get_registered_meta_keys_with_subtype_without_registered_keys_is_empty() {
- register_meta( 'post', 'registered_key1', array( 'object_subtype' => 'post' ) );
- register_meta( 'post', 'registered_key2', array( 'object_subtype' => 'post' ) );
-
- $meta_keys = get_registered_meta_keys( 'post', 'page' );
-
- unregister_meta_key( 'post', 'post', 'registered_key1' );
- unregister_meta_key( 'post', 'post', 'registered_key2' );
-
- $this->assertEmpty( $meta_keys );
- }
-
</del><span class="cx" style="display: block; padding: 0 10px"> public function test_get_registered_meta_keys_with_invalid_type_is_empty() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- register_meta( 'post', 'registered_key1', array( 'object_subtype' => 'post' ) );
- register_meta( 'post', 'registered_key2', array( 'object_subtype' => 'post' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ register_meta( 'post', 'registered_key1', array() );
+ register_meta( 'post', 'registered_key2', array() );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $meta_keys = get_registered_meta_keys( 'invalid-type' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- unregister_meta_key( 'post', 'post', 'registered_key1' );
- unregister_meta_key( 'post', 'post', 'registered_key2' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ unregister_meta_key( 'post', 'registered_key1' );
+ unregister_meta_key( 'post', 'registered_key2' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEmpty( $meta_keys );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public function test_get_registered_meta_keys_has_count() {
- register_meta( 'post', 'registered_key1', array( 'object_subtype' => 'post' ) );
- register_meta( 'post', 'registered_key2', array( 'object_subtype' => 'page' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function test_get_registered_meta_keys_description_arg() {
+ register_meta( 'post', 'registered_key1', array( 'description' => 'I\'m just a field, take a good look at me' ) );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $meta_keys = get_registered_meta_keys( 'post' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- unregister_meta_key( 'post', 'post', 'registered_key1' );
- unregister_meta_key( 'post', 'page', 'registered_key2' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ unregister_meta_key( 'post', 'registered_key1' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->assertCount( 2, $meta_keys );
- }
-
- public function test_get_registered_meta_keys_description_arg() {
- register_meta( 'post', 'registered_key1', array( 'object_subtype' => 'post', 'description' => 'I\'m just a field, take a good look at me' ) );
-
- $meta_keys = get_registered_meta_keys( 'post', 'post' );
-
- unregister_meta_key( 'post', 'post', 'registered_key1' );
-
</del><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( 'I\'m just a field, take a good look at me', $meta_keys['registered_key1']['description'] );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_get_registered_meta_keys_invalid_arg() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- register_meta( 'post', 'registered_key1', array( 'object_subtype' => 'post', 'invalid_arg' => 'invalid' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ register_meta( 'post', 'registered_key1', array( 'invalid_arg' => 'invalid' ) );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $meta_keys = get_registered_meta_keys( 'post', 'post' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $meta_keys = get_registered_meta_keys( 'post' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- unregister_meta_key( 'post', 'post', 'registered_key1' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ unregister_meta_key( 'post', 'registered_key1' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertArrayNotHasKey( 'invalid_arg', $meta_keys['registered_key1'] );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_get_registered_metadata() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- register_meta( 'post', 'flight_number', array( 'object_subtype' => 'post' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ register_meta( 'post', 'flight_number', array() );
</ins><span class="cx" style="display: block; padding: 0 10px"> add_post_meta( self::$post_id, 'flight_number', 'Oceanic 815' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $meta = get_registered_metadata( 'post', 'post', self::$post_id );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $meta = get_registered_metadata( 'post', self::$post_id );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- unregister_meta_key( 'post', 'post', 'flight_number' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ unregister_meta_key( 'post', 'flight_number' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( 'Oceanic 815', $meta['flight_number'][0] );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_get_registered_metadata_by_key() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- register_meta( 'post', 'flight_number', array( 'object_subtype' => 'post' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ register_meta( 'post', 'flight_number', array() );
</ins><span class="cx" style="display: block; padding: 0 10px"> add_post_meta( self::$post_id, 'flight_number', 'Oceanic 815' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $meta = get_registered_metadata( 'post', 'post', self::$post_id, 'flight_number' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $meta = get_registered_metadata( 'post', self::$post_id, 'flight_number' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- unregister_meta_key( 'post', 'post', 'flight_number' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ unregister_meta_key( 'post', 'flight_number' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( 'Oceanic 815', $meta[0] );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_get_registered_metadata_by_key_single() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- register_meta( 'post', 'flight_number', array( 'object_subtype' => 'post', 'single' => true ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ register_meta( 'post', 'flight_number', array( 'single' => true ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> add_post_meta( self::$post_id, 'flight_number', 'Oceanic 815' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $meta = get_registered_metadata( 'post', 'post', self::$post_id, 'flight_number' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $meta = get_registered_metadata( 'post', self::$post_id, 'flight_number' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- unregister_meta_key( 'post', 'post', 'flight_number' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ unregister_meta_key( 'post', 'flight_number' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( 'Oceanic 815', $meta );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_get_registered_metadata_by_invalid_key() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- register_meta( 'post', 'flight_number', array( 'object_subtype' => 'post' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ register_meta( 'post', 'flight_number', array() );
</ins><span class="cx" style="display: block; padding: 0 10px"> add_post_meta( self::$post_id, 'flight_number', 'Oceanic 815' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $meta = get_registered_metadata( 'post', 'post', self::$post_id, 'flight_pilot' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $meta = get_registered_metadata( 'post', self::$post_id, 'flight_pilot' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- unregister_meta_key( 'post', 'post', 'flight_number' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ unregister_meta_key( 'post', 'flight_number' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->assertWPError( $meta );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->assertFalse( $meta );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public function test_get_registered_metadata_invalid_object_type() {
- register_meta( 'post', 'flight_number', array( 'object_subtype' => 'post' ) );
- add_post_meta( self::$post_id, 'flight_number', 'Oceanic 815' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function test_get_registered_metadata_invalid_object_type_returns_empty_array() {
+ $meta = get_registered_metadata( 'invalid-type', self::$post_id );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $meta = get_registered_metadata( 'invalid-type', 'invalid-subtype', self::$post_id );
-
- unregister_meta_key( 'post', 'post', 'flight_number' );
-
- $this->assertWPError( $meta );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->assertEmpty( $meta );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
- public function test_get_registered_metadata_invalid() {
- $meta = get_registered_metadata( 'invalid-type', 'invalid-subtype', self::$post_id );
-
- $this->assertWPError( $meta );
- }
</del><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre>
</div>
</div>
</body>
</html>