Correct code local cash Gravatars with plugin “FV Gravatar Cache”
-
Hi
This code was written to me ChatGPT
// 91. Comment Author Gravatar URL
if( ! function_exists('ampforwp_get_comments_gravatar') ){
function ampforwp_get_comments_gravatar( $comment ) {
global $redux_builder_amp;
if(isset($redux_builder_amp['ampforwp-display-avatar']) && $redux_builder_amp['ampforwp-display-avatar'] == 0){
return '';
}
if (class_exists('FV_Gravatar_Cache')) {
$options = get_option('fv_gravatar_cache');
$size = !empty($options['size']) ? $options['size'] : '96';
$email_hash = md5(strtolower(trim($comment->comment_author_email)));
$upload_dir = wp_upload_dir();
$cache_dir = $upload_dir['basedir'] . '/fv-gravatar-cache/';
$cache_url = $upload_dir['baseurl'] . '/fv-gravatar-cache/';
$cached_avatar_path = $cache_dir . $email_hash . 'x' . $size . '.png';
$default_avatar_url = $cache_url . 'mystery' . esc_html($size) . '.png';
if (file_exists($cached_avatar_path)) {
$avatar_url = $cache_url . $email_hash . 'x' . $size . '.png';
} else {
$avatar_url = $default_avatar_url;
}
return $avatar_url;
}
$gravatar_exists = ampforwp_gravatar_checker($comment->comment_author_email);
if (null !== ampforwp_get_wp_user_avatar($comment, 'comment')) {
return ampforwp_get_wp_user_avatar($comment, 'comment');
} elseif ($gravatar_exists) {
return get_avatar_url($comment, apply_filters('ampforwp_get_comments_gravatar', '60'), '');
} else {
return apply_filters('ampforwp_get_comments_gravatar', '');
}
}
}
Viewing 8 replies - 1 through 8 (of 8 total)
Viewing 8 replies - 1 through 8 (of 8 total)
- You must be logged in to reply to this topic.