[wp-hackers] Simplifying media-upload.php reuse in custom metaboxes

Andrew Nacin wp at andrewnacin.com
Wed Aug 18 08:04:46 UTC 2010


On Wed, Aug 18, 2010 at 3:29 AM, Adam van den Hoven <adam at littlefyr.com>wrote:

> Hey guys,
>
> I've been hacking around trying to get the media library to work well with
> custom meta boxes. Specifically, I want to pass modify the form fields that
> show up for the media items to only provide the size selectors and to only
> allow sending the URL for the chosen size to a piece of javascript that
> will
> update the meta box accordingly.
>
> To this end, I've made the following change in wp-admin/includes/media.php
>
> 1302,1303d1301
> <   $form_fields = apply_filters('media_upload_media_item_form_fields',
> $form_fields);
> <
>
> I'm terrible at picking good names but basically I want a filter that lets
> me manipulate the field items for each before it gets written out. I can
> then add arbitrary parameters to the query string and get it to do what I
> want.
>
> Initially I tried defining get_media_item in my functions.php but PHP
> complained about redefining the function (I'm not a PHP guy), so I modified
> the core function. Clearly not going to survive the next incremental
> update.
>
>
> Is there a more robust way to make this change or do I need to submit this
> as a patch?
>

In get_media_item(), $form_fields gets set like this:

$form_fields = get_attachment_fields_to_edit( $post, $errors );

In get_attachment_fields_to_edit(), you'll see a filter designed to
modify/add fields.


More information about the wp-hackers mailing list