/** * Featured image for self-hosted videos. If an image is found, * it's used as the "poster" attribute in the [video] shortcode. * * @since 4.0.0 * @param array $atts Shortcode attributes. * @return array */ function cherry_video_atts($atts) { // Don't show in the admin. if (is_admin()) { return $atts; } // Check if post has an image attached. if (!cherry_has_post_thumbnail()) { return $atts; } // Only run if the user didn't set a `poster` image. if (!empty($atts['poster'])) { return $atts; } $thumbnail_id = get_post_thumbnail_id(); if (empty($thumbnail_id)) { return $atts; } $src = wp_get_attachment_image_src($thumbnail_id, 'full', false); if (is_array($src) && !empty($src)) { $atts['poster'] = $src[0]; } return $atts; }
/** * Get featured image. * If has post thumbnail - will get post thumbnail, else - get first image from content. * * @since 4.0.0 * @param array $args * @return string */ function cherry_get_the_post_image($args) { /** * Filter post format image output to rewrite image from child theme or plugins. * @since 4.0.0 */ $result = apply_filters('cherry_pre_get_post_image', false); if (false !== $result) { return $result; } $post_id = get_the_ID(); $post_type = get_post_type($post_id); /** * Filter the default arguments used to display a post image. * * @since 4.0.0 * @param array $defaults Array of arguments. * @param int $post_id The post ID. * @param string $post_type The post type of the current post. */ $defaults = apply_filters('cherry_get_the_post_image_defaults', array('container' => 'figure', 'container_class' => 'post-thumbnail', 'size' => is_single($post_id) ? cherry_get_option('blog-post-featured-image-size') : cherry_get_option('blog-featured-images-size'), 'before' => '', 'after' => '', 'class' => is_single($post_id) ? cherry_get_option('blog-post-featured-image-align') : cherry_get_option('blog-featured-images-align'), 'wrap' => '<%1$s class="%2$s %6$s"><a href="%4$s" class="%2$s-link popup-img" data-init=\'%5$s\'>%3$s</a></%1$s>'), $post_id, $post_type); $args = wp_parse_args($args, $defaults); wp_enqueue_script('magnific-popup'); $default_init = array('type' => 'image'); /** * Filter the arguments used to init image zoom popup. * * @since 4.0.0 * @param array $args Array of arguments. */ $init = apply_filters('cherry_get_the_post_image_zoom_init', $default_init); $init = wp_parse_args($init, $default_init); $init = json_encode($init); if (cherry_has_post_thumbnail($post_id)) { $thumb = get_the_post_thumbnail($post_id, $args['size'], array('class' => $args['container_class'] . '-img')); $thumb = $args['before'] . $thumb . $args['after']; $url = wp_get_attachment_url(get_post_thumbnail_id($post_id)); } else { $img = cherry_get_post_images(); if (!$img || empty($img) || empty($img[0])) { return false; } elseif (is_int($img[0])) { $thumb = wp_get_attachment_image($img[0], $args['size'], '', array('class' => $args['container_class'] . '-img')); $thumb = $args['before'] . $thumb . $args['after']; $url = wp_get_attachment_url($img[0]); } else { global $_wp_additional_image_sizes; if (!isset($_wp_additional_image_sizes[$args['size']])) { return false; } $thumb = '<img src="' . esc_url($img[0]) . '" class="' . $args['container_class'] . '-img" width="' . $_wp_additional_image_sizes[$args['size']]['width'] . '">'; $thumb = $args['before'] . $thumb . $args['after']; $url = $img[0]; } } $result = sprintf($args['wrap'], $args['container'], $args['container_class'], $thumb, $url, $init, esc_attr($args['class'])); /** * Filter featured image. * * @since 4.0.0 */ return apply_filters('cherry_get_the_post_image', $result, $args); }