I'm trying to implement the code to add a custom post status from my plugin, exactly as given in this tutorial: /
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
andadmin_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?
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
andadmin_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?
Share Improve this question asked Jul 1, 2014 at 19:49 ShellbotShellbot 5602 gold badges5 silver badges12 bronze badges 1 |2 Answers
Reset to default 1I 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>";
}
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'] : "";
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745100108a4611221.html
wp-admin/admin.php
, you can see where$hook_suffix
is set in the admin bootstrap process. – Milo Commented Jul 1, 2014 at 20:38