Last Updated on October 21, 2023 EDT by Jordan
Content Error or Suggest an Edit
Notice a grammatical error or technical inaccuracy? Let us know; we will give you credit!
Introduction
The following article provides information on the WordPress admin-ajax.php function and a list of WordPress Plugins using admin-ajax.php in a manner that results in performance issues with your WordPress site.
What is admin-ajax.php
The “admin-ajax.php” file handles asynchronous requests made by both administrators and visitors of a WordPress website. It is an endpoint for various AJAX (Asynchronous JavaScript and XML) calls made by the WordPress admin area and front-end components.
AJAX allows websites to communicate with servers in the background without reloading the entire page. It enables the creation of dynamic and interactive web applications. WordPress leverages AJAX to enhance the user experience by providing features like live updates, form submissions without page reloads, and more.
When an AJAX request is made to admin-ajax.php, WordPress examines the request to determine the appropriate action to perform. The request includes parameters such as the action name and any additional data required to process the request.
WordPress provides various hooks and actions developers can use to extend its functionality. In the case of admin-ajax.php, these hooks allow developers to register their custom AJAX actions and associate them with specific functionalities.
Source: https://kinsta.com/blog/admin-ajax-php/
Performance Issues with admin-ajax.php
Why does using admin-ajax.php cause performance issues? The following two articles go in-depth into why admin-ajax.php should be avoided completely when developing a plugin, especially for any front-end non-logged-in requests.
- WP REST API vs admin-ajax.php vs Must-Use Plugin: Handling AJAX Requests in WordPress – Delicious Brains
- Don’t Use Admin-Ajax – blog.julien-maury.dev
- https://github.com/snicco/http-routing-bundle
- Handling AJAX Requests in WordPress: WP REST API vs admin-ajax.php vs Must-Use Plugin – Delicious Brains
- 10up Engineering Best Practices
Videos
WordPress Performance Team Github Issue
The following Github issue is the first step in solving the performance issues with admin-ajax.php
Logging admin-ajax.php Requests
If you’re in a position where you’re seeing many admin-ajax.php requests in your access log and your WordPress site is slow or you want to know more about the requests. There is no native method in WordPress to investigate these requests, so I decided to make a mu-plugin that logs each request to a log file.
You simply drop the ajaxlog.php script into your wp-content/mu-plugins folder and then a log will be generated within the same folder.
Attention
It’s suggested to remove the ajaxlog.php file after you’ve gathered the data you require, and delete the log file from your server.
Potential Solutions
Short Term Unstable
As mentioned in the GitHub issue, there was a gist that has now been forked and updated to work with WordPress 6.1 that is a drop-in replacement for admin-ajax.php
I haven’t tested this, so you must use this code carefully.
Long Term Solution
The long-term solution is most likely to build a user-ajax.php handler that is bare-bones and performant. The admin-ajax.php is still required for backend-related actions that require more code than a front-end request. This is just a suggestion. Hopefully, the WordPress performance team will figure out something.
Problematic Plugins Using admin-ajax.php
Changelog
- 03/10/2023 – Added WordPress Performance team Github Issue.
- 04-17-2023 – Added additional video and embedded Youtube videos.
Last Updated on October 21, 2023 EDT by Jordan