我需要一个特定的插件来覆盖wordpress函数get_avatar()
以某种条件将配置文件图像绑定到其他图像。
我该怎么做?是否有特定的挂钩或过滤器来执行此操作?
我需要一个特定的插件来覆盖wordpress函数get_avatar()
以某种条件将配置文件图像绑定到其他图像。
我该怎么做?是否有特定的挂钩或过滤器来执行此操作?
有get\\u avatar过滤器。codex ref
我可以进去functions.php
功能get_avatar()
但最好的方法似乎是使用过滤器get_avatar
.
我在这里找到了答案:https://codex.wordpress.org/Plugin_API/Filter_Reference/get_avatar
化身功能有一个过滤器挂钩get_avatar
. 您应该使用它来过滤并替换为您的函数,就像下面的示例一样,没有逻辑。
add_filter( \'get_avatar\', \'get_avatar\', 10, 5 );
/**
* Override get_avatar with uploaded avatar else default.
*/
function get_avatar( $avatar, $id_or_email, $size, $default, $alt )
{
$avatar = "<img alt=\'{$alt}\' src=\'{$avatar_path}\' class=\'avatar avatar-{$size} photo avatar-default\' height=\'{$size}\' width=\'{$size}\' />";
return $avatar;
}
你可以用这个link
您可以使用以下筛选器-
// Apply filter
add_filter( \'get_avatar\' , \'my_avatar_func\' , 1 , 5 );
function my_avatar_func( $avatar, $id_or_email, $size, $default, $alt ) {
// your code here
}
这与其说是一个有直接答案的问题,不如说是一个理论问题。我一直在处理更新或删除帖子以及更新或删除用户时启动功能的不同操作。对于行动,publish_post 和before_delete_post 对于职位和personal_options_update, edit_user_profile_update 和delete_user 对于用户。通过更新后,您可以访问当前设置的值,同时访问新值,以便在发生任何事情之前进行您认为合适的任何更改。使用用户更新,您只能在设置新信息后才能访问新信息。Is there a