<!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>[18445] trunk: Introduce register_meta(), get_metadata_by_mid(), and *_post_meta capabilities.</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, #logmsg > ol { margin-left: 0; 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">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/18445">18445</a></dd>
<dt>Author</dt> <dd>ryan</dd>
<dt>Date</dt> <dd>2011-07-20 22:04:35 +0000 (Wed, 20 Jul 2011)</dd>
</dl>

<h3>Log Message</h3>
<pre>Introduce register_meta(), get_metadata_by_mid(), and *_post_meta capabilities.  fixes <a href="http://core.trac.wordpress.org/ticket/17850">#17850</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminadminajaxphp">trunk/wp-admin/admin-ajax.php</a></li>
<li><a href="#trunkwpadminincludesmetaboxesphp">trunk/wp-admin/includes/meta-boxes.php</a></li>
<li><a href="#trunkwpadminincludespostphp">trunk/wp-admin/includes/post.php</a></li>
<li><a href="#trunkwpadminincludestemplatephp">trunk/wp-admin/includes/template.php</a></li>
<li><a href="#trunkwpincludescapabilitiesphp">trunk/wp-includes/capabilities.php</a></li>
<li><a href="#trunkwpincludesclasswpxmlrpcserverphp">trunk/wp-includes/class-wp-xmlrpc-server.php</a></li>
<li><a href="#trunkwpincludesmetaphp">trunk/wp-includes/meta.php</a></li>
<li><a href="#trunkwpincludesposttemplatephp">trunk/wp-includes/post-template.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminadminajaxphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/admin-ajax.php (18444 => 18445)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/admin-ajax.php        2011-07-15 23:11:36 UTC (rev 18444)
+++ trunk/wp-admin/admin-ajax.php        2011-07-20 22:04:35 UTC (rev 18445)
</span><span class="lines">@@ -393,10 +393,10 @@
</span><span class="cx">         break;
</span><span class="cx"> case 'delete-meta' :
</span><span class="cx">         check_ajax_referer( &quot;delete-meta_$id&quot; );
</span><del>-        if ( !$meta = get_post_meta_by_id( $id ) )
</del><ins>+        if ( !$meta = get_metadata_by_mid( 'post', $id ) )
</ins><span class="cx">                 die('1');
</span><span class="cx"> 
</span><del>-        if ( !current_user_can( 'edit_post', $meta-&gt;post_id ) || is_protected_meta( $meta-&gt;meta_key ) )
</del><ins>+        if ( is_protected_meta( $meta-&gt;meta_key, 'post' ) || ! current_user_can( 'delete_post_meta',  $meta-&gt;post_id, $meta-&gt;meta_key ) )
</ins><span class="cx">                 die('-1');
</span><span class="cx">         if ( delete_meta( $meta-&gt;meta_id ) )
</span><span class="cx">                 die('1');
</span><span class="lines">@@ -849,7 +849,7 @@
</span><span class="cx">                         die(__('Please provide a custom field value.'));
</span><span class="cx">                 }
</span><span class="cx"> 
</span><del>-                $meta = get_post_meta_by_id( $mid );
</del><ins>+                $meta = get_metadata_by_mid( 'post', $mid );
</ins><span class="cx">                 $pid = (int) $meta-&gt;post_id;
</span><span class="cx">                 $meta = get_object_vars( $meta );
</span><span class="cx">                 $x = new WP_Ajax_Response( array(
</span><span class="lines">@@ -869,10 +869,8 @@
</span><span class="cx">                         die(__('Please provide a custom field value.'));
</span><span class="cx">                 if ( !$meta = get_post_meta_by_id( $mid ) )
</span><span class="cx">                         die('0'); // if meta doesn't exist
</span><del>-                if ( !current_user_can( 'edit_post', $meta-&gt;post_id ) )
</del><ins>+                if ( is_protected_meta( $meta-&gt;meta_key, 'post' ) || !current_user_can( 'edit_post_meta', $meta-&gt;post_id, $meta-&gt;meta_key ) )
</ins><span class="cx">                         die('-1');
</span><del>-                if ( is_protected_meta( $meta-&gt;meta_key ) )
-                        die('-1');
</del><span class="cx">                 if ( $meta-&gt;meta_value != stripslashes($value) || $meta-&gt;meta_key != stripslashes($key) ) {
</span><span class="cx">                         if ( !$u = update_meta( $mid, $key, $value ) )
</span><span class="cx">                                 die('0'); // We know meta exists; we also know it's unchanged (or DB error, in which case there are bigger problems).
</span></span></pre></div>
<a id="trunkwpadminincludesmetaboxesphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/meta-boxes.php (18444 => 18445)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/meta-boxes.php        2011-07-15 23:11:36 UTC (rev 18444)
+++ trunk/wp-admin/includes/meta-boxes.php        2011-07-20 22:04:35 UTC (rev 18445)
</span><span class="lines">@@ -425,7 +425,11 @@
</span><span class="cx"> &lt;div id=&quot;ajax-response&quot;&gt;&lt;/div&gt;
</span><span class="cx"> &lt;?php
</span><span class="cx"> $metadata = has_meta($post-&gt;ID);
</span><del>-list_meta($metadata);
</del><ins>+foreach ( $metadata as $key =&gt; $value ) {
+        if ( is_protected_meta( $metadata[ $key ][ 'meta_key' ], 'post' ) || ! current_user_can( 'edit_post_meta', $post-&gt;ID, $metadata[ $key ][ 'meta_key' ] ) )
+                unset( $metadata[ $key ] );
+}
+list_meta( $metadata );
</ins><span class="cx"> meta_form(); ?&gt;
</span><span class="cx"> &lt;/div&gt;
</span><span class="cx"> &lt;p&gt;&lt;?php _e('Custom fields can be used to add extra metadata to a post that you can &lt;a href=&quot;http://codex.wordpress.org/Using_Custom_Fields&quot; target=&quot;_blank&quot;&gt;use in your theme&lt;/a&gt;.'); ?&gt;&lt;/p&gt;
</span></span></pre></div>
<a id="trunkwpadminincludespostphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/post.php (18444 => 18445)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/post.php        2011-07-15 23:11:36 UTC (rev 18444)
+++ trunk/wp-admin/includes/post.php        2011-07-20 22:04:35 UTC (rev 18445)
</span><span class="lines">@@ -210,7 +210,7 @@
</span><span class="cx">                                 continue;
</span><span class="cx">                         if ( $meta-&gt;post_id != $post_ID )
</span><span class="cx">                                 continue;
</span><del>-                        if ( is_protected_meta( $value['key'] ) )
</del><ins>+                        if ( is_protected_meta( $value['key'], 'post' ) || ! current_user_can( 'edit_post_meta', $post_ID, $value['key'] ) )
</ins><span class="cx">                                 continue;
</span><span class="cx">                         update_meta( $key, $value['key'], $value['value'] );
</span><span class="cx">                 }
</span><span class="lines">@@ -222,7 +222,7 @@
</span><span class="cx">                                 continue;
</span><span class="cx">                         if ( $meta-&gt;post_id != $post_ID )
</span><span class="cx">                                 continue;
</span><del>-                        if ( is_protected_meta( $meta-&gt;meta_key ) )
</del><ins>+                        if ( is_protected_meta( $meta-&gt;meta_key, 'post' ) || ! current_user_can( 'delete_post_meta', $post_ID, $meta-&gt;meta_key ) )
</ins><span class="cx">                                 continue;
</span><span class="cx">                         delete_meta( $key );
</span><span class="cx">                 }
</span><span class="lines">@@ -671,7 +671,7 @@
</span><span class="cx">         if ( is_string($metavalue) )
</span><span class="cx">                 $metavalue = trim( $metavalue );
</span><span class="cx"> 
</span><del>-        if ( ('0' === $metavalue || !empty ( $metavalue ) ) &amp;&amp; ((('#NONE#' != $metakeyselect) &amp;&amp; !empty ( $metakeyselect) ) || !empty ( $metakeyinput) ) ) {
</del><ins>+        if ( ('0' === $metavalue || ! empty ( $metavalue ) ) &amp;&amp; ((('#NONE#' != $metakeyselect) &amp;&amp; !empty ( $metakeyselect) ) || !empty ( $metakeyinput) ) ) {
</ins><span class="cx">                 // We have a key/value pair. If both the select and the
</span><span class="cx">                 // input for the key have data, the input takes precedence:
</span><span class="cx"> 
</span><span class="lines">@@ -681,16 +681,12 @@
</span><span class="cx">                 if ( $metakeyinput)
</span><span class="cx">                         $metakey = $metakeyinput; // default
</span><span class="cx"> 
</span><del>-                if ( is_protected_meta( $metakey ) )
</del><ins>+                if ( is_protected_meta( $metakey, 'post' ) || ! current_user_can( 'add_post_meta', $post_ID, $metakey ) )
</ins><span class="cx">                         return false;
</span><span class="cx"> 
</span><del>-                wp_cache_delete($post_ID, 'post_meta');
-                $wpdb-&gt;insert( $wpdb-&gt;postmeta, array( 'post_id' =&gt; $post_ID, 'meta_key' =&gt; $metakey, 'meta_value' =&gt; $metavalue ) );
-                $meta_id = $wpdb-&gt;insert_id;
-                do_action( 'added_postmeta', $meta_id, $post_ID, $metakey, $metavalue );
-
-                return $meta_id;
</del><ins>+                return add_post_meta($post_ID, $metakey, $metavalue);
</ins><span class="cx">         }
</span><ins>+
</ins><span class="cx">         return false;
</span><span class="cx"> } // add_meta
</span><span class="cx"> 
</span><span class="lines">@@ -771,7 +767,6 @@
</span><span class="cx">         return $wpdb-&gt;get_results( $wpdb-&gt;prepare(&quot;SELECT meta_key, meta_value, meta_id, post_id
</span><span class="cx">                         FROM $wpdb-&gt;postmeta WHERE post_id = %d
</span><span class="cx">                         ORDER BY meta_key,meta_id&quot;, $postid), ARRAY_A );
</span><del>-
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><span class="lines">@@ -789,9 +784,6 @@
</span><span class="cx"> 
</span><span class="cx">         $meta_key = stripslashes($meta_key);
</span><span class="cx"> 
</span><del>-        if ( is_protected_meta( $meta_key ) )
-                return false;
-
</del><span class="cx">         if ( '' === trim( $meta_value ) )
</span><span class="cx">                 return false;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkwpadminincludestemplatephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/template.php (18444 => 18445)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/template.php        2011-07-15 23:11:36 UTC (rev 18444)
+++ trunk/wp-admin/includes/template.php        2011-07-20 22:04:35 UTC (rev 18445)
</span><span class="lines">@@ -466,7 +466,7 @@
</span><span class="cx"> function _list_meta_row( $entry, &amp;$count ) {
</span><span class="cx">         static $update_nonce = false;
</span><span class="cx"> 
</span><del>-        if ( is_protected_meta( $entry['meta_key'] ) )
</del><ins>+        if ( is_protected_meta( $entry['meta_key'], 'post' ) )
</ins><span class="cx">                 return;
</span><span class="cx"> 
</span><span class="cx">         if ( !$update_nonce )
</span><span class="lines">@@ -478,8 +478,6 @@
</span><span class="cx">                 $style = 'alternate';
</span><span class="cx">         else
</span><span class="cx">                 $style = '';
</span><del>-        if ('_' == $entry['meta_key'] { 0 } )
-                $style .= ' hidden';
</del><span class="cx"> 
</span><span class="cx">         if ( is_serialized( $entry['meta_value'] ) ) {
</span><span class="cx">                 if ( is_serialized_string( $entry['meta_value'] ) ) {
</span></span></pre></div>
<a id="trunkwpincludescapabilitiesphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/capabilities.php (18444 => 18445)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/capabilities.php        2011-07-15 23:11:36 UTC (rev 18444)
+++ trunk/wp-includes/capabilities.php        2011-07-20 22:04:35 UTC (rev 18445)
</span><span class="lines">@@ -951,6 +951,23 @@
</span><span class="cx">                 else
</span><span class="cx">                         $caps[] = $post_type-&gt;cap-&gt;read_private_posts;
</span><span class="cx">                 break;
</span><ins>+        case 'edit_post_meta':
+        case 'delete_post_meta':
+        case 'add_post_meta':
+                $post = get_post( $args[0] );
+                $post_type_object = get_post_type_object( $post-&gt;post_type );
+                $caps = map_meta_cap( $post_type_object-&gt;cap-&gt;edit_post, $user_id, $post-&gt;ID );        
+
+                $meta_key = isset( $args[ 1 ] ) ? $args[ 1 ] : false; 
+                        
+                if ( $meta_key &amp;&amp; has_filter( &quot;auth_post_meta_{$meta_key}&quot; ) ) {
+                        $allowed = apply_filters( &quot;auth_post_meta_{$meta_key}&quot;, false, $meta_key, $post-&gt;ID, $user_id, $cap, $caps );
+                        if ( ! $allowed )
+                                $caps[] = $cap;
+                } elseif ( $meta_key &amp;&amp; is_protected_meta( $meta_key, 'post' ) ) {
+                        $caps[] = $cap;
+                }
+                break;
</ins><span class="cx">         case 'edit_comment':
</span><span class="cx">                 $comment = get_comment( $args[0] );
</span><span class="cx">                 $post = get_post( $comment-&gt;comment_post_ID );
</span></span></pre></div>
<a id="trunkwpincludesclasswpxmlrpcserverphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/class-wp-xmlrpc-server.php (18444 => 18445)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/class-wp-xmlrpc-server.php        2011-07-15 23:11:36 UTC (rev 18444)
+++ trunk/wp-includes/class-wp-xmlrpc-server.php        2011-07-20 22:04:35 UTC (rev 18445)
</span><span class="lines">@@ -234,9 +234,8 @@
</span><span class="cx"> 
</span><span class="cx">                 foreach ( (array) has_meta($post_id) as $meta ) {
</span><span class="cx">                         // Don't expose protected fields.
</span><del>-                        if ( strpos($meta['meta_key'], '_wp_') === 0 ) {
</del><ins>+                        if ( ! current_user_can( 'edit_post_meta', $post_id , $meta['meta_key'] ) )
</ins><span class="cx">                                 continue;
</span><del>-                        }
</del><span class="cx"> 
</span><span class="cx">                         $custom_fields[] = array(
</span><span class="cx">                                 &quot;id&quot;    =&gt; $meta['meta_id'],
</span><span class="lines">@@ -262,19 +261,18 @@
</span><span class="cx">                 foreach ( (array) $fields as $meta ) {
</span><span class="cx">                         if ( isset($meta['id']) ) {
</span><span class="cx">                                 $meta['id'] = (int) $meta['id'];
</span><del>-
</del><ins>+                                $pmeta = get_metadata_by_mid( 'post', $meta['id'] );
</ins><span class="cx">                                 if ( isset($meta['key']) ) {
</span><del>-                                        update_meta($meta['id'], $meta['key'], $meta['value']);
</del><ins>+                                        if ( $meta['key'] != $pmeta-&gt;meta_key )
+                                                continue;
+                                        if ( current_user_can( 'edit_post_meta', $post_id, $meta['key'] ) )
+                                                update_meta( $meta['id'], $meta['key'], $meta['value'] );
+                                } elseif ( current_user_can( 'delete_post_meta', $post_id, $pmeta-&gt;meta_key ) ) {
+                                                delete_meta( $meta['id'] );
</ins><span class="cx">                                 }
</span><del>-                                else {
-                                        delete_meta($meta['id']);
-                                }
</del><ins>+                        } elseif ( current_user_can( 'add_post_meta', $post_id, $meta['key'] ) ) {
+                                        add_post_meta( $post_id, $meta['key'], $meta['value'] );
</ins><span class="cx">                         }
</span><del>-                        else {
-                                $_POST['metakeyinput'] = $meta['key'];
-                                $_POST['metavalue'] = $meta['value'];
-                                add_meta($post_id);
-                        }
</del><span class="cx">                 }
</span><span class="cx">         }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkwpincludesmetaphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/meta.php (18444 => 18445)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/meta.php        2011-07-15 23:11:36 UTC (rev 18444)
+++ trunk/wp-includes/meta.php        2011-07-20 22:04:35 UTC (rev 18445)
</span><span class="lines">@@ -26,7 +26,7 @@
</span><span class="cx">  * @param bool $unique Optional, default is false.  Whether the specified metadata key should be
</span><span class="cx">  *                 unique for the object.  If true, and the object already has a value for the specified
</span><span class="cx">  *                 metadata key, no change will be made
</span><del>- * @return bool True on successful update, false on failure.
</del><ins>+ * @return bool The meta ID on successful update, false on failure.
</ins><span class="cx">  */
</span><span class="cx"> function add_metadata($meta_type, $object_id, $meta_key, $meta_value, $unique = false) {
</span><span class="cx">         if ( !$meta_type || !$meta_key )
</span><span class="lines">@@ -49,7 +49,7 @@
</span><span class="cx"> 
</span><span class="cx">         $check = apply_filters( &quot;add_{$meta_type}_metadata&quot;, null, $object_id, $meta_key, $meta_value, $unique );
</span><span class="cx">         if ( null !== $check )
</span><del>-                return (bool) $check;
</del><ins>+                return $check;
</ins><span class="cx"> 
</span><span class="cx">         if ( $unique &amp;&amp; $wpdb-&gt;get_var( $wpdb-&gt;prepare(
</span><span class="cx">                 &quot;SELECT COUNT(*) FROM $table WHERE meta_key = %s AND $column = %d&quot;,
</span><span class="lines">@@ -61,20 +61,25 @@
</span><span class="cx"> 
</span><span class="cx">         do_action( &quot;add_{$meta_type}_meta&quot;, $object_id, $meta_key, $_meta_value );
</span><span class="cx"> 
</span><del>-        $wpdb-&gt;insert( $table, array(
</del><ins>+        $result = $wpdb-&gt;insert( $table, array(
</ins><span class="cx">                 $column =&gt; $object_id,
</span><span class="cx">                 'meta_key' =&gt; $meta_key,
</span><span class="cx">                 'meta_value' =&gt; $meta_value
</span><span class="cx">         ) );
</span><span class="cx"> 
</span><ins>+        if ( ! $result )
+                return false;
+
+        $mid = (int) $wpdb-&gt;insert_id;
+
</ins><span class="cx">         wp_cache_delete($object_id, $meta_type . '_meta');
</span><span class="cx">         // users cache stores usermeta that must be cleared.
</span><span class="cx">         if ( 'user' == $meta_type )
</span><span class="cx">                 clean_user_cache($object_id);
</span><span class="cx"> 
</span><del>-        do_action( &quot;added_{$meta_type}_meta&quot;, $wpdb-&gt;insert_id, $object_id, $meta_key, $_meta_value );
</del><ins>+        do_action( &quot;added_{$meta_type}_meta&quot;, $mid, $object_id, $meta_key, $_meta_value );
</ins><span class="cx"> 
</span><del>-        return true;
</del><ins>+        return $mid;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><span class="lines">@@ -146,6 +151,7 @@
</span><span class="cx">         do_action( &quot;update_{$meta_type}_meta&quot;, $meta_id, $object_id, $meta_key, $_meta_value );
</span><span class="cx"> 
</span><span class="cx">         $wpdb-&gt;update( $table, $data, $where );
</span><ins>+
</ins><span class="cx">         wp_cache_delete($object_id, $meta_type . '_meta');
</span><span class="cx">         // users cache stores usermeta that must be cleared.
</span><span class="cx">         if ( 'user' == $meta_type )
</span><span class="lines">@@ -282,6 +288,40 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><ins>+ * Get meta data by meta ID
+ *
+ * @since 3.3.0
+ *
+ * @param string $meta_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 Meta object or false.
+ */
+function get_metadata_by_mid( $meta_type, $meta_id ) {
+        global $wpdb;
+
+        if ( ! $meta_type )
+                return false;
+
+        if ( !$meta_id = absint( $meta_id ) )
+                return false;
+
+        if ( ! $table = _get_meta_table($meta_type) )
+                return false;
+
+        $id_column = ( 'user' == $meta_type ) ? 'umeta_id' : 'meta_id';
+
+        $meta = $wpdb-&gt;get_row( $wpdb-&gt;prepare( &quot;SELECT * FROM $table WHERE $id_column = %d&quot;, $meta_id ) );
+
+        if ( empty( $meta ) )
+                return false;
+
+        if ( isset( $meta-&gt;meta_value ) )
+                $meta-&gt;meta_value = maybe_unserialize( $meta-&gt;meta_value );
+
+        return $meta;
+}
+
+/**
</ins><span class="cx">  * Update the metadata cache for the specified objects.
</span><span class="cx">  *
</span><span class="cx">  * @since 2.9.0
</span><span class="lines">@@ -588,7 +628,7 @@
</span><span class="cx">  * @return bool True if the key is protected, false otherwise.
</span><span class="cx">  */
</span><span class="cx"> function is_protected_meta( $meta_key, $meta_type = null ) {
</span><del>-        $protected = (  '_' == $meta_key[0] );
</del><ins>+        $protected = ( '_' == $meta_key[0] );
</ins><span class="cx"> 
</span><span class="cx">         return apply_filters( 'is_protected_meta', $protected, $meta_key, $meta_type );
</span><span class="cx"> }
</span><span class="lines">@@ -603,8 +643,34 @@
</span><span class="cx">  * @param string $meta_type Type of meta
</span><span class="cx">  * @return mixed Sanitized $meta_value
</span><span class="cx">  */
</span><del>-function sanitize_meta( $meta_key, $meta_value, $meta_type = null ) {
-        return apply_filters( 'sanitize_meta', $meta_value, $meta_key, $meta_type );
</del><ins>+function sanitize_meta( $meta_key, $meta_value, $meta_type ) {
+        return apply_filters( &quot;sanitize_{$meta_type}_meta_{$meta_key}&quot;, $meta_value, $meta_key, $meta_type );
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+/**
+ * Register meta key
+ * 
+ * @since 3.3.0
+ *
+ * @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 array $args Arguments
+ */
+function register_meta( $meta_type, $meta_key, $sanitize_callback, $auth_callback = null ) {
+        if ( is_callable( $sanitize_callback ) )
+                add_filter( &quot;sanitize_{$meta_type}_meta_{$meta_key}&quot;, $sanitize_callback, 10, 3 );
+
+        if ( empty( $auth_callback ) ) {
+                if ( is_protected_meta( $meta_key, $meta_type ) )
+                        $auth_callback = '__return_false';
+                else
+                        $auth_callback = '__return_true';
+        }
+
+        if ( is_callable( $auth_callback ) )
+                add_filter( &quot;auth_{$meta_type}_meta_{$meta_key}&quot;, $auth_callback, 10, 6 );
+}
+
</ins><span class="cx"> ?&gt;
</span></span></pre></div>
<a id="trunkwpincludesposttemplatephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/post-template.php (18444 => 18445)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/post-template.php        2011-07-15 23:11:36 UTC (rev 18444)
+++ trunk/wp-includes/post-template.php        2011-07-20 22:04:35 UTC (rev 18445)
</span><span class="lines">@@ -737,7 +737,7 @@
</span><span class="cx">                 echo &quot;&lt;ul class='post-meta'&gt;\n&quot;;
</span><span class="cx">                 foreach ( (array) $keys as $key ) {
</span><span class="cx">                         $keyt = trim($key);
</span><del>-                        if ( '_' == $keyt[0] )
</del><ins>+                        if ( is_protected_meta( $keyt, 'post' ) )
</ins><span class="cx">                                 continue;
</span><span class="cx">                         $values = array_map('trim', get_post_custom_values($key));
</span><span class="cx">                         $value = implode($values,', ');
</span></span></pre>
</div>
</div>

</body>
</html>