Why does my custom plugin only function correctly once per page?

The reason your code only applies to the first table, is because you are only selecting the first input with var number = document.querySelector(‘.nutrition-table__number’); You need to loop over all your tables, and add an event listener to each. Here is an example of how this could work. The plugin pattern is from https://vanillajstoolkit.com/boilerplates/revealing-module-pattern/ /*! … Read more

Access checks with custom REST endpoints and backbone

The issue was I overrode the Backbone.sync method only in Backbone.Model. When Backbone fetches the initial data (GET) it is using the sync method in Backbone.collections. So I need to override the sync in Backbone.Collections: app.Collection = Backbone.Collection.extend({ sync: function( method, model, options ){ return Backbone.sync(method, this, jQuery.extend( options, { beforeSend: function (xhr) { xhr.setRequestHeader( … Read more

Ajax Call not Working in Plugin

You need to add the ajax callback action on your plugin file or themes functions.php like as below: add_action( ‘wp_ajax_fetch_data’, ‘fetch_data_callback’ ); add_action( ‘wp_ajax_nopriv_fetch_data’, ‘fetch_data_callback’ ); then you need to put all the featch_data.php code inside the callback function ‘fetch_data_callback’ like as below: function fetch_data_callback(){ //your function code goes here wp_die() // need to add … Read more