[wp-trac] [WordPress Trac] #23148: Add hook in wp_ajax_save_attachment for additional attachment fields
WordPress Trac
noreply at wordpress.org
Fri Feb 15 16:32:32 UTC 2013
#23148: Add hook in wp_ajax_save_attachment for additional attachment fields
-------------------------+------------------
Reporter: griffinjt | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: 3.6
Component: Media | Version: 3.5
Severity: normal | Resolution:
Keywords: has-patch |
-------------------------+------------------
Changes (by bradyvercher):
* cc: brady@… (added)
Comment:
Any fields added using the backward compatible filter
`attachment_fields_to_edit` are already rendered in the new media modal
and can be saved by hooking into `attachment_field_to_save`, which is
fired by `wp_ajax_save_attachment_compat()`. These fields can also be
registered to work on the new "Edit Media" screens, so I'm not sure a hook
is really necessary here.
Here's how something similar would be done:
{{{
function attachment_url_field_23148( $form_fields, $post ) {
$form_fields['attachment_url_23148'] = array(
'label' => 'Link',
'input' => 'text',
'value' => get_post_meta( $post->ID,
'attachment_url_23148', true ),
'show_in_edit' => false,
);
return $form_fields;
}
add_filter( 'attachment_fields_to_edit', 'attachment_url_field_23148', 10,
2 );
function save_attachment_url_23148( $post, $data ) {
if ( isset( $data['attachment_url_23148'] ) ) {
update_post_meta( $post['ID'], 'attachment_url_23148',
esc_url_raw( $data['attachment_url_23148'] ) );
}
return $post;
}
add_filter( 'attachment_fields_to_save', 'save_attachment_url_23148', 10,
2 );
}}}
--
Ticket URL: <http://core.trac.wordpress.org/ticket/23148#comment:12>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list