WordPress / WordPress/Documentation-Issue-Tracker

[DevHub] Conveying the importance of wp_doing_ajax during init and admin_init hooks

Open
#53 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

[Status] Review APIs developer documentation (DevHub)
Dominant language
Shell
Stars
109
Forks
73
PR merge metrics
No merged PRs in 30d

Description

WordPress speed complaints have long been a thorn in our side. We have been analyzing some complex WordPress sites we host and one aspect which weighs heavily on the php consumption is the use of init and admin_init hooks in plugins. The reason this appears to compound php loads is due to plugins which commonly use AJAX. This often leads to a large volume of init/admin_init calls running repeatedly and rapidly. The WordPress "heartbeat" is a common culprit but many Page Builders are just as likely to lead to the same issue.

The reason repeated calls to admin_init and init hooks lead to PHP spikes is often due to them being incredibly popular hooks to initiate countless plugins in varying degrees. This can especially become a serious bottleneck when a plugin is kicking off a call to an outside API where some sort of remote call such as a curl is being waited on.

We combed through your documentation but could not seem to locate any recommendations to use the function wp_doing_ajax to help alleviate this issue. Obviously every plugin developer would need to stop and consider the implications for using wp_doing_ajax, but I would imagine 90%+ of the plugin use cases could wrap their init/admin_init scripts with if( !wp_doing_ajax ) and see speed improvements.

I hope this perspective is helpful to you and you'll recognize the importance of spreading the word to the WordPress scene about taking advantage of it for the greater good.

Thanks for all you do!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the existing WordPress documentation for the init and admin_init hooks, AJAX requests, and wp_doing_ajax. Compare that coverage with the issue's recommendation about avoiding unnecessary plugin work during AJAX calls; the work is done when the guidance is added in the appropriate documentation location and clearly explains the performance trade-offs.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, wordpress
Domain
documentation
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.