I’ve been busy thinking about a problem, and so far I didn’t find a solution to it.
The abstract scenario
On admin page A, I would like to print the value of a (global) variable—in the context of admin page B, though.
The concrete scenario
On a custom user-options page, I would like to list all metaboxes registered for each post type.
Both plugins and the theme can add/remove metaboxes with respect to the current page context ($pagenow
). Thus, the $wp_meta_boxes
global is set up in that context.
So far, I’ve read into virtually any hook, read a lot on AJAX (the right and the wrong ways), and tried out numerous different approaches I came up with.
Unfortunatly, without luck.
The question
Is it possible to retrieve the value of $wp_meta_boxes
on admin page post-new.php?post_type=my_super_duper_post_type
, for instance, from another admin page?
If so, how would I go about that?
Can this be done via AJAX?
Or can I trick the plugins/theme into thinking that the current page is post-new.php?post_type=my_super_duper_post_type
, for instance, while we’re actually on my options page?
Ok, this could be achieved this way, probably.
Now, you send a request from your plugin page to
post-new.php?post_type=my_super_duper_post_type&mgv=1
through ajax, and use the returned json response of wp_meta_boxeses variables.Thanks to @Shazzad and @G.M., I found the right track.
Here is a short outline of what I did:
The JavaScript/AJAX action
Enqueue the JavaScript file for my custom user options page
Set up the right hook to handle the AJAX request
Now I am able to get all actually registered meta boxes for whatever post type I’d like—while being on some other admin page.