post_author);
} elseif(is_a($id_or_email, 'WP_Comment')){
if(!empty($id_or_email->user_id)){
$user = get_user_by('id', (int) $id_or_email->user_id);
}
if(empty($user) && !empty($id_or_email->comment_author_email)){
$id_or_email = $id_or_email->comment_author_email;
}
if(is_a($id_or_email, 'WP_Comment')){
return false;
}
}
if(!empty($user) && is_a($user, 'WP_User')){
$id_or_email = $user->user_email;
}
// We need an email which should be a string if something else is being passed then just return
if(!is_string($id_or_email)){
return false;
}
$email_hash = md5(strtolower(trim($id_or_email)));
return $email_hash;
}
// Deletes all the gravatar stored
static function delete(){
$path = \SpeedyCache\Util::cache_path('gravatars');
if(!file_exists($path)){
return;
}
$files = scandir($path);
if(empty($files)){
return __('No file present to delete', 'speedycache');
}
foreach($files as $file){
// We dont want to delete index.html or any directory.
if(file_exists($path . $file) && !is_dir($path . $file) && $file != 'index.html'){
@unlink($path . $file);
}
}
return __('Gravatar files deleted', 'speedycache');
}
static function convert_path_to_link($path){
preg_match('/\/cache\/speedycache\/.+/', $path, $out);
$prefix_link = str_replace(array('http:', 'https:'), '', content_url());
return $prefix_link . $out[0];
}
}