Using Javascript Callback from plugin in a theme

I’m definitely missing some basics here.

I’m using this plugin wich performs ajax actions, and then fires a js function as callback.
I would like to use the callback in a custom js script of my theme.

Callback function is already defined (but empty) at the beginning of the main plugin js, and then fired as callback of an $.ajax post that puts values in its variables.

This is a simplified version of the plugin js

    new Favorites;

// Callback Function for use in themes
function favorites_after_button_submit(favorites, post_id, site_id, status){}

var Favorites = function()

    var plugin = this;
    var $ = jQuery;

    // Initialization
    plugin.init = function(){

            url: plugin.ajaxurl,
            type: 'post',
            datatype: 'json',
            data: {
                action : plugin.formactions.favorite,
                nonce : plugin.nonce,
                postid : post_id,
                siteid : site_id,
                status : status
            success: function(data){
                favorites_after_button_submit(data.favorites, post_id, site_id, status);

    return plugin.init();   

As you can see, function favorites_after_button_submit(){} is defined but does nothing.

At first glance, I would remove that function from there and use it in my theme. But I’m sure this is not the way to do this.

SO, how could I intercept that function that is fired as callback, make available its data from another js function and use it to perform some actions?

Read more here: Using Javascript Callback from plugin in a theme

Leave a Reply

Your email address will not be published. Required fields are marked *