Created
October 20, 2012 21:33
-
-
Save pgooch/3924890 to your computer and use it in GitHub Desktop.
Use the default wordpress media uploader into your plugin.
This file contains 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
<!-- This is just the code for the button and hidden input --> | |
<input id="backdrop_upload_button" value="Upload/Select Image" type="button" class="button" /> | |
<input type="hidden" name="the_image" id="the_image" value="<?= $settings['the_image'] ?>" /> |
This file contains 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
// This is the jQuery that opens the uploader and gets the result, then places it in the hidden input | |
var $ = jQuery; | |
// Handels image uploading | |
$(document).ready(function(){ | |
$("input#upload_button").click(function(){ | |
tb_show('','media-upload.php?type=image&post_id=1&TB_iframe=true&flash=0&backdrop=true'); | |
return false; | |
}) | |
window.send_to_editor=function(html){ | |
var img = $('<div>'+html+'</div>').find('img').attr('src'); | |
$('#the_image').val(img); | |
tb_remove(); | |
}; | |
}); |
This file contains 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
// This adds the required scripts to the admin head | |
add_action('admin_print_scripts',array(&$this,'uploader_scripts')); | |
add_action('admin_print_styles',array(&$this,'uploader_styles')); | |
public function uploader_scripts(){ | |
wp_enqueue_script('media-upload'); | |
wp_enqueue_script('thinkbox'); | |
} | |
public function uploader_styles(){ | |
wp_enqueue_style('thickbox'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment