Globally disabling plugin that uses Ajax

Plugins that use Ajax to perform essential actions can be tricky to get set up properly while being globally disabled with Plugin Organizer. In order for this to work you need to use plugin filters to make sure the plugin is enabled on it’s Ajax endpoints. Examples of plugins that use Ajax are Ninja Forms and Woocommerce. Only running these plugins where they are needed can help speed up your site.

The first step to getting this set up is to globally disable the plugin on the Global Plugins page under Plugin Organizer in the WordPress admin. After going to the page a list of the sites plugins are presented in a list. For this example I click Ninja Forms and turn it red. Then I click save in the top right of any of the meta boxes.

Global Plugins page

Now that the plugin is globally disabled it will no longer work on any pages. There are two issues I now face. My contact page no longer displays the contact form and the admin pages are now missing the Ninja Forms admin menu. I can solve the first problem in two different ways. The edit screen for the contact page has a similar list of disabled/enabled plugins in it’s list of meta boxes. If I edit that page and enable the plugin there my contact page has the contact form.

Ninja Forms contact form

I still have a few more issues to solve though. I don’t have the Ninja Forms admin menu and when I submit the form an error is generated. To determine what the error is I open my browsers developer console. On windows you can hit the ctrl+F12 keys to open this console or you can find it in your browsers settings menu. Most modern browsers come with a developer console.

Browser console displaying ajax error

After opening my browser console I can see an error pointing me to where the Ajax URL for ninja forms is located. I copy the URL and create a plugin filter using that URL and also include the contact page URL so that I can have both together in the same spot.

After creating this plugin filter my contact form works again and Ninja Forms is only loaded on the contact page and on the admin-ajax.php endpoint. The problem I still face is that there is no admin menu for Ninja Forms. To fix this I go the contact page and edit it. I then enable Ninja Forms in the Plugin Organizer meta box and save it. Then I go back to the plugin filter and modify it. I set the permalink to my admin URL and select “Also Affect Children”.

Plugin filter for admin pages

Now that I have the plugin enabled on the contact page and a plugin filter created with the base admin URL and also affect children selected I have a working form and an admin menu for Ninja Forms. I can also use this plugin filter to manage all other plugins I’ve globally disabled and need to have enabled on my admin pages.

This example is some what simple compared to other plugins like Woocommerce which uses the WordPress REST API. That requires an Ajax endpoint on the front end of the site to have the plugin enabled as well as the admin. Using your browsers console you can find the necessary URLs to add to your plugin filter like I explained above.

Scroll to Top