• Hi there,

    Thanks for all your effort in putting together this plugin.

    I found an issue and thought I should report it. Although this may not be an actual problem for most users, when using this plugin on a development server with xdebug enabled, a notice is thrown by WordPress. The notice is the following:

    Notice: wp_register_style was called <strong>incorrectly</strong>. Scripts and styles should not be registered or enqueued until the <code>wp_enqueue_scripts</code>, <code>admin_enqueue_scripts</code>, or <code>login_enqueue_scripts</code> hooks. Please see <a href="https://codex.www.ads-software.com/Debugging_in_WordPress">Debugging in WordPress</a> for more information. (This message was added in version 3.3.0.)

    The notice comes from lines 9 and 10 in the wcff-options class. You’re actually registering and enqueuing the style without putting it in one of the hooks mentioned in the notice above, so that’s where the problem is.

    • This topic was modified 8 years, 4 months ago by psymeons.
Viewing 2 replies - 1 through 2 (of 2 total)
  • You can fix this by editing wcff-options.php

    Change lines 9 and 10

    wp_register_style( 'wcff-style', plugin_dir_url( __FILE__ ) . '../assets/css/wcff.css' );
    wp_enqueue_style('wcff-style');

    to

    function wccpf_register_styles() {
    	wp_register_style( 'wcff-style', plugin_dir_url( __FILE__ ) . '../assets/css/wcff.css' );
    	wp_enqueue_style('wcff-style');
    }
    
    add_action( 'wp_enqueue_scripts', 'wccpf_register_styles' );

    Thank you. I read about the problem more broadly on Stack Overflow about the potential issues of declaring those outside of functions.

    This is the second thread about this I’ve come across in as many pages and the first with a solution (and it works). Since it only seems to come up as a notice in debug mode, many people might not know about it and it perhaps could be baked into the next update?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘wp_register_style & wp_enqueue_style called incorrectly’ is closed to new replies.