[Plugin: JQuery Mega Menu Widget] Patch fix for "Notice: wp_enqueue_script was called incorrect
-
If, as I do, you have PHP set to show all errors during development, you get the following error for Mega Menu plugin.
Notice: wp_enqueue_script was called incorrectly. Scripts and styles should not be registered or enqueued until the wp_enqueue_scripts.
It’s an easy fix, and one you might want to add to the code.
Change the plugin intialization from:
// Initialize the plugin. $dcjqmegamenu = new dc_jqmegamenu();
to
$dcjqmegamenu = new dc_jqmegamenu; add_action('init', array($dcjqmegamenu, 'dc_jqmegamenu2'));
Rename the first function in
dc_jqmegamenu
todc_jqmegamenu2
(because you want to stop the class auto-initializing, and wait for it to be initialized at the right time by the WordPress init hook.In reality, the way the current code calls it does not do any harm, apart from spitting out kind of annoying error warnings on every page, but perhaps still worth fixing?
Here’s the content of a patch file I created:
*** dcwp_jquery_mega_menu.orig.php 2012-08-11 14:22:06.272810507 -0400 --- dcwp_jquery_mega_menu.php 2012-08-11 14:18:28.772809667 -0400 *************** *** 13,19 **** class dc_jqmegamenu { ! function dc_jqmegamenu(){ global $registered_skins; if(!is_admin()){ --- 13,19 ---- class dc_jqmegamenu { ! function dc_jqmegamenu2(){ global $registered_skins; if(!is_admin()){ *************** *** 49,55 **** include_once('dcwp_jquery_mega_menu_widget.php'); // Initialize the plugin. ! $dcjqmegamenu = new dc_jqmegamenu(); // Register the widget add_action('widgets_init', create_function('', 'return register_widget("dc_jqmegamenu_widget");')); --- 49,57 ---- include_once('dcwp_jquery_mega_menu_widget.php'); // Initialize the plugin. ! ! $dcjqmegamenu = new dc_jqmegamenu; ! add_action('init', array($dcjqmegamenu, 'dc_jqmegamenu2')); // Register the widget add_action('widgets_init', create_function('', 'return register_widget("dc_jqmegamenu_widget");'));
- The topic ‘[Plugin: JQuery Mega Menu Widget] Patch fix for "Notice: wp_enqueue_script was called incorrect’ is closed to new replies.