[wp-hackers] get attachment ID when hijacking Media Library send_to_editor

Steve Taylor steve at sltaylor.co.uk
Mon Mar 21 18:52:05 UTC 2011


I'm using code from Brad Williams, Ozh Richard and Justin Tadlock's
excellent new book on plugin development (pp. 84 - 89; boj-meta-box in
http://media.wiley.com/product_ancillary/22/04709162/DOWNLOAD/Chapter%2004%20Code.zip).

The idea is to hijack the Media Library interface for choosing images
or files for custom fields (whether in post meta boxes, custom
settings pages, widgets, etc.).

What I'm trying to do is to return the attachment ID instead of the
URL. The standard send_to_editor function is the way the code I'm
building on gets into things - replacing it with another function
which takes the HTML on its way into the editor and grabs the URL from
the image SRC.

Getting the image ID is doable - it's included as part of a class in
the HTML generated. But what about other files? The HTML generated is
just a link, without any indication of the ID. You could take the URL
and maybe match on the guid column in the posts table - but what if
the Link field is empty? Only the file title is returned, and this
isn't necessarily unique.

Has anyone figured out how to get the ID of the selected file more directly?

cheers,

Steve Taylor


More information about the wp-hackers mailing list