调整php以改变行为(非常具体的问题)

时间:2018-12-02 20:18:49

标签: php wordpress gravatar

我正在运行Wordpress安装。它正在抓取Gravatar用户的详细信息和图片,并使用此信息填充我的网站首页(需要的特定类别(日记))。它替换了精选图片并放置了作者的头像。一个月前,我开始对所有图像图像使用缓存(在注释方面效果很好),但是对首页上加载的图像没有影响。该代码可防止图像来自缓存,并在每一个来自gravatar的请求时提取图像。缓存文件夹位于“ / wp-content / uploads / fv-gravatar-cache”中。该缓存是由插件(fv gravatar缓存)生成的,这是代码(是子主题中funtions.php文件的一部分):

add_filter('post_thumbnail_html', 'author_gravatar_featured_image_in_diaries', 90, 5);
function author_gravatar_featured_image_in_diaries($html, $post_id, $post_thumbnail_id, $size, $attr) {

    $id = get_post_thumbnail_id();
    $src = wp_get_attachment_image_src($id, $size);
    $alt = get_the_title($id);
    //$class = $attr['class'];

        $author_id = get_post_field ('post_author', $post_id);
        $email = get_the_author_meta( 'user_email', $author_id );
        $fname = get_the_author_meta('first_name', $author_id );
        $lname = get_the_author_meta('last_name', $author_id );
        $profile_img = esc_url( get_avatar_url($email) );

    if ( in_category( 'diaries', $post_id) || post_is_in_descendant_category( 4 ) ) {
        $html = '<img src="' . $profile_img . '" alt="' . $fname . $lname . '" />';
    }

    return $html;
}

请帮助我更改此行为。我希望从文件夹而不是从gravatar.com网站加载图像。图片使用用户ID命名(不是电子邮件地址,而是20个字符的全数字名称+ .jpg)(例如x = 0172b97fa46359d13c3c69a376d2aeabx192.png)

谢谢!

0 个答案:

没有答案