这是我激活插件时收到的错误:
注意:wp\\u enqueue\\u脚本调用不正确。在wp\\u enqueue\\u脚本、admin\\u enqueue\\u脚本或login\\u enqueue\\u脚本挂钩之前,不应注册或排队脚本和样式。有关详细信息,请参阅WordPress中的调试。(此消息是在版本3.3中添加的。)在/目录/第3547行
这是第3547行:
trigger_error( sprintf( __( \'%1$s was called <strong>incorrectly</strong>. %2$s %3$s\' ), $function, $message, $version ) );
以下是WP\\U调试输出的if语句的其余部分:
if ( WP_DEBUG && apply_filters( \'doing_it_wrong_trigger_error\', true ) ) {
if ( function_exists( \'__\' ) ) {
$version = is_null( $version ) ? \'\' : sprintf( __( \'(This message was added in version %s.)\' ), $version );
$message .= \' \' . __( \'Please see <a href="http://codex.wordpress.org/Debugging_in_WordPress">Debugging in WordPress</a> for more information.\' );
trigger_error( sprintf( __( \'%1$s was called <strong>incorrectly</strong>. %2$s %3$s\' ), $function, $message, $version ) );
} else {
$version = is_null( $version ) ? \'\' : sprintf( \'(This message was added in version %s.)\', $version );
$message .= \' Please see <a href="http://codex.wordpress.org/Debugging_in_WordPress">Debugging in WordPress</a> for more information.\';
trigger_error( sprintf( \'%1$s was called <strong>incorrectly</strong>. %2$s %3$s\', $function, $message, $version ) );
}
}
这是我插件中唯一的wp\\u enqueue脚本实例:
wp_enqueue_script(\'csv3\', plugins_url( \'/js/demo.js\' , __FILE__ ) , array( \'jquery\' ));
这几乎是一字不差的
an example I found 完成了我需要的任务
下面是将变量传递给演示的三个函数。js文件:
function check_db(){
global $table;
global $quanid;
$hf_userid = get_current_user_id();
global $wpdb;
$wpdb->get_results( $wpdb->prepare("SELECT count( 1 ) FROM $table WHERE ItemID = \'$quanid\' AND user = \'$hf_userid\'", ARRAY_A));
}
add_action(\'wp_ajax_check_db\', \'check_db\');
function update_entry(){
global $quanid;
$price = isset($_POST[$quanid]);
$hf_userid = get_current_user_id();
global $table;
global $wpdb;
$wpdb->update( $wpdb->prepare( \'$table\',
array(
\'ItemID\' => \'$quanid\',
\'Price\' => $price,
\'user\' => $hf_userid)));
}
add_action(\'wp_ajax_update_entry\', \'update_entry\');
function post_entry(){
global $quanid;
$price = isset($_POST[$quanid]);
$hf_userid = get_current_user_id();
global $wpdb;
$wpdb->insert( $wpdb->prepare(
\'$table\',
array(
\'ItemID\' => \'$quanid\',
\'Price\' => $price,
\'user\' => $hf_userid
),
array(
\'%d\', \'%d\', \'%d\'
)
));
die();
return true;
}
add_action(\'wp_ajax_post_entry\', \'post_entry\');