<!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>[22783] trunk: Support attachment_fields_to_save and attachment_fields_to_edit for attachments going through post.php.</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/22783">22783</a></dd>
<dt>Author</dt> <dd>nacin</dd>
<dt>Date</dt> <dd>2012-11-21 18:53:00 +0000 (Wed, 21 Nov 2012)</dd>
</dl>

<h3>Log Message</h3>
<pre>Support attachment_fields_to_save and attachment_fields_to_edit for attachments going through post.php. see <a href="http://core.trac.wordpress.org/ticket/22186">#22186</a>. see <a href="http://core.trac.wordpress.org/ticket/21391">#21391</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadmincsswpadminrtlcss">trunk/wp-admin/css/wp-admin-rtl.css</a></li>
<li><a href="#trunkwpadmincsswpadmincss">trunk/wp-admin/css/wp-admin.css</a></li>
<li><a href="#trunkwpadminincludesmediaphp">trunk/wp-admin/includes/media.php</a></li>
<li><a href="#trunkwpadminincludespostphp">trunk/wp-admin/includes/post.php</a></li>
<li><a href="#trunkwpincludesmediaphp">trunk/wp-includes/media.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadmincsswpadminrtlcss"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/css/wp-admin-rtl.css (22782 => 22783)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/css/wp-admin-rtl.css        2012-11-21 18:37:52 UTC (rev 22782)
+++ trunk/wp-admin/css/wp-admin-rtl.css        2012-11-21 18:53:00 UTC (rev 22783)
</span><span class="lines">@@ -922,6 +922,11 @@
</span><span class="cx">         padding-right: 18px;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+.compat-attachment-fields th {
+        padding-right: 0;
+        padding-left: 10px;
+}
+
</ins><span class="cx"> /*------------------------------------------------------------------------------
</span><span class="cx">   11.1 - Custom Fields
</span><span class="cx"> ------------------------------------------------------------------------------*/
</span></span></pre></div>
<a id="trunkwpadmincsswpadmincss"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/css/wp-admin.css (22782 => 22783)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/css/wp-admin.css        2012-11-21 18:37:52 UTC (rev 22782)
+++ trunk/wp-admin/css/wp-admin.css        2012-11-21 18:53:00 UTC (rev 22783)
</span><span class="lines">@@ -3400,6 +3400,11 @@
</span><span class="cx">         display: none;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+.compat-attachment-fields th {
+        padding-top: 5px;
+        padding-right: 10px;
+}
+
</ins><span class="cx"> /*------------------------------------------------------------------------------
</span><span class="cx">   11.2 - Post Revisions
</span><span class="cx"> ------------------------------------------------------------------------------*/
</span></span></pre></div>
<a id="trunkwpadminincludesmediaphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/media.php (22782 => 22783)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/media.php        2012-11-21 18:37:52 UTC (rev 22782)
+++ trunk/wp-admin/includes/media.php        2012-11-21 18:53:00 UTC (rev 22783)
</span><span class="lines">@@ -1276,6 +1276,7 @@
</span><span class="cx"> 
</span><span class="cx">         $default_args = array(
</span><span class="cx">                 'errors' =&gt; null,
</span><ins>+                'taxonomies' =&gt; false,
</ins><span class="cx">         );
</span><span class="cx"> 
</span><span class="cx">         $args = wp_parse_args( $args, $default_args );
</span><span class="lines">@@ -1283,26 +1284,28 @@
</span><span class="cx"> 
</span><span class="cx">         $form_fields = array();
</span><span class="cx"> 
</span><del>-        foreach ( get_attachment_taxonomies($post) as $taxonomy ) {
-                $t = (array) get_taxonomy($taxonomy);
-                if ( ! $t['public'] || ! $t['show_ui'] )
-                        continue;
-                if ( empty($t['label']) )
-                        $t['label'] = $taxonomy;
-                if ( empty($t['args']) )
-                        $t['args'] = array();
</del><ins>+        if ( $args['taxonomies'] ) {
+                foreach ( get_attachment_taxonomies($post) as $taxonomy ) {
+                        $t = (array) get_taxonomy($taxonomy);
+                        if ( ! $t['public'] || ! $t['show_ui'] )
+                                continue;
+                        if ( empty($t['label']) )
+                                $t['label'] = $taxonomy;
+                        if ( empty($t['args']) )
+                                $t['args'] = array();
</ins><span class="cx"> 
</span><del>-                $terms = get_object_term_cache($post-&gt;ID, $taxonomy);
-                if ( false === $terms )
-                        $terms = wp_get_object_terms($post-&gt;ID, $taxonomy, $t['args']);
</del><ins>+                        $terms = get_object_term_cache($post-&gt;ID, $taxonomy);
+                        if ( false === $terms )
+                                $terms = wp_get_object_terms($post-&gt;ID, $taxonomy, $t['args']);
</ins><span class="cx"> 
</span><del>-                $values = array();
</del><ins>+                        $values = array();
</ins><span class="cx"> 
</span><del>-                foreach ( $terms as $term )
-                        $values[] = $term-&gt;slug;
-                $t['value'] = join(', ', $values);
</del><ins>+                        foreach ( $terms as $term )
+                                $values[] = $term-&gt;slug;
+                        $t['value'] = join(', ', $values);
</ins><span class="cx"> 
</span><del>-                $form_fields[$taxonomy] = $t;
</del><ins>+                        $form_fields[$taxonomy] = $t;
+                }
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         // Merge default fields with their errors, so any key passed with the error (e.g. 'error', 'helps', 'value') will replace the default
</span><span class="lines">@@ -1332,6 +1335,7 @@
</span><span class="cx">                         continue;
</span><span class="cx"> 
</span><span class="cx">                 $name = &quot;attachments[$attachment_id][$id]&quot;;
</span><ins>+                $id_attr = &quot;attachments-$attachment_id-$id&quot;;
</ins><span class="cx"> 
</span><span class="cx">                 if ( !empty( $field['tr'] ) ) {
</span><span class="cx">                         $item .= $field['tr'];
</span><span class="lines">@@ -1341,17 +1345,17 @@
</span><span class="cx">                 $field = array_merge( $defaults, $field );
</span><span class="cx"> 
</span><span class="cx">                 if ( $field['input'] == 'hidden' ) {
</span><del>-                        $hidden_fields[$id] = $field['value'];
</del><ins>+                        $hidden_fields[$name] = $field['value'];
</ins><span class="cx">                         continue;
</span><span class="cx">                 }
</span><span class="cx"> 
</span><span class="cx">                 $required      = $field['required'] ? '&lt;span class=&quot;alignright&quot;&gt;&lt;abbr title=&quot;required&quot; class=&quot;required&quot;&gt;*&lt;/abbr&gt;&lt;/span&gt;' : '';
</span><span class="cx">                 $aria_required = $field['required'] ? &quot; aria-required='true' &quot; : '';
</span><del>-                $class  = 'compat-item-' . $name;
</del><ins>+                $class  = 'compat-field-' . $id;
</ins><span class="cx">                 $class .= $field['required'] ? ' form-required' : '';
</span><span class="cx"> 
</span><span class="cx">                 $item .= &quot;\t\t&lt;tr class='$class'&gt;&quot;;
</span><del>-                $item .= &quot;\t\t\t&lt;th valign='top' scope='row' class='label'&gt;&lt;label for='$name'&gt;&lt;span class='alignleft'&gt;{$field['label']}&lt;/span&gt;$required&lt;br class='clear' /&gt;&lt;/label&gt;&quot;;
</del><ins>+                $item .= &quot;\t\t\t&lt;th valign='top' scope='row' class='label'&gt;&lt;label for='$id_attr'&gt;&lt;span class='alignleft'&gt;{$field['label']}&lt;/span&gt;$required&lt;br class='clear' /&gt;&lt;/label&gt;&quot;;
</ins><span class="cx">                 $item .= &quot;&lt;/th&gt;\n\t\t\t&lt;td class='field'&gt;&quot;;
</span><span class="cx"> 
</span><span class="cx">                 if ( !empty( $field[ $field['input'] ] ) )
</span><span class="lines">@@ -1361,9 +1365,9 @@
</span><span class="cx">                                 // sanitize_post() skips the post_content when user_can_richedit
</span><span class="cx">                                 $field['value'] = htmlspecialchars( $field['value'], ENT_QUOTES );
</span><span class="cx">                         }
</span><del>-                        $item .= &quot;&lt;textarea id='$name' name='$name' $aria_required&gt;&quot; . $field['value'] . '&lt;/textarea&gt;';
</del><ins>+                        $item .= &quot;&lt;textarea id='$id_attr' name='$name' $aria_required&gt;&quot; . $field['value'] . '&lt;/textarea&gt;';
</ins><span class="cx">                 } else {
</span><del>-                        $item .= &quot;&lt;input type='text' class='text' id='$name' name='$name' value='&quot; . esc_attr( $field['value'] ) . &quot;' $aria_required /&gt;&quot;;
</del><ins>+                        $item .= &quot;&lt;input type='text' class='text' id='$id_attr' name='$name' value='&quot; . esc_attr( $field['value'] ) . &quot;' $aria_required /&gt;&quot;;
</ins><span class="cx">                 }
</span><span class="cx">                 if ( !empty( $field['helps'] ) )
</span><span class="cx">                         $item .= &quot;&lt;p class='help'&gt;&quot; . join( &quot;&lt;/p&gt;\n&lt;p class='help'&gt;&quot;, array_unique( (array) $field['helps'] ) ) . '&lt;/p&gt;';
</span><span class="lines">@@ -1388,7 +1392,7 @@
</span><span class="cx">         if ( !empty( $form_fields['_final'] ) )
</span><span class="cx">                 $item .= &quot;\t\t&lt;tr class='final'&gt;&lt;td colspan='2'&gt;{$form_fields['_final']}&lt;/td&gt;&lt;/tr&gt;\n&quot;;
</span><span class="cx">         if ( $item )
</span><del>-                $item = '&lt;table&gt;' . $item . '&lt;/table&gt;';
</del><ins>+                $item = '&lt;table class=&quot;compat-attachment-fields&quot;&gt;' . $item . '&lt;/table&gt;';
</ins><span class="cx"> 
</span><span class="cx">         return array(
</span><span class="cx">                 'item'   =&gt; $item,
</span><span class="lines">@@ -2285,6 +2289,11 @@
</span><span class="cx"> 
</span><span class="cx">         &lt;/div&gt;
</span><span class="cx">         &lt;?php
</span><ins>+        $extras = get_compat_media_markup( $post-&gt;ID );
+        echo $extras['item'];
+        foreach ( $extras['hidden'] as $hidden_field =&gt; $value ) {
+                echo '&lt;input type=&quot;hidden&quot; name=&quot;' . esc_attr( $hidden_field ) . '&quot; value=&quot;' . esc_attr( $value ) . '&quot; /&gt;' . &quot;\n&quot;;
+        }
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span></span></pre></div>
<a id="trunkwpadminincludespostphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/post.php (22782 => 22783)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/post.php        2012-11-21 18:37:52 UTC (rev 22782)
+++ trunk/wp-admin/includes/post.php        2012-11-21 18:53:00 UTC (rev 22783)
</span><span class="lines">@@ -238,6 +238,9 @@
</span><span class="cx">                         // update_meta expects slashed
</span><span class="cx">                         update_post_meta( $post_ID, '_wp_attachment_image_alt', addslashes( $image_alt ) );
</span><span class="cx">                 }
</span><ins>+
+                if ( isset( $post_data['attachments'][ $post_ID ] ) )
+                        $post_data = apply_filters( 'attachment_fields_to_save', $post_data, $post_data['attachments'][ $post_ID ] );
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         add_meta( $post_ID );
</span></span></pre></div>
<a id="trunkwpincludesmediaphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/media.php (22782 => 22783)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/media.php        2012-11-21 18:37:52 UTC (rev 22782)
+++ trunk/wp-includes/media.php        2012-11-21 18:53:00 UTC (rev 22783)
</span><span class="lines">@@ -1293,7 +1293,7 @@
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         if ( function_exists('get_compat_media_markup') )
</span><del>-                $response['compat'] = get_compat_media_markup( $attachment-&gt;ID );
</del><ins>+                $response['compat'] = get_compat_media_markup( $attachment-&gt;ID, array( 'taxonomies' =&gt; true ) );
</ins><span class="cx"> 
</span><span class="cx">         return apply_filters( 'wp_prepare_attachment_for_js', $response, $attachment, $meta );
</span><span class="cx"> }
</span></span></pre>
</div>
</div>

</body>
</html>