Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/455.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将脚本加载到管理员wordpress_Javascript_Php_Wordpress_Meta Boxes - Fatal编程技术网

Javascript 将脚本加载到管理员wordpress

Javascript 将脚本加载到管理员wordpress,javascript,php,wordpress,meta-boxes,Javascript,Php,Wordpress,Meta Boxes,我对如何将脚本加载到wp admin感到困惑。我创建了一个metabox上传图像,并将wordpress thickbox上传程序附加到其中。 要显示wordpress uploader thickbox,我使用jquery: $(function() { var formfield = null; $('#upload_image_button').click(function() { $('html').addClass('Image'); formfield = $

我对如何将脚本加载到wp admin感到困惑。我创建了一个metabox上传图像,并将wordpress thickbox上传程序附加到其中。 要显示wordpress uploader thickbox,我使用jquery:

$(function() {

var formfield = null;

$('#upload_image_button').click(function() {

    $('html').addClass('Image');

    formfield = $(this).prev('input').attr('name');  
    formfield_id = $(this).prev('input').attr('id'); 

    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 normally handles 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');

        $( "#" + formfield_id ).val(fileurl);

        tb_remove();

        $('html').removeClass('Image');
        formfield = null;
    } else {
        window.original_send_to_editor(html);
    }
};
});
我的代谢箱

function upload_image(){
 echo '<input id="upload_image" type="text" size="36" name="_logo_agence" value="'.$logo_agence.'" />';
        echo '<input id="upload_image_button" type="button" value=" Logo" />';
        echo '<div>'.$image_logo.'</div>';

}
问题是这个脚本没有附加到wordpress admin,当我使用element inspector时,任何地方都没有metabox.js,所以当我单击metabox按钮加载脚本时,它没有加载thickbox

有人有主意吗

谢谢你的帮助。

  • 不需要两个
    管理队列脚本

  • 脚本
    media upload
    thickbox
    作为您的
    my upload
    的依赖项添加,因此无需将它们排队

  • 这是
    wp\u排队\u脚本('my-upload')
    ,而不是
    wp\u排队\u媒体

  • 在WordPress中使用以下jQuery样式:

    jQuery(document).ready(function($){ /*my-code*/ });
    
工作队列:

add_action('admin_enqueue_scripts', 'my_admin_scripts');

function my_admin_scripts($hook) 
{
    # Not our screen, bail out
    if( 'post.php' !== $hook )
        return;

    # Not our post type, bail out
    global $typenow;
    if( 'post' !== $typenow )
        return;

    wp_register_script( 
        'my-upload', 
        get_stylesheet_directory_uri() . '/js/script.js', 
        array( 'jquery', 'media-upload', 'thickbox' )
    );
    wp_enqueue_script('my-upload');
    wp_enqueue_style('thickbox');
}
add_action('admin_enqueue_scripts', 'my_admin_scripts');

function my_admin_scripts($hook) 
{
    # Not our screen, bail out
    if( 'post.php' !== $hook )
        return;

    # Not our post type, bail out
    global $typenow;
    if( 'post' !== $typenow )
        return;

    wp_register_script( 
        'my-upload', 
        get_stylesheet_directory_uri() . '/js/script.js', 
        array( 'jquery', 'media-upload', 'thickbox' )
    );
    wp_enqueue_script('my-upload');
    wp_enqueue_style('thickbox');
}