나는 워드 프레스 플러그인을 개발 중이며 이미지를 업로드 할 수있는 필드가 있어야합니다. 워드 프레스는 매우 손수 업 로더를 가지고 있기 때문에 그것을 사용할 수 있다면 좋을 것입니다.내 플러그인에서 wordpress 업로드 파일/이미지 코드를 사용하는 방법
가능하면 누구나 알 수 있습니까? 당신은 단지 파일을 업로드 할 경우
감사
나는 워드 프레스 플러그인을 개발 중이며 이미지를 업로드 할 수있는 필드가 있어야합니다. 워드 프레스는 매우 손수 업 로더를 가지고 있기 때문에 그것을 사용할 수 있다면 좋을 것입니다.내 플러그인에서 wordpress 업로드 파일/이미지 코드를 사용하는 방법
가능하면 누구나 알 수 있습니까? 당신은 단지 파일을 업로드 할 경우
감사
, 당신은 미디어 업 로더가 필요하지 않습니다. 간단한 양식 만 있으면됩니다. 당신은 어쩌면이 작업을하기 위해 미디어 upload.php로에 URL을 추가해야합니다
<a onclick="return false;" title="Upload image" class="thickbox" id="add_image" href="media-upload.php?type=image&TB_iframe=true&width=640&height=105">Upload Image</a>
:
는이 같은 링크를 필요로하는 미디어 업 로더를 호출합니다.>>> media-upload.php에 URL을 추가해야 작동 할 수 있습니다. 어떻게하면됩니까? – vick
blog를 포함 할 href 속성에 대해 php echo bloginfo ('name')?>/wp-admin/media-upload.php? type = image & TB_iframe = true & 너비 = 640 & height = 105 url과 wp-admin 폴더는 media-upload.php가 위치해 있습니다. – 2ndkauboy
플러그인이 할 일은 무엇입니까? 나는 3 개의 플러그인을 직접 작성했다. 어쩌면 당신의 플러그인이 나를 위해 유용 할 수도 있습니다. 그리고 당신이 대답을 투표하고 받아 들일 수 있다는 것을 알았습니까?) – 2ndkauboy
이 코드를 사용하여 워드 프레스 기본 미디어 파일 업 로더를 사용하여 간단하게
<label for="upload_image">
<input id="upload_image" type="text" size="36" name="ad_image" value="http://" />
<input id="upload_image_button" class="button" type="button" value="Upload Image" />
<br />Enter a URL or upload an image
</label>
<?php
add_action('admin_enqueue_scripts', 'my_admin_scripts');
function my_admin_scripts() {
if (isset($_GET['page']) && $_GET['page'] == 'my_plugin_page') {
wp_enqueue_media();
wp_register_script('my-admin-js', WP_PLUGIN_URL.'/my-plugin/my-admin.js', array('jquery'));
wp_enqueue_script('my-admin-js');
}
}
?>
<script>
jQuery(document).ready(function($){
var custom_uploader;
$('#upload_image_button').click(function(e) {
e.preventDefault();
//If the uploader object has already been created, reopen the dialog
if (custom_uploader) {
custom_uploader.open();
return;
}
//Extend the wp.media object
custom_uploader = wp.media.frames.file_frame = wp.media({
title: 'Choose Image',
button: {
text: 'Choose Image'
},
multiple: true
});
//When a file is selected, grab the URL and set it as the text field's value
custom_uploader.on('select', function() {
console.log(custom_uploader.state().get('selection').toJSON());
attachment = custom_uploader.state().get('selection').first().toJSON();
$('#upload_image').val(attachment.url);
});
//Open the uploader dialog
custom_uploader.open();
});
});
</script>
이라는 줄을 추가하고 선택한 이미지를 축소판으로 표시 할 수 있습니다. $ ('# upload_image_src'). attr ('src', attachment.url); –
http://www.webmaster-source.com/2010/01/08/using- JQuery와에 이미지의 링크를 검색 할 수 있습니다 the-wordpress-uploader-in-your-plugin-or-theme/ – Anonymous
나는 이것에 관한 튜토리얼을 썼다. Wordpress의 미디어 업 로더 드롭 다운을 사용하는 방법 :) http://www.cedricve.me/2012/03/ 31/use-the-built-in-wordpress-uploader-in-own-wp-plugin/당신이나 다른 사람에게 도움이되기를 바랍니다. 좋은 하루 보내십시오 –