wp미디어업로더를사용한업로드파일경로가필드에표시되지않았습니다.
커스텀을 사용하고 있습니다.media upload
내 플러그인에서.저번에는(before 4.0) WordPress
버전은 완벽하게 동작합니다.오디오 또는 이미지 파일을 업로드하면 업로드가 성공합니다.
그리고 클릭을 클릭합니다."Insert Into Post"
텍스트 필드에 표시된 업로드된 파일의 경로.
단, 업그레이드 시WordPress into 4.4.2
업로드된 파일을 업로드합니다.
[ Insert Into Post ]를 클릭하면 업로드된 파일의 파일 경로가 텍스트 필드에 표시되지 않습니다.
두 WordPress의 코드는 100% 동일합니다.
HTML 코드는 다음과 같습니다.
<input type="text" size="50" name="mp3" id="mp3" class="upload-url" />
<input id="st_upload_button" class="st_upload_button" type="button" name="upload_button" value="Upload">
그리고 여기 내 기능이 있습니다.php 코드:
function pro_scripts_method() {
wp_enqueue_script('media-upload');
wp_enqueue_script('thickbox');
wp_register_script( 'custom-js', plugin_dir_url( __FILE__ )."js/custom.js");
wp_enqueue_script( 'custom-js' );
}
add_action('admin_enqueue_scripts', 'pro_scripts_method');
JS 코드는 다음과 같습니다.
jQuery('.st_upload_button').click(function() {
targetfield = jQuery(this).prev('.upload-url');
tb_show('', 'media-upload.php?type=image&TB_iframe=true');
return false;
});
window.send_to_editor = function(html) {
fileurl = jQuery(html).attr('href');
//alert(fileurl);
jQuery(targetfield).val(fileurl);
tb_remove();
}
경고합니다.fileurl
변수는 정의되지 않은 값을 제공합니다.그러니 그 문제를 해결할 수 있도록 도와주세요.
새 WordPress가 미디어 업로드에 대해 변경한 내용은 빈 링크 URL 필드입니다.
하지만file url
이 필드 아래에 있는 버튼을 클릭한 다음Insert Into Post
코드는 정상적으로 동작합니다. : )
그래서 우리는 간단한 방법을 필요로 합니다.file url
링크 URL의 값입니다. 워드프레스에 설정 유무는 모르겠지만, 그것을 달성하기 위해 jQuery에 작성한 간단한 코드가 있습니다.그것은 나에게 있어서 매우 효과가 있습니다.
내가 정말 하고 있는 건
사용자가 를 눌렀을 때Insert into Post
버튼을 클릭합니다.my jQuery는 그것의 부모를 확인합니다.Insert into Post
버튼을 클릭하여file url
[ Link URL ]필드에 삽입합니다.바로 그거야!간단하죠?
jQuery('.savesend input[type=submit]').click(function(){
var url = jQuery(this).parents('.describe').find('.urlfile').data('link-url');
var field = jQuery(this).parents('.describe').find('.urlfield');
field.val(url);
});
시험해보고 알려주세요:)
왜 안 쓰세요?
다음을 사용해 보십시오.
jQuery(document).ready(function($) {
"use strict";
$('.st_upload_button').on('click', function(e){
e.preventDefault();
var $input_field = $(this).prev();
var custom_uploader = wp.media.frames.file_frame = wp.media({
title: 'Add Audio',
button: {
text: 'Add Audio'
},
multiple: false
});
custom_uploader.on('select', function() {
var attachment = custom_uploader.state().get('selection').first().toJSON();
$input_field.val(attachment.url);
});
custom_uploader.open();
});
});
버튼을 클릭하면 미디어 화면이 열리고 입력 필드에 URL이 표시됩니다.
Wordpress 3.5 이후 Wordpress 업로더의 새로운 버전입니다.Wordpress 4.0에서는 사용할 수 없는 것 같습니다.
기본 튜토리얼은 http://www.webmaster-source.com/ 에서 찾을 수 있습니다.
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: false
});
//When a file is selected, grab the URL and set it as the text field's value
custom_uploader.on('select', function() {
attachment = custom_uploader.state().get('selection').first().toJSON();
$('#upload_image').val(attachment.url);
});
//Open the uploader dialog
custom_uploader.open();
});
});
<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>
//This part Should be in function.php (or similar)
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');
}
}
언급URL : https://stackoverflow.com/questions/36545961/upload-file-path-not-shown-in-field-using-wp-media-uploader
'programing' 카테고리의 다른 글
문자열을 JSON 개체로 변환 (0) | 2023.02.09 |
---|---|
전체 경로 제거, 파일 이름만 유지 (0) | 2023.02.09 |
ORA-011033 해결 방법: ORACLE 초기화 또는 셧다운 진행 중 (0) | 2023.02.09 |
iFrame의 각도, onLoad 함수 (0) | 2023.02.09 |
Spring Boot에서 각 사용자의 환율 제한을 설정하려면 어떻게 해야 합니까? (0) | 2023.02.09 |