Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to figure out if this is by design, a bug or a feature I should try to request. I created a plugin and added the following code:

function test_wp() {
    echo '<div style="position: absolute; border: 3px solid #dcdcdc; background: #ffffff; padding: 20px; left: 200px; top: 100px; font-size: 30px; z-index: 9999;">It worked</div>';
}
add_action('wp', 'test_wp');

I'm essentially looking for instances where the 'wp' hook does/doesn't get triggered. It doesn't load on the admin dashboard, which is obvious since it's not loading any single WP object. Whenever I click into "All Posts" it does appear to get triggered. Which is what I expected to happen.

Now, when clicking edit on any existing post, it appears 'wp' hook is not getting triggered on the post editor pages. It seems to me that the 'wp' hook should be getting called here, since it's loading a post and it's respective data directly onto this page. Yet the trigger doesn't seem to load.

Am I missing some logic behind it not loading here?

I am able to trigger the 'posts_selection' hook, which according to the Action Reference list happens right before 'wp' hook runs. That said, I have no idea what 'posts_selection' is actually doing, since the documentation for it is empty.

I am currently running WordPress 3.6.1 and had the same issue in 3.6.0. I haven't tried any versions prior to 3.6.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

No, 'wp' action hook is not triggered on post edit page.

This hook is a query-related hook, it means that it runs everytime a posts query is triggered from an url.

For this reason it's a more frontend hook (it runs on every frontend request), even if is triggered in some edit pages, more specifically, in the admin pages that do a post query: edit.php (so post, page and every cpt list) and upload.php (that show a list of media, i.e. attachment post type).

When you are on single post edit, no post query is triggered, because the current post is retrieved by WP with get_post().

'posts_selection' is another query-related hook, so it runs on every frontend request and on admin pages that run a post query (just like the 'wp' hook).

If you need and early action hook that runs on post edit page, a good idea is look at 'load-post.php' hook (one of the 'load-{$page}' hooks), that is fired only on post edit page.

In a function that runs on that hook, you can access to the post id being edited using $_GET['post'] variable.

share|improve this answer
    
Good to know. Thanks! –  David Stinemetze Sep 19 '13 at 1:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.