All of the examples I’ve seen for add_settings_section
& add_settings_field
have them being called on the admin_init
action. This means that they’re being called when loading every single admin page.
However, my understanding is that they’re only used when rendering the options page on which they’re displayed. Is there any reason no to put all calls to add_settings_section
& add_settings_field
in the callback function given to add_menu_page
?
I’m wondering because I’ve got a plugin where the selection of fields to display is determined by a call to an external API. I certainly don’t want to have to do this on every admin page load. Even if I cache the result of the API call in a transient that’s going to expire every so often.