• I am converting a rating and aggregator plugin I wrote a couple of years ago (that works correctly) to a must-use plugin for a multisite network.

    Problem is, although the ajax routine works just fine, when it is supposed to register the results it is not calling the callback function specified in the wp_ajax actions.

    In the constructor of my plugin’s code I have:

    add_action( 'wp_ajax_ipubstarajax', array( $this,'star_ratings' ) );
    add_action( 'wp_ajax_nopriv_ipubstarajax', array( $this,'star_ratings' ) );

    Then later in the code scripts and css are enqued and the js is localized:

    public function register_plugin_scripts() {
    
        wp_register_script( 'my_eg_starscript', plugins_url( 'fcn-stars/js/eg-star-rating.js', __FILE__ ), array('jquery'));
        wp_register_script( 'eg-ajax-script', plugins_url( 'fcn-stars/js/eg-star-user.js', __FILE__ ), array('jquery'));
    	 wp_enqueue_script( 'jquery' );
    	 wp_enqueue_script( 'my_eg_starscript' );
    	 wp_enqueue_script( 'eg-ajax-script' );
        wp_localize_script( 'eg-ajax-script', 'myAjax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' )));        
    
    	} // end register_plugin_scripts

    In the eg-star-user.js file is the function called by the plugin:

    function sendRatingsToServer(){	
    
       var str = $('form').serialize();
             	$.ajax({
    	        type: "POST",
    	        url: "/wp-admin/admin-ajax.php",
    	        data: 'action=ipubstarajax&'+str,
    	        success: function(response) {
    ///////////////////////  ETC

    Am I not calling the URL and ACTION properly for a plugin in the mu-plugins folder??

    Any help is appreciated.

    Thanks,

    Ed

The topic ‘Ajax in mu-plugins’ is closed to new replies.