I've been making a find-a-dealer type plugin in WordPress and I finally got it all done, everything works on my local and dev server.
I push it up to production and upon activation, I get these errors/warnings:
Notice: wp_register_style 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 /home/sites/my_site/public_html/wp-includes/functions.php on line 4773
Notice: wp_register_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 /home/sites/my_site/public_html/wp-includes/functions.php on line 4773
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 /home/sites/my_site/public_html/wp-includes/functions.php on line 4773
Notice: wp_enqueue_style 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 /home/sites/my_site/public_html/wp-includes/functions.php on line 4773
Notice: Undefined offset: 0 in /home/sites/my_site/public_html/wp-includes/plugin.php on line 914
Notice: Undefined offset: 0 in /home/sites/my_site/public_html/wp-includes/plugin.php on line 933
Warning: call_user_func_array() expects parameter 1 to be a valid callback, no array or string given in /home/sites/my_site/public_html/wp-includes/class-wp-hook.php on line 286
Looking at these errors, I immediately went to my plugin's code for handling registering css/js:
main-plugin-file.php (skimmed down)
function fad_css_js()
{
# add css
wp_register_style('front_css', plugins_url('skin/css/front.css', __FILE__));
# register css
wp_enqueue_style('front_css');
}
# actions
add_action('init', 'fad_css_js');
admin-plugin-file.php (skimmed down)
function adn_css_js()
{
# css
wp_register_style('adn-css', plugins_url('skin/css/admin.css', __FILE__));
wp_enqueue_style('adn-css');
# js
wp_register_script('adn-js', plugins_url('skin/js/admin.js', __FILE__), array(), false, true);
wp_enqueue_script('adn-js');
}
add_action('admin_enqueue_scripts', adn_css_js());
Like I said, this worked on my localhost and development server. Going to production seems to bring up all these errors, it (the code) doesn't look to be in the wrong, I register before any enqueue, so I'm really not sure.
Going to the debugging page on WP site wasn't helpful..
How do I debug/resolve this?
Edit
Can confirm that a different plugin with the css/js code like this:
function my_other_js_css()
{
# add css
wp_register_style('my_other__css', plugins_url('css/main.css', __FILE__));
wp_register_style('my_other_media_css', plugins_url('css/media.css', __FILE__));
# add js
wp_register_script('my_other_js', plugins_url('js/main.js', __FILE__), array(), false, true);
# register css
wp_enqueue_style('my_other_css');
wp_enqueue_style('my_other_media_css');
# register js
wp_enqueue_script('my_other_js');
}
add_action('plugins_loaded', array('the_plugin', 'get_instance'));
add_action('init', 'my_other_js_css');
init
hook or others. There are only a handful of valid hooks to register and enqueue on, and they're all mentioned in the warning