0

Can someone help me fix this error?

PHP Notice: wp_enqueue_script was called incorrectly. Scripts and styles should not be registered or enqueued until the wp_enqueue_scripts, admin_enqueue_scripts, or login_enqueue_scripts hooks. Please see Debugging in WordPress for more information. (This message was added in version 3.3.0.) in /nas/content/live/greattaste/wp-includes/functions.php on line 4986

code:

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 );

    }
}
4
  • How are you calling wp_auth_check_load? Is it attached to a hook? such as add_action( 'init', 'wp_auth_check_load' ); ? Commented Jan 15, 2020 at 20:53
  • It's s big function that contains all these code: function wp_auth_check_load() {.... wp_register_style(..); wp_register_script() }
    – Luis
    Commented Jan 15, 2020 at 21:57
  • @Luis but how are you using that function? In your code how do you call wp_auth_check_load Commented Jan 15, 2020 at 21:59
  • 1
    wp_auth_check_load is a function in WP core, are you making edits and modifications to the WP core files?! This is very dangerous, bad practice, and should never be done. All your changes will be lost when you update WordPress. If you want to make changes to WP behaviour or add new functionality, you should use plugins and hooks/filters like everybody else
    – Tom J Nowell
    Commented Jan 15, 2020 at 22:38

1 Answer 1

-1

Before you can use, those two lines :

wp_enqueue_style( 'wp-auth-check' );
wp_enqueue_script( 'wp-auth-check' );

you should register those assets, inside wp_enqueue_scripts or admin_enqueue_scripts, like the following :

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');
2
  • This still won't work – they need to register and enqueue the scripts after wp_enqueue_scripts or admin_enqueue_scripts. The wp_auth_check_load function is being called before these hooks (hence the error) :) Commented Jan 15, 2020 at 21:37
  • 1
    This is not the answer, the problem is not what he did, but when/where he did it, like Andy said
    – Tom J Nowell
    Commented Jan 15, 2020 at 22:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.