Saturday, August 6, 2022
HomeWordPress Developmentplugins - WordPress Hooks : The place to put callbacks that repetitively...

plugins – WordPress Hooks : The place to put callbacks that repetitively yield the identical impact?


To provide the context first: As an instance you create a customized plugin by your self. That plugin has for instance:

A) 30 totally different endpoints / REST calls,

B) provides 15 totally different admin pages to the wp-admin,

C) enqueues a script particular to each single admin web page,

and so forth.

To allow the complete performance of this, I do:

A) 30 totally different calls to register_rest_route, and hook them to the rest_api_init hook.

B) Load the 15 totally different admin pages, and hook them to the admin_menu hook.

C) Enqueue all the page-specific scripts through swap($page_slug) and hook that to the admin_enqueue_scripts hook.

Every thing of this works completely, which is why will not element the code any additional. As a result of my query does not likely concern code, however the logic of wordpress and hooks underneath the hood: Presently, the code for A) – C) is written in the principle plugin file of my customized plugin, and I’ve usually discovered to do it that manner. Which means, AFAIK, that the complete hookings run on each single web page load.

I now puzzled: Could not you for instance hook your 30 endpoints of your REST API just for instance through the activation hook of the plugin or related? And related for the admin pages?

Simply feels odd to me that you just’re loading the identical code, whose output is theoretically a static registration, time and again in manufacturing techniques, and this on each single web page load.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments