我被要求在一个网站上做一些工作,在这个网站上,老开发人员已经将这个函数(创建一个变量,将用户的头像存储到img标签中)写入到函数中。php:
add_filter(\'get_avatar\', \'lb_acf_profile_avatar\', 10, 5);
function lb_acf_profile_avatar($avatar, $id_or_email, $size, $default, $alt) {
$user = \'\';
// Get user by id or email
if (is_numeric($id_or_email)) {
$id = (int) $id_or_email;
$user = get_user_by(\'id\', $id);
} elseif (is_object($id_or_email)) {
if (!empty($id_or_email->user_id)) {
$id = (int) $id_or_email->user_id;
$user = get_user_by(\'id\', $id);
}
} else {
$user = get_user_by(\'email\', $id_or_email);
}
if (!$user) {
return $avatar;
}
// Get the user id
$user_id = $user->ID;
//$user_info = get_userdata($user_id)
// Get the file id
$avatar_url = $user->get(\'user_url\'); //\'https://dojo.nearsoft.com/wp-content/uploads/2017/02/Eric-Wroolie-per-template.jpg\';
if ($avatar_url == \'\') {
return $avatar;
}
$avatar = \'<img alt="\' . $alt . \'" src="\' . $avatar_url . \'" class="avatar avatar-\' . $size . \'" height="\' . $size . \'" width="\' . $size . \'"/>\';
// Return our new avatar
return $avatar;
}
我知道这个功能可以工作,因为他构建的应用程序使用代码为每个用户生成化身。我只是不知道如何使用它,也无法联系到他来帮助我使用它。
到目前为止,我的努力都失败了,使用的代码有点像这样:
<?php lb_acf_profile_avatar() ?>
<?php if ($avatar != \'\') : ?>
<div>Hellow World</div>
<?php endif; ?>
在这里,我尝试调用函数,然后假设返回的变量(化身图像)从此点起可用。事实似乎并非如此。
对于每个参数,错误消息为其中的5条:
Warning: Missing argument 5 for lb_acf_profile_avatar(), called in /home/materialshub/public_html/development/wp-content/themes/bolt/header.php on line 238 and defined in /home/materialshub/public_html/development/wp-content/themes/bolt/functions.php on line 663
Is there a way to tailor this so I get the avatar_url without the img tag returned, but I need the original code to function as it should as it is also used in the app and is functioning correctly.
我没有访问该应用程序的权限。或者老开发人员。你能提供的任何帮助都是很好的。如果你想了解更多信息,请告诉我。
I think I want a new function that gets the avatar_url like the function above but without any of the img tag. A simple url is all I need.
我需要这是动态的,所以它可以为所有用户自动工作,生成avatar\\u url。我怎样才能在这个庄园里传递论点?
I cannot just use the inbuilt get_avatar() WordPress function before we try go down that route as the app has made use of an empty field in the database \'user_url\'.
我很感激这是一个很烦人的问题,但我很感激你的好意。
EDIT: 我已尝试还原回get\\u avatar()函数,然后返回此警告:
Warning: Missing argument 1 for get_avatar(), called in /home/materialshub/public_html/development/wp-content/themes/bolt/header.php on line 239 and defined in /home/materialshub/public_html/development/wp-includes/pluggable.php on line 2450
谢谢,杰森。