Calling WP Gallery Uploader/Selector From Metabox

Figured out the answer to the question. file_frame.on(‘open’, function() { var selection = file_frame.state().get(‘selection’); var library = file_frame.state(‘gallery-edit’).get(‘library’); var ids = jQuery(‘#fg_perm_metadata’).val(); if (ids) { idsArray = ids.split(‘,’); idsArray.forEach(function(id) { attachment = wp.media.attachment(id); attachment.fetch(); selection.add( attachment ? [ attachment ] : [] ); }); file_frame.setState(‘gallery-edit’); idsArray.forEach(function(id) { attachment = wp.media.attachment(id); attachment.fetch(); library.add( attachment ? [ … Read more

Can’t seem to attach uploaded image to post and set it as thumbnail

You have a variable scope problem. $post_id = wp_insert_post($post_information); function upload_user_file( $file = array() ) { require_once( ABSPATH . ‘wp-admin/includes/admin.php’ ); $file_return = wp_handle_upload( $file, array(‘test_form’ => false ) ); // … You set $post_id outside of your upload_user_file() function but that means that it is unavailable inside the function where you need it for … Read more

Multiple images with Media Uploader on front-end

You can’t have two buttons with the same ID (#upload_image_button) as IDs are supposed to be unique. You should give the buttons a class and give the ID equal to that of the name of the associated input. <input type=”text” size=”36″ name=”image_1″ value=”http://” /> <input id=”image_1″ class=”button upload_image_button” type=”button” value=”Upload Image” /> <input type=”text” size=”36″ … Read more

Show media url immediately after upload in media uploader

Here’s a heinous hack that replaces the title of uploaded images with the url (constructed by chopping the “-150×150” affix from the pinkynail): function wpse156087_admin_footer_media_new_php() { ?> <script type=”text/javascript”> jQuery(document).ready(function() { (function ($) { uploader.bind(‘UploadComplete’, function() { setTimeout(function() { $(‘#media-items .media-item’).each(function () { var img_src = $(‘img’, this).prop(‘src’); if (img_src.indexOf(‘/wp-content/uploads/’) > 0) { $(‘.filename.new .title’, … Read more

Allow only attachment uploaded to current post

Maybe I was over thinking, but the solution is easier than I thought. I just have to limit the event handler to some element, so other unrelated ones will not trigger the handler. In this case, .media-modal is the overall parent of the media library element, so I am specifying this extra selector to the … Read more