[wp-hackers] $postnow?

Mike Schinkel mikeschinkel at newclarity.net
Wed Sep 22 07:26:26 UTC 2010


On Sep 22, 2010, at 2:46 AM, Andrew Nacin wrote:
> The $id global or $post->ID or $post_id will all get you what you need.
> Instead of a custom function (with no guarantee we won't break it in the
> future), I think the problem is that you're relying on a hook that is too
> early for what you want. admin_init runs really early on a typical admin
> page. Even load-$pagenow runs too early for a lot of stuff. And even if they
> weren't too early, they're too generalized and they would require you to
> make all sorts of duplicative checks that the admin later makes for you.
> (There's a lot of branching in post.php for example.)
> 
> There are metabox-specific hooks after the add_meta_box() calls and before
> they are generated, which would be the perfect time and context to remove,
> add, or adjust meta boxes.

Can you suggest some specific hooks?  In tracing the code via a debugger I don't find any obviously appropriate candidates.

And aren't post types supposed to be complete after init?  What about other plugins who might decide to inspect the post types and take action in a load-{$pagenow} hook or an $admin_action{$action} hook?

BTW, I didn't just run into this need, this is about the 10th time I've had to worry about it so I finally decided to email about it.  And I'm not trying to solve this use-case (I've already got something that works), I'm trying to figure out a reliable method to determine post_id in the future.  The response "you're doing it too early" simply doesn't work for cases where I must know post_id earlier, i.e. in the admin_menu hook, for example. (The reality is I also need to get access to $typenow before it's assigned, too.) 

-Mike




More information about the wp-hackers mailing list