Created
May 15, 2011 13:18
-
-
Save miya0001/973153 to your computer and use it in GitHub Desktop.
WordPressプラグイン内でメディアアップローダーを使用してファイル名を選択しテキストフィールドに挿入する
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
<h3>My Picture (1)</h3> | |
<input type="text" id="my_media_1" name="my_media_1" value="" /> | |
<a class="media-upload" href="JavaScript:void(0);" rel="my_media_1">Select File</a> | |
<h3>My Picture (2)</h3> | |
<input type="text" id="my_media_2" name="my_media_2" value="" /> | |
<a class="media-upload" href="JavaScript:void(0);" rel="my_media_2">Select File</a> |
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
jQuery('document').ready(function(){ | |
jQuery('.media-upload').each(function(){ | |
var rel = jQuery(this).attr("rel"); | |
jQuery(this).click(function(){ | |
window.send_to_editor = function(html) { | |
imgurl = jQuery('img', html).attr('src'); | |
jQuery('#'+rel).val(imgurl); | |
tb_remove(); | |
} | |
formfield = jQuery('#'+rel).attr('name'); | |
tb_show(null, 'media-upload.php?post_id=0&type=image&TB_iframe=true'); | |
return false; | |
}); | |
}); | |
}); |
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
<?php | |
add_action('admin_print_scripts-'.$hook_suffix, 'my_admin_scripts'); | |
add_action('admin_print_styles-'.$hook_suffix, 'my_admin_styles'); | |
function my_admin_styles() { | |
wp_enqueue_style('thickbox'); | |
} | |
function my_admin_scripts() { | |
wp_enqueue_script('media-upload'); | |
wp_enqueue_script('thickbox'); | |
wp_enqueue_script('jquery'); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Love the plugin Oembedgist. I was struggling for over a week trying to figure out how to do this natively with WordPress and some other plugins but this one did the job. WordPress won't let me post reviews as I am a new member so here is a tip for anyone who installs the plugin but unable to post a single gist file using the example provided by the author.
The URL for a single gist has to be in the format https://gist.github.com/frndlyy/e7e51d3acddee51c4e42d0ee9bbe0dc0#file-aduser_create_bulk_users.ps1
and not https://gist.github.com/frndlyy/e7e51d3acddee51c4e42d0ee9bbe0dc0#file-aduser_create_bulk_users-ps1
Notice the difference. You have to copy the actual file name (.ps1 file extension) and not the URL when you click on the gist file