[英]Wordpress;how to remove_action from a Plugin to hide admin_notices created by another Plugin
I am a beginner to WP hooks, (actions and filters) I was able to create a Plugin that shows all 4 admin notices in WP dashboard我是 WP 钩子的初学者,(操作和过滤器)我能够创建一个插件,在 WP 仪表板中显示所有 4 个管理员通知
here the Plugin-one code这里是插件一代码
/* Start admin notices on */
function display_admin_notice() {
?>
<div class ="notice notice-success is-dismissible"><p>Congratulatios! it seems you have a nice success notice</p></div>
<div class = "notice notice-error"><p>What a nice error message</p> </div>
<div class = "notice notice-warning"><p>WARNING!!! site about to blow up in pieces</p></div>
<div class = "notice notice-info is-dismissible"><p>INFO - you must renew license</p></div>
<?php
}
add_action( 'admin_notices', 'display_admin_notice' );
/* Stop admin notices on */
it works perfectly.它完美地工作。
Now I have another plugin that hides ALL notifications现在我有另一个隐藏所有通知的插件
/* Start Block ALL admin notices */
add_action('admin_enqueue_scripts', 'block_dismissable_admin_notices');
add_action('login_enqueue_scripts', 'block_dismissable_admin_notices');
function block_dismissable_admin_notices() {
echo '<style>.wp-core-ui .notice{ display: none !important; }</style>';
}
/* Stop Block ALL admin notices */
it works fine too它也很好用
BUT I need to REMOVE the action from the first Plugin, NOT to hide all notifications, I mean, is there a way to get the但我需要从第一个插件中删除操作,而不是隐藏所有通知,我的意思是,有没有办法获得
add_action( 'admin_notices', 'display_admin_notice'
from the first Plugin and remove_action so the Plugin hides/block ONLY the admin_notices from THAT plugin and NOT from all the Wordpress core or another plugins?从第一个插件和remove_action,所以插件只隐藏/阻止该插件的admin_notices,而不是所有Wordpress核心或其他插件?
Thanks in advance提前致谢
Instead of loading code and then unloading it (pointless) you could add an if statement to conditionally check if the action hook is needed.您可以添加一个 if 语句来有条件地检查是否需要操作挂钩,而不是加载代码然后卸载它(毫无意义)。
eg.例如。
$noticesOn = true; // Conditional setting could be here
if ( $noticesOn == true ) {
add_action('admin_enqueue_scripts', 'block_dismissable_admin_notices');
add_action('login_enqueue_scripts', 'block_dismissable_admin_notices');
}
ok, I finally got it好的,我终于明白了
this is the solution这是解决方案
add_action( 'init', 'remove_my_action' );
function remove_my_action()
{
global $wp_filter;
remove_action( 'admin_notices', 'display_admin_notice');
}
it works perfect它完美无缺
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.