Php 在WordPress小部件中集成图像上传框
我正在开发一个小的WordPress小部件,并尝试将其设置为用户可以上传图像的位置。到目前为止,正在加载必要的脚本,但当我单击“媒体库图像”按钮时,图像上载程序不会弹出 这是我的javascript文件:Php 在WordPress小部件中集成图像上传框,php,jquery,wordpress,Php,Jquery,Wordpress,我正在开发一个小的WordPress小部件,并尝试将其设置为用户可以上传图像的位置。到目前为止,正在加载必要的脚本,但当我单击“媒体库图像”按钮时,图像上载程序不会弹出 这是我的javascript文件: jQuery(document).ready(function($) { var formfield = null; $('#upload_image_button').click(function() { $('html').addClass('Image'); form
jQuery(document).ready(function($) {
var formfield = null;
$('#upload_image_button').click(function() {
$('html').addClass('Image');
formfield = $('#wp-ss-image').attr('name');
tb_show('', 'media-upload.php?type=image&TB_iframe=true');
return false;
});
// user inserts file into post. only run custom if user started process using the above process
// window.send_to_editor(html) is how wp would normally handle the received data
window.original_send_to_editor = window.send_to_editor;
window.send_to_editor = function(html){
var fileurl;
if (formfield != null) {
fileurl = $('img',html).attr('src');
$('#wp-ss-image').val(fileurl);
tb_remove();
$('html').removeClass('Image');
formfield = null;
} else {
window.original_send_to_editor(html);
}
};
});
以下是我调用脚本的函数:
add_action('admin_print_scripts-widgets.php', 'wp_ss_image_admin_scripts');
function wp_ss_image_admin_scripts() {
wp_enqueue_script( 'wp-ss-image-upload', plugins_url( '/WP-Simple-Social/wp-simple-social-image.js' ), array( 'jquery','media-upload','thickbox' ) );
}
add_action('admin_print_styles-widgets.php', 'wp_ss_admin_styles');
function wp_ss_admin_styles() {
wp_enqueue_style( 'thickbox' );
}
下面是显示输入框和图像上载按钮的html:
<p>Upload Photo: <input id="wp-ss-image" class="widefat" type="text" size="75" name="<?php echo $this->get_field_name( 'image' ); ?>" value="<?php echo esc_url( $image ); ?>" />
<input id="upload_image_button" type="button" value="Media Library Image" class="button-secondary" />
上传照片:我发现最好的方法是使用live()方法,即使它不赞成on()盈利
工作
没用
如果有人能解释一下,我将不胜感激
jQuery(document).ready(function($) {
$("#testage").live("click", function() {
alert("CLICK!");
});
});
jQuery(document).ready(function($) {
$("#testage").on("click", function() {
alert("CLICK!");
});
});