Exemplo n.º 1
0
 /**
  * Retrieve a post image.
  *
  * @since  1.0.0
  * @global WP_Post $post WP_Post object.
  * @param  string  $size Image size.
  * @return string        Image tag.
  */
 public function image($size = '')
 {
     global $post;
     $shortcode = Cherry_Shortcodes_Handler::get_shortcode_name();
     if ('banner' == $shortcode) {
         return Cherry_Shortcodes_Tools::get_image_url($this->atts['image']);
     }
     if (!post_type_supports(get_post_type($post->ID), 'thumbnail')) {
         return;
     }
     if (!has_post_thumbnail($post->ID)) {
         return;
     }
     $url = get_permalink($post->ID);
     $image_classes = array();
     $image_classes[] = 'post-thumbnail_link';
     switch ($shortcode) {
         case 'posts':
             if (empty($size)) {
                 $size = sanitize_key($this->atts['image_size']);
             }
             if (isset($this->atts['lightbox_image']) && 'yes' === $this->atts['lightbox_image']) {
                 $image_classes[] = 'cherry-popup-img';
                 $image_classes[] = 'popup-img';
                 $thumbnail_id = get_post_thumbnail_id($post->ID);
                 $url = wp_get_attachment_url($thumbnail_id);
                 if (!$url) {
                     $url = get_permalink($post->ID);
                 }
                 wp_enqueue_script('magnific-popup');
             }
             $thumbnail = get_the_post_thumbnail($post->ID, $size);
             break;
         case 'swiper_carousel':
             $post_id = get_the_ID();
             $crop_image = (bool) ('yes' === $this->atts['crop_image']) ? true : false;
             $crop_width = intval($this->atts['crop_width']);
             $crop_height = intval($this->atts['crop_height']);
             if ($crop_image) {
                 $img_url = wp_get_attachment_url(get_post_thumbnail_id(), 'full');
                 $thumbnail = Cherry_Shortcodes_Tools::get_crop_image($img_url, get_post_thumbnail_id(), $crop_width, $crop_height);
             } else {
                 $thumbnail = get_the_post_thumbnail($post->ID, 'large');
             }
             break;
         default:
             if (empty($this->atts['image_size'])) {
                 $thumbnail = get_the_post_thumbnail($post->ID, 'large');
             } else {
                 $thumbnail = get_the_post_thumbnail($post->ID, sanitize_key($this->atts['image_size']));
             }
             break;
     }
     $wrap = 'no' === $this->atts['linked_image'] ? '%3$s' : '<a href="%1$s" title="%2$s" class="%4$s">%3$s</a>';
     $image_classes = apply_filters('cherry_shortcodes_image_classes_template_callbacks', $image_classes, $shortcode);
     $image_classes = array_unique($image_classes);
     $image_classes = array_map('sanitize_html_class', $image_classes);
     $image = sprintf($wrap, esc_url($url), esc_attr(the_title_attribute(array('before' => '', 'after' => '', 'echo' => false, 'post' => $post->ID))), $thumbnail, join(' ', $image_classes));
     /**
      * Filter a image.
      *
      * @since 1.0.0
      * @param string $image     Image tag.
      * @param array  $atts      Shortcode attributes.
      * @param string $shortcode Shortcode name.
      */
     return apply_filters('cherry_shortcodes_image_template_callbacks', $image, $this->atts, $shortcode);
 }