For images uploaded using WordPress’ media uploader, there is an “Insert Into Post” button that sends a shortcode to the editor for that image.
I have a text input that, when focused, I’d like the media uploader to appear so that the user can select an image and send the file URL to the text input.
The main issue I’m having is creating the additional “Insert Into Post” button that sends the file URL to the appropriate text field.
Which hook do I use for that and how can I get the file URL data returned to the input field?
Your guidance is appreciated!
What you’ve described is the older WordPress way of doing it… If you want to use the new uploader in WordPress 3.5+, you can create a
wp.media
object to upload it, similar to the code in wp-admin/js/custom-background.js:the
frame.on('select' function(){
code is run when a file is chosen.A litter further searching and I was able to find some good sources explaining how to do this. I went for a JavaScript, PHP mix:
JavaScript
source: http://jaspreetchahal.org/wordpress-using-media-uploader-in-your-plugin/
PHP
source: http://shibashake.com/wordpress-theme/how-to-hook-into-the-media-upload-popup-interface