1

我在我的插件中使用 wordpress mediaupload 功能。

Error: jQuery is not defined
Source File: http://localhost/my_wp/wp-admin/load-scripts.php?c=0&load=utils,thickbox,media-upload&ver=4ec4a484079ac4122099967c5457437d
Line: 19

这是我的插件加载时的错误消息。当我看到代码时,媒体上传脚本首先加载,然后 jquery 正在加载。这是我的代码

add_action( 'admin_enqueue_scripts', 'wpvote_include_files' );
function wpvote_include_files() {
    wp_deregister_script( 'jquery' );
    wp_register_script( 'jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js' );
    wp_enqueue_script( 'jquery' );

 wp_enqueue_script('media-upload');
    wp_enqueue_script('thickbox');
    wp_register_script('my-upload', WPVOTE_PLUGIN_URL.'wpmediaupload_scripts.js', array('jquery','media-upload','thickbox'));
    wp_enqueue_script('my-upload');

}

这是我的页面源代码

<script type='text/javascript' src='http://localhost/my_wp/wp-admin/load-scripts.php?c=0&amp;load=utils,thickbox,media-upload&amp;ver=4ec4a484079ac4122099967c5457437d'></script>
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js?ver=3.3.2'></script>
4

1 回答 1

0

A posible problem is that you are trying to enqueue a script in the admin area. Why don't you try using the admin_enqueue_scripts method?

add_action( 'admin_enqueue_scripts', 'function_name' );

Reference: http://codex.wordpress.org/Plugin_API/Action_Reference/admin_enqueue_scripts

于 2012-10-02T23:09:21.467 回答