Is this possible to do?
I love how the new uploader works. I’m guessing it has to do with a jQuery call like the other way did.
EDIT
This is the code I am currently using
jQuery(document).ready(function($) {
$('.custom_upload_image_button').click(function() {
imageField = $(this).prev('input');
tb_show('', 'media-upload.php?type=image&TB_iframe=true');
});
window.send_to_editor = function(html) {
imgurl = $(html).attr('href');
$(imageField).val(imgurl);
tb_remove();
};
$('.clear_field').click(function() {
var defaultImage = jQuery(this).parent().siblings('.custom_default_image').text();
jQuery(this).parent().siblings('.custom_upload_image').val('');
return false;
});
});
To get you started, the basic functions and overrides as far as I know currently.There might be better solutions, but I only had two days with 3.5 yet:
This is not complete working answer. You have to define and keep track of your input fields by yourself etc.. This just should get you started.
If you have more concrete questions, just ask.
And make sure to reassign the original functions when your script is done.
Pulled from comments:
Here is a small tutorial on how to use WP 3.5 media uploader in theme options. That’s what I came up with and it works perfect for me. Let me know if you come up with any better solution.
Here is how I have implemented the code in my theme options:
Update
This code works only on post edit page. To make it work on theme options page you need to add
wp_enqueue_media();
I’m doing almost the same it’s not ready yet but it works:
in the php:
The javascript:
This will enable you to upload and send the image url (of any size) to the
<input>
element.I’m trying to do this as a setting it and it works, Only thig I need now is a reliable way to send the attachment ID to the
<input>
I think @janw has got this one completely right, but I was unable to make one thing work. Jan inserts the media library button using:
and then pre-empts the default action using:
The problem that I ran into is that inserting a media button in this fashion does not assign an id of “default_featured_image_button” to the link. In fact it does not add any id on the inserted link. So this is what I did to get it to work.
I added this line to my meta box callback function just after my input field:
I then enqueued my custom jquery file and the thickbox css file, also in my functions.php file, using:
Finally my image-set.js file included the following:
You will note that I used variables to store the name and id of the input field that is just prior to the link that calls the jQuery. In that way this code can be used repeatedly on the same page. You would just need to assign a class to all buttons or use individual id’s for the buttons in your jquery as I did. I hope this helps someone as Jan’s answer did me.
I know that this is an old post, but I just want to share my findings:
To open the media editor, we call this function
the media editor basically will check for tinyMCE editor (
window.tinymce
), then Quicktags (window.QTags
), to pass the content to.For my approach to get the content, I assigned
window.QTags
with a custom object, which has aninsertContent()
method:Reference: phpxref