• Hi,

    I thought of understanding better the nuts and bolts of WordPress core program during this slack period by reading the code and drawing a general flowchart for my own purpose. I have a few questions though:

    Screenshot of the program flow in question: https://prnt.sc/xohtiz

    (Q1) I was wondering how do_action( “load-{$plugin_page}” ) gets triggered. Or rather, does add_menu_page “call” load-{$plugin_page} apart from load-{$page_hook}?

    Screenshot of code: https://prntscr.com/xoj8mh

    (Q2) Is there any use case in the core that I could look at for this hook: do_action( “admin_action_{$action}” );

    Screenshot of code: https://prntscr.com/xoj7g9

    The questions above aren’t for a specific project as such. This is a “back to basics” exercise in order for me to better structure plugins etc. Equally important, it will make me better diagnose issues that may come up with sites I maintain.

    Thanks in advance.

    Cheers.
    M

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    “load-{$plugin_page}” fires when a plugin’s admin page is loaded. There are likely no callbacks added since WP loads the admin page anyway. The action is there for plugin developer use if they need to execute code before a plugin’s admin page is loaded. This way someone could influence one plugin’s behavior from another plugin, provided they know the right page ID.

    The “load-$something” format is applied in other contexts besides plugin admin pages. It all depends on what value is passed for $something. It generally fires just before some PHP file is required or included.

    Similarly, “admin_action_{$action}” likely has no added callbacks, but it’s there for developer use should they see a need. In this case it fires on any admin request that includes an “action” value in any of the request super globals. An action value is commonly passed when requesting admin-ajax.php, but in that case a more specific action hook is most commonly used.

    Thread Starter mysticalcode

    (@mysticalcode)

    Thanks, @bcworkz,

    “load-{$plugin_page}” fires when a plugin’s admin page is loaded. There are likely no callbacks added since WP loads the admin page anyway. The action is there for plugin developer use if they need to execute code before a plugin’s admin page is loaded. This way someone could influence one plugin’s behaviour from another plugin, provided they know the right page ID.

    I guess I got fixated with menu structures where a plugin’s admin pages are called. I’ll do some experimentation to understand it better. This one is particularly interesting as well:

    The “load-$something” format is applied in other contexts besides plugin admin pages. It all depends on what value is passed for $something. It generally fires just before some PHP file is required or included.

    I’ll have a play with “admin_action_{$action}” as well.

    Again, thank you. I hope you’re well.

    Cheers,
    M

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘admin.php flow’ is closed to new replies.