php - 一个插件覆盖了我使用functions.php设置的属性值
问题描述
我必须遵循代码:
function my_custom_avatar($avatar, $id_or_email, $size, $default, $alt) {
// Stuff that sets background
$avatar = "<img src='{$avatar}' alt='{$alt}' style='{$background}' class='avatar test avatar-{$size} photo' height='{$size}' width='{$size}' />";
return $avatar;
}
add_filter( 'get_avatar' , 'my_custom_avatar' , 10, 5);
上面的代码style
在大多数情况下应用带有背景 URL 的属性,因此它可以正常工作。
但是,在论坛插件的一页上,该style
属性设置为width: 64px; height: 64px;
. 看起来我的style
属性值被插件用于的其他过滤器覆盖get_avatar
。
有什么方法可以确保我的过滤器添加的代码不会被插件覆盖?
我尝试使用以下方法提高优先级:
add_filter( 'get_avatar' , 'my_custom_avatar' , 99, 5);
add_filter( 'get_avatar' , 'my_custom_avatar' , 999, 5);
add_filter( 'get_avatar' , 'my_custom_avatar' , 9999999, 5);
然而,他们都没有工作。
如何防止插件覆盖我的值?
谢谢。
解决方案
您可以使用 删除插件创建的过滤器remove_filter
,例如,如果插件如下:
function pluginMethod($args) {}
add_filter('get_avatar', 'pluginMethod', 10, 5);
你可以做:
remove_filter('get_avatar', 'pluginMethod');
请参阅:https ://codex.wordpress.org/Function_Reference/remove_filter
希望这对您有所帮助。
推荐阅读
- asp.net-core - 我应该在每个页面上还是在 Layout.cshtml 部分文件中放置一个脚本部分?
- node.js - 修改 npm 模块文件夹外的 npm 包
- c# - 如何在 C# 中从 RSA 私钥和颁发者生成授权令牌?
- html - 如何访问跨度值
- javascript - 非变异数组
- azure-application-insights - 无法在 Azure App Insights 中设置警报
- r - 如何根据 R 中的字符串模式列表对列进行分组?
- python - 在 Django Admin 中显示对象相关对象参考
- c - Inotify 写入可见性保证
- laravel - Laravel 邮件通知 - 从地址修改