Last active
December 23, 2015 05:09
-
-
Save jeffsebring/6585213 to your computer and use it in GitHub Desktop.
WP 3.5 Metabox Uploader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
var file_frame; | |
var wp_media_post_id = wp.media.model.settings.post.id; | |
var set_to_post_id = <?php echo get_the_ID(); ?>; | |
jQuery('.upload_image_button').on('click', function( event ){ | |
event.preventDefault(); | |
if ( file_frame ) { | |
file_frame.uploader.uploader.param( 'post_id', set_to_post_id ); | |
file_frame.open(); | |
return; | |
} else { | |
wp.media.model.settings.post.id = set_to_post_id; | |
} | |
file_frame = wp.media.frames.file_frame = wp.media({ | |
title: jQuery( this ).data( 'uploader_title' ), | |
button: { | |
text: jQuery( this ).data( 'uploader_button_text' ), | |
}, | |
multiple: false | |
}); | |
file_frame.on( 'select', function() { | |
attachment = file_frame.state().get('selection').first().toJSON(); | |
jQuery( '#pu01_audio-box' ).val( attachment.url ); | |
wp.media.model.settings.post.id = wp_media_post_id; | |
}); | |
file_frame.open(); | |
}); | |
jQuery( 'a.add_media' ).on('click', function() { | |
wp.media.model.settings.post.id = wp_media_post_id; | |
}); | |
</script> | |
<label for="pu01_audio">Audio</label><br> | |
<input size="50" type="text" name="pu01_audio" id="pu01_audio-box" value="<?php echo esc_url( $value ); ?>" /> | |
<input type="button" data-uploader_title="Choose or Upload an Audio File" class="button upload_image_button" name="pu01_audio_uploader" id="pu01_audio_uploader" value="Upload" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment