• wordpress plugin Category Ajax Chain Selects shows 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.) in /home/bricpro/public_html/wp-includes/functions.php on line 3049 , i added my site last year , now my site gets down because of some plugin issue , Now i had debugged my site i am receiving this error , i am not suur why this is happening for this plugin ,once i deactivate this plugin there error got removed , how can i fix this without loss my old data and functnalities.

    https://wordpress.org/plugins/category-ajax-chain-selects/

Viewing 2 replies - 1 through 2 (of 2 total)
  • In chainselects.php file, change lines 220 – 227 from this:

    wp_enqueue_script( 'my-ajax-handle', plugin_dir_url( __FILE__ ) . 'chainselects.js', array( 'jquery' ) );
    wp_localize_script( 'my-ajax-handle', 'the_ajax_script', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
    
    add_action( 'wp_ajax_the_ajax_hook', 'chainselect_updatecats' );
    add_action( 'wp_ajax_nopriv_the_ajax_hook', 'chainselect_updatecats' );
    
    wp_register_style('chainselects_css', plugin_dir_url( __FILE__ ) . 'chainselects.css');
    wp_enqueue_style( 'chainselects_css');

    To this:

    function enqueue_scripts_properly() {
    			wp_enqueue_script( 'my-ajax-handle', plugin_dir_url( __FILE__ ) . 'chainselects.js', array( 'jquery' ) );
    			wp_localize_script( 'my-ajax-handle', 'the_ajax_script', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
    
    			add_action( 'wp_ajax_the_ajax_hook', 'chainselect_updatecats' );
    			add_action( 'wp_ajax_nopriv_the_ajax_hook', 'chainselect_updatecats' );
    
    			wp_register_style('chainselects_css', plugin_dir_url( __FILE__ ) . 'chainselects.css');
    			wp_enqueue_style( 'chainselects_css');
    			}
    	add_action('wp_enqueue_scripts', 'enqueue_scripts_properly');

    Oops — this is the proper code:

    function enqueue_scripts_properly() {
    			wp_enqueue_script( 'my-ajax-handle', plugin_dir_url( __FILE__ ) . 'chainselects.js', array( 'jquery' ) );
    			wp_localize_script( 'my-ajax-handle', 'the_ajax_script', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
    
    			wp_register_style('chainselects_css', plugin_dir_url( __FILE__ ) . 'chainselects.css');
    			wp_enqueue_style( 'chainselects_css');
    			}
    	add_action('wp_enqueue_scripts', 'enqueue_scripts_properly');
    	add_action( 'wp_ajax_the_ajax_hook', 'chainselect_updatecats' );
    	add_action( 'wp_ajax_nopriv_the_ajax_hook', 'chainselect_updatecats' );
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Shows error on wp_enqueue_script in Category Ajax Chain Selects’ is closed to new replies.