/** * Return an instance of this class. * * @since 1.0.0 * * @return object A single instance of this class. */ public static function get_instance() { if (null == self::$instance) { self::$instance = new self(); } return self::$instance; }
public function __construct() { $this->resizer = PHTPB_Resize_Image::get_instance(); }
public static function get_att_img($attachment_id, $size, $attr = '', $skip_mime_types = array()) { if (!is_array($size)) { $resized = wp_get_attachment_image_src($attachment_id, $size); if (!$resized) { return; } $img = array(); $img['1x']['url'] = $resized[0]; $img['1x']['width'] = $resized[1]; $img['1x']['height'] = $resized[2]; } else { list($width, $height) = $size; $resizer = PHTPB_Resize_Image::get_instance(); $img = $resizer->resize_image_srcset($attachment_id, intval($width), intval($height), $skip_mime_types); } $html = ''; if (isset($img['1x']['url']) && isset($img['1x']['width']) && isset($img['1x']['height'])) { $default_attr = array('src' => $img['1x']['url'], 'class' => '', 'alt' => self::image_alt($attachment_id)); if (isset($img['2x']['url']) && isset($img['2x']['url']) && $img['2x']['url']) { $default_attr['srcset'] = $img['1x']['url'] . ' 1x, ' . $img['2x']['url'] . ' 2x'; } $attr = wp_parse_args($attr, $default_attr); $attr = array_map('esc_attr', $attr); $html = '<img '; foreach ($attr as $name => $value) { $html .= " {$name}=" . '"' . $value . '"'; } $html .= ' />'; } return $html; }