Support attachment_fields_to_save and attachment_fields_to_edit for attachments going through post.php. see #22186. see #21391.
git-svn-id: http://core.svn.wordpress.org/trunk@22783 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
6815f4bfef
commit
55a6c62e76
|
@ -922,6 +922,11 @@ th.sorted a span {
|
||||||
padding-right: 18px;
|
padding-right: 18px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.compat-attachment-fields th {
|
||||||
|
padding-right: 0;
|
||||||
|
padding-left: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
/*------------------------------------------------------------------------------
|
/*------------------------------------------------------------------------------
|
||||||
11.1 - Custom Fields
|
11.1 - Custom Fields
|
||||||
------------------------------------------------------------------------------*/
|
------------------------------------------------------------------------------*/
|
||||||
|
|
|
@ -3400,6 +3400,11 @@ td.plugin-title p {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.compat-attachment-fields th {
|
||||||
|
padding-top: 5px;
|
||||||
|
padding-right: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
/*------------------------------------------------------------------------------
|
/*------------------------------------------------------------------------------
|
||||||
11.2 - Post Revisions
|
11.2 - Post Revisions
|
||||||
------------------------------------------------------------------------------*/
|
------------------------------------------------------------------------------*/
|
||||||
|
|
|
@ -1276,6 +1276,7 @@ function get_compat_media_markup( $attachment_id, $args = null ) {
|
||||||
|
|
||||||
$default_args = array(
|
$default_args = array(
|
||||||
'errors' => null,
|
'errors' => null,
|
||||||
|
'taxonomies' => false,
|
||||||
);
|
);
|
||||||
|
|
||||||
$args = wp_parse_args( $args, $default_args );
|
$args = wp_parse_args( $args, $default_args );
|
||||||
|
@ -1283,26 +1284,28 @@ function get_compat_media_markup( $attachment_id, $args = null ) {
|
||||||
|
|
||||||
$form_fields = array();
|
$form_fields = array();
|
||||||
|
|
||||||
foreach ( get_attachment_taxonomies($post) as $taxonomy ) {
|
if ( $args['taxonomies'] ) {
|
||||||
$t = (array) get_taxonomy($taxonomy);
|
foreach ( get_attachment_taxonomies($post) as $taxonomy ) {
|
||||||
if ( ! $t['public'] || ! $t['show_ui'] )
|
$t = (array) get_taxonomy($taxonomy);
|
||||||
continue;
|
if ( ! $t['public'] || ! $t['show_ui'] )
|
||||||
if ( empty($t['label']) )
|
continue;
|
||||||
$t['label'] = $taxonomy;
|
if ( empty($t['label']) )
|
||||||
if ( empty($t['args']) )
|
$t['label'] = $taxonomy;
|
||||||
$t['args'] = array();
|
if ( empty($t['args']) )
|
||||||
|
$t['args'] = array();
|
||||||
|
|
||||||
$terms = get_object_term_cache($post->ID, $taxonomy);
|
$terms = get_object_term_cache($post->ID, $taxonomy);
|
||||||
if ( false === $terms )
|
if ( false === $terms )
|
||||||
$terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']);
|
$terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']);
|
||||||
|
|
||||||
$values = array();
|
$values = array();
|
||||||
|
|
||||||
foreach ( $terms as $term )
|
foreach ( $terms as $term )
|
||||||
$values[] = $term->slug;
|
$values[] = $term->slug;
|
||||||
$t['value'] = join(', ', $values);
|
$t['value'] = join(', ', $values);
|
||||||
|
|
||||||
$form_fields[$taxonomy] = $t;
|
$form_fields[$taxonomy] = $t;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Merge default fields with their errors, so any key passed with the error (e.g. 'error', 'helps', 'value') will replace the default
|
// Merge default fields with their errors, so any key passed with the error (e.g. 'error', 'helps', 'value') will replace the default
|
||||||
|
@ -1332,6 +1335,7 @@ function get_compat_media_markup( $attachment_id, $args = null ) {
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
$name = "attachments[$attachment_id][$id]";
|
$name = "attachments[$attachment_id][$id]";
|
||||||
|
$id_attr = "attachments-$attachment_id-$id";
|
||||||
|
|
||||||
if ( !empty( $field['tr'] ) ) {
|
if ( !empty( $field['tr'] ) ) {
|
||||||
$item .= $field['tr'];
|
$item .= $field['tr'];
|
||||||
|
@ -1341,17 +1345,17 @@ function get_compat_media_markup( $attachment_id, $args = null ) {
|
||||||
$field = array_merge( $defaults, $field );
|
$field = array_merge( $defaults, $field );
|
||||||
|
|
||||||
if ( $field['input'] == 'hidden' ) {
|
if ( $field['input'] == 'hidden' ) {
|
||||||
$hidden_fields[$id] = $field['value'];
|
$hidden_fields[$name] = $field['value'];
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$required = $field['required'] ? '<span class="alignright"><abbr title="required" class="required">*</abbr></span>' : '';
|
$required = $field['required'] ? '<span class="alignright"><abbr title="required" class="required">*</abbr></span>' : '';
|
||||||
$aria_required = $field['required'] ? " aria-required='true' " : '';
|
$aria_required = $field['required'] ? " aria-required='true' " : '';
|
||||||
$class = 'compat-item-' . $name;
|
$class = 'compat-field-' . $id;
|
||||||
$class .= $field['required'] ? ' form-required' : '';
|
$class .= $field['required'] ? ' form-required' : '';
|
||||||
|
|
||||||
$item .= "\t\t<tr class='$class'>";
|
$item .= "\t\t<tr class='$class'>";
|
||||||
$item .= "\t\t\t<th valign='top' scope='row' class='label'><label for='$name'><span class='alignleft'>{$field['label']}</span>$required<br class='clear' /></label>";
|
$item .= "\t\t\t<th valign='top' scope='row' class='label'><label for='$id_attr'><span class='alignleft'>{$field['label']}</span>$required<br class='clear' /></label>";
|
||||||
$item .= "</th>\n\t\t\t<td class='field'>";
|
$item .= "</th>\n\t\t\t<td class='field'>";
|
||||||
|
|
||||||
if ( !empty( $field[ $field['input'] ] ) )
|
if ( !empty( $field[ $field['input'] ] ) )
|
||||||
|
@ -1361,9 +1365,9 @@ function get_compat_media_markup( $attachment_id, $args = null ) {
|
||||||
// sanitize_post() skips the post_content when user_can_richedit
|
// sanitize_post() skips the post_content when user_can_richedit
|
||||||
$field['value'] = htmlspecialchars( $field['value'], ENT_QUOTES );
|
$field['value'] = htmlspecialchars( $field['value'], ENT_QUOTES );
|
||||||
}
|
}
|
||||||
$item .= "<textarea id='$name' name='$name' $aria_required>" . $field['value'] . '</textarea>';
|
$item .= "<textarea id='$id_attr' name='$name' $aria_required>" . $field['value'] . '</textarea>';
|
||||||
} else {
|
} else {
|
||||||
$item .= "<input type='text' class='text' id='$name' name='$name' value='" . esc_attr( $field['value'] ) . "' $aria_required />";
|
$item .= "<input type='text' class='text' id='$id_attr' name='$name' value='" . esc_attr( $field['value'] ) . "' $aria_required />";
|
||||||
}
|
}
|
||||||
if ( !empty( $field['helps'] ) )
|
if ( !empty( $field['helps'] ) )
|
||||||
$item .= "<p class='help'>" . join( "</p>\n<p class='help'>", array_unique( (array) $field['helps'] ) ) . '</p>';
|
$item .= "<p class='help'>" . join( "</p>\n<p class='help'>", array_unique( (array) $field['helps'] ) ) . '</p>';
|
||||||
|
@ -1388,7 +1392,7 @@ function get_compat_media_markup( $attachment_id, $args = null ) {
|
||||||
if ( !empty( $form_fields['_final'] ) )
|
if ( !empty( $form_fields['_final'] ) )
|
||||||
$item .= "\t\t<tr class='final'><td colspan='2'>{$form_fields['_final']}</td></tr>\n";
|
$item .= "\t\t<tr class='final'><td colspan='2'>{$form_fields['_final']}</td></tr>\n";
|
||||||
if ( $item )
|
if ( $item )
|
||||||
$item = '<table>' . $item . '</table>';
|
$item = '<table class="compat-attachment-fields">' . $item . '</table>';
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'item' => $item,
|
'item' => $item,
|
||||||
|
@ -2285,6 +2289,11 @@ function edit_form_image_editor() {
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<?php
|
<?php
|
||||||
|
$extras = get_compat_media_markup( $post->ID );
|
||||||
|
echo $extras['item'];
|
||||||
|
foreach ( $extras['hidden'] as $hidden_field => $value ) {
|
||||||
|
echo '<input type="hidden" name="' . esc_attr( $hidden_field ) . '" value="' . esc_attr( $value ) . '" />' . "\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -238,6 +238,9 @@ function edit_post( $post_data = null ) {
|
||||||
// update_meta expects slashed
|
// update_meta expects slashed
|
||||||
update_post_meta( $post_ID, '_wp_attachment_image_alt', addslashes( $image_alt ) );
|
update_post_meta( $post_ID, '_wp_attachment_image_alt', addslashes( $image_alt ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( isset( $post_data['attachments'][ $post_ID ] ) )
|
||||||
|
$post_data = apply_filters( 'attachment_fields_to_save', $post_data, $post_data['attachments'][ $post_ID ] );
|
||||||
}
|
}
|
||||||
|
|
||||||
add_meta( $post_ID );
|
add_meta( $post_ID );
|
||||||
|
|
|
@ -1293,7 +1293,7 @@ function wp_prepare_attachment_for_js( $attachment ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( function_exists('get_compat_media_markup') )
|
if ( function_exists('get_compat_media_markup') )
|
||||||
$response['compat'] = get_compat_media_markup( $attachment->ID );
|
$response['compat'] = get_compat_media_markup( $attachment->ID, array( 'taxonomies' => true ) );
|
||||||
|
|
||||||
return apply_filters( 'wp_prepare_attachment_for_js', $response, $attachment, $meta );
|
return apply_filters( 'wp_prepare_attachment_for_js', $response, $attachment, $meta );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue