Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function isImage($url) {
- $headers = get_headers($url, 1);
- if (isset($headers['Content-Type'])) {
- $contentType = $headers['Content-Type'];
- if (strpos($contentType, 'image/') === 0) {
- return true;
- }
- }
- $pathInfo = pathinfo($url);
- if (isset($pathInfo['extension'])) {
- $extension = strtolower($pathInfo['extension']);
- $imageExtensions = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp', 'ico'];
- if (in_array($extension, $imageExtensions)) {
- return true;
- }
- }
- return false;
- }
- add_filter('wcfm_custom_field_value', function($val, $name, $product_id, $field_type, $field) {
- if($field_type == 'upload') {
- $field_value = wcfm_get_attachment_url(get_post_meta($product_id, $name, true));
- if(!$field_value || !isImage($field_value)) {
- return $val;
- }
- return '<img src="'.esc_url($field_value).'" alt="'. wcfm_removeslashes(__($field['label'], 'WCfM')) .'"/>';
- }
- return $val;
- }, 10, 5);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement