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.
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.
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.
With 20 years of experience in technology spanning Linux, Data Center Infrastructure, and related services and applications, Jordan consults with small, medium, and large organizations tackling technology problems and needs. With 10 years of experience in WordPress, he’s created Managing WP as a means of dumping his brain on the web.