admin管理员组文章数量:1287973
This is my code:
class App
{
public function run()
{
add_action('admin_menu', [$this, 'menu']);
add_action('admin_notices', [$this, 'pip']);
}
public function menu()
{
echo 0;
add_submenu_page(
'tools.php',
__('Tools', 'name-plugin'),
__('Name', 'name-plugin'),
'manage_options',
'name-plugin',
[$this, 'show']
);
}
public function show()
{
echo 1;
}
public function pip() {
echo 2;
}
}
This code printed 021
But I want to print 012
Note: I want to put all add_action
in run
method
I used priority too, but it's not work:
add_action('admin_menu', [$this, 'menu'], 1);
add_action('admin_notices', [$this, 'pip'], 2);
If I put admin_notices
in show
method, this code works fine.
But I don't want put it in show
method
This is my code:
class App
{
public function run()
{
add_action('admin_menu', [$this, 'menu']);
add_action('admin_notices', [$this, 'pip']);
}
public function menu()
{
echo 0;
add_submenu_page(
'tools.php',
__('Tools', 'name-plugin'),
__('Name', 'name-plugin'),
'manage_options',
'name-plugin',
[$this, 'show']
);
}
public function show()
{
echo 1;
}
public function pip() {
echo 2;
}
}
This code printed 021
But I want to print 012
Note: I want to put all add_action
in run
method
I used priority too, but it's not work:
add_action('admin_menu', [$this, 'menu'], 1);
add_action('admin_notices', [$this, 'pip'], 2);
If I put admin_notices
in show
method, this code works fine.
But I don't want put it in show
method
1 Answer
Reset to default 0Those are not admin notices. It's not enough to echo
text on the admin_notices
hook, it needs to be wrapped in specific HTML.
Here is an example taken from the official WP doc for admin_notices
:
function sample_admin_notice__success() {
?>
<div class="notice notice-success is-dismissible">
<p><?php _e( 'Done!', 'sample-text-domain' ); ?></p>
</div>
<?php
}
add_action( 'admin_notices', 'sample_admin_notice__success' );
If you need to add notices after the hook has fired, use the same HTML structure and WordPress will move it using javascript to the correct place
本文标签: pluginsadminnotices show after load completed
版权声明:本文标题:plugins - admin_notices show after load completed 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741323789a2372357.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
021
. I don't know why you'd expect anything different. Admin notices display at the top of the page. That's normal. – Jacob Peattie Commented Sep 13, 2021 at 8:45show
method. But admin_notices run beforeshow
method and my error not showing – user212402 Commented Sep 13, 2021 at 8:52show()
, the code that handles submission of that form should be in a separate function that's hooked earlier. Then it can pass any errors to the notices hook. – Jacob Peattie Commented Sep 13, 2021 at 8:54admin_notices
hook, they have specific HTML that's needed – Tom J Nowell ♦ Commented Sep 13, 2021 at 9:36