PHP注意:WP_ENQUEUE_SCRIPT调用不正确。不应注册脚本和样式

时间:2020-01-15 作者:Luis

有人能帮我纠正这个错误吗?

PHP注意:调用了wp\\u enqueue\\u脚本incorrectly. 在wp_enqueue_scripts, admin_enqueue_scripts, 或login_enqueue_scripts 挂钩。请参见Debugging in WordPress 了解更多信息。(此消息是在版本3.3.0中添加的。)in/nas/content/live/greattaste/wp包含/功能。php在线4986

代码:

function wp_auth_check_load() {
    if ( ! is_admin() && ! is_user_logged_in() ) {
        return;
    }

    if ( defined( \'IFRAME_REQUEST\' ) ) {
        return;
    }

    $screen = get_current_screen();
    $hidden = array( \'update\', \'update-network\', \'update-core\', \'update-core-network\', \'upgrade\', \'upgrade-network\', \'network\' );
    $show   = ! in_array( $screen->id, $hidden );

    /**
     * Filters whether to load the authentication check.
     *
     * Passing a falsey value to the filter will effectively short-circuit
     * loading the authentication check.
     *
     * @since 3.6.0
     *
     * @param bool      $show   Whether to load the authentication check.
     * @param WP_Screen $screen The current screen object.
     */
    if ( apply_filters( \'wp_auth_check_load\', $show, $screen ) ) {
        wp_enqueue_style( \'wp-auth-check\' );
        wp_enqueue_script( \'wp-auth-check\' );

        add_action( \'admin_print_footer_scripts\', \'wp_auth_check_html\', 5 );
        add_action( \'wp_print_footer_scripts\', \'wp_auth_check_html\', 5 );

    }
}

1 个回复
SO网友:Amine Faiz

在使用之前,请先使用以下两行:

wp_enqueue_style( \'wp-auth-check\' );
wp_enqueue_script( \'wp-auth-check\' );
您应该在wp\\u enqueue\\u脚本或admin\\u enqueue\\u脚本中注册这些资产,如下所示:

function my_assets() {
wp_register_style( \'wp-auth-check\', \'path/to/style\', $deps = array, $ver = false, $media = \'all\' )
 wp_register_script( \'wp-auth-check\', \'path/to/your-script\', $deps = array, $ver = false, $in_footer = false )
}

add_action(\'wp_enqueue_scripts\', \'my_assets\');
or 
add_action(\'admin_enqueue_scripts\', \'my_assets\');