1

I'm trying to implement the code to add a custom post status from my plugin, exactly as given in this tutorial: http://jamescollings.co.uk/blog/wordpress-create-custom-post-status/

Now, it isn't working and after some investigation it seems the admin_footer-post.php action isn't firing. The codex page for this action hook states . . .

admin_footer-(hookname) is triggered at the end of the section of a specific admin page, after admin_footer and admin_print_footer_scripts actions.

The hookname part you can get using the variable $GLOBALS['hook_suffix']

. . . but that variable is empty. I've tried directly accessing $hook_suffix with no luck, and printing out the entire $GLOBALS array shows no hook_suffix anywhere.

I am very confused.

At first I thought maybe it was written for an older version of WP but there's a comment on the blog post from just 3 days ago from someone who seems to have achieved success. I've tried turning off themes and all other plugins, and just have absolutely no idea where to go from here.

What could make the $GLOBALS['hook_suffix'] variable, apparently a common enough thing in WP development, simply cease to exist on my site?

  • without seeing your code in context it's hard to say where you've gone wrong. if you look in wp-admin/admin.php, you can see where $hook_suffix is set in the admin bootstrap process. – Milo Jul 1 '14 at 20:38
1

I thing you are missing the context. $GLOBALS['hook_suffix'] is available on any action fired after admin_init.

Now, if you tried something like add_action( 'admin_footer-'. $GLOBALS['hook_suffix'], 'myfunction' ) outside of any function, you are not going to get anything.

But if you do it - add_action('admin_menu', 'do_hook_to_footer') and put the earlier hook within the do_hook_to_footer function, it will work.

Or, better you try like this -

<?php
/** Plugin Name: WPSE(#152404) $hook_suffix Test Plugin */
add_action( 'admin_menu', 'hook_that' );
function hook_that()
{
    add_action( "admin_footer-{$GLOBALS['hook_suffix']}", 'test_that' );
}
function test_that()
{
    echo "<h1>I AM HOOKED TO <code>admin_footer-{$GLOBALS['hook_suffix']}</code></h1>";
}
  • seems like we edited the same example to your answer at the same time. If you would like to "role back", simply click on the timestamp above my avatar and make it undone. – kaiser Jul 1 '14 at 20:48
  • 1
    Your example is much cleaner and includes the example i was going to add. It should stay :) – Shazzad Jul 1 '14 at 20:51
  • Hmm, thanks. I tried just replacing my plugin code with the above exactly. Resulted in no message displayed and this notice: "Notice: Undefined index: hook_suffix in blah blah..." – Shellbot Jul 2 '14 at 8:06
0

I was getting the same error when I move my Wp List table to the frontend Notice: Undefined index: hook_suffix in ..../wp-admin/includes/class-wp-screen.php on line 213

I fixed it by replacing

$id = $GLOBALS['hook_suffix'];

with

$id = isset($GLOBALS['hook_suffix']) ? $GLOBALS['hook_suffix'] : "";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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