/** * Returns the Settings from the Database * * @param string $force - Forces a database call incase it was stored. * * @return array */ public static function get_settings($force = false) { if (empty(self::$settings) || $force) { self::$settings = get_option(self::$option_key); } return self::$settings; }
public static function image($image = 'featured', $additional_attributes = array(), $tag_type = 'img') { if (empty($image)) { return ''; } if ($image === 'featured') { if (is_numeric($image) && get_post_type($image) !== 'attachment') { $attachment = get_post(get_post_thumbnail_id($image)); } else { $attachment = get_post(get_post_thumbnail_id()); } if ($attachment) { $image = array('alt' => get_post_meta($attachment->ID, '_wp_attachment_image_alt', true), 'caption' => $attachment->post_excerpt, 'description' => $attachment->post_content, 'href' => get_permalink($attachment->ID), 'src' => $attachment->guid, 'url' => $attachment->guid, 'title' => $attachment->post_title); if (GRAV_BLOCKS_PLUGIN_SETTINGS::is_setting_checked('advanced_options', 'add_responsive_img')) { $image['sizes'] = array(); foreach (self::get_image_sizes() as $size => $image_size) { // Only include sizes that are not cropped. if (empty($image_size['crop']) && $image_size['width']) { if ($url = wp_get_attachment_image_src($attachment->ID, $size)) { $image['sizes'][$size] = $url[0]; } } } } } else { return ''; } } if ($tag_type === 'img' && !isset($additional_attributes['alt']) && !empty($image['alt'])) { $additional_attributes['alt'] = esc_attr($image['alt']); } if (!isset($additional_attributes['title']) && !empty($image['title'])) { $additional_attributes['title'] = esc_attr($image['title']); } $image_sources = array(); if (GRAV_BLOCKS_PLUGIN_SETTINGS::is_setting_checked('advanced_options', 'add_responsive_img')) { $additional_attributes['src'] = 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=='; $image_sources = self::image_sources($image, true); } else { if ($tag_type === 'img' && !isset($additional_attributes['src'])) { if (!empty($image['sizes']['large'])) { $additional_attributes['src'] = $image['sizes']['large']; } else { if (!empty($image['url'])) { $additional_attributes['src'] = $image['sizes']['url']; } } } } $additional_attributes = array_filter($additional_attributes); foreach ($additional_attributes as $attribute_key => $attribute_value) { $additional_attributes[$attribute_key] = '"' . esc_attr($attribute_value) . '"'; } $attributes_array = array_filter(array_merge($image_sources, $additional_attributes)); // If not ALt then add an empty one for validation if ($tag_type === 'img' && empty($additional_attributes['alt'])) { $attributes_array['alt'] = '""'; } $attributes_str = trim(urldecode(http_build_query($attributes_array, '', ' '))); if ($attributes_str) { if ($tag_type === 'div') { return '<div ' . $attributes_str . '></div>'; } else { return '<img ' . $attributes_str . ' />'; } } return ''; }