/**
 * Filter to add 'srcset' and 'sizes' attributes to post thumbnails and gallery images.
 * The filter is added to the hook in wp-tevko-core-functions.php because
 * it is only needed on a version of WordPress previous to 4.4.
 *
 * @since 2.3.0
 * @see 'wp_get_attachment_image_attributes'
 *
 * @return array Attributes for image.
 */
function tevkori_filter_attachment_image_attributes($attr, $attachment, $size)
{
    // Set 'srcset' and 'sizes' if not already present and both were returned.
    if (empty($attr['srcset'])) {
        $srcset = wp_get_attachment_image_srcset($attachment->ID, $size);
        $sizes = wp_get_attachment_image_sizes($attachment->ID, $size);
        if ($srcset && $sizes) {
            $attr['srcset'] = $srcset;
            if (empty($attr['sizes'])) {
                $attr['sizes'] = $sizes;
            }
        }
    }
    return $attr;
}
 /**
  * render image tag
  *
  * @param int $attachment_id post id of the image
  * @since 1.6.10
  */
 public function create_image_tag($attachment_id)
 {
     $image = wp_get_attachment_image_src($attachment_id, 'full');
     if ($image) {
         list($src, $width, $height) = $image;
         $hwstring = image_hwstring($width, $height);
         $attachment = get_post($attachment_id);
         $alt = trim(strip_tags(get_post_meta($attachment_id, '_wp_attachment_image_alt', true)));
         $title = trim(strip_tags($attachment->post_title));
         // Finally, use the title
         global $wp_current_filter;
         $more_attributes = '';
         // create srcset and sizes attributes if we are in the the_content filter and in WordPress 4.4
         if (isset($wp_current_filter) && in_array('the_content', $wp_current_filter) && !defined('ADVADS_DISABLE_RESPONSIVE_IMAGES')) {
             if (function_exists('wp_get_attachment_image_srcset')) {
                 $more_attributes .= ' srcset=\'' . wp_get_attachment_image_srcset($attachment_id, 'full') . '\'';
             }
             if (function_exists('wp_get_attachment_image_sizes')) {
                 $more_attributes .= ' sizes=\'' . wp_get_attachment_image_sizes($attachment_id, 'full') . '\'';
             }
         }
         echo rtrim("<img {$hwstring}") . " src='{$src}' alt='{$alt}' title='{$title}' {$more_attributes}/>";
     }
 }
    function test_wp_make_content_images_responsive_schemes()
    {
        $image_meta = wp_get_attachment_metadata(self::$large_id);
        $size_array = array((int) $image_meta['sizes']['medium']['width'], (int) $image_meta['sizes']['medium']['height']);
        $srcset = sprintf('srcset="%s"', wp_get_attachment_image_srcset(self::$large_id, $size_array, $image_meta));
        $sizes = sprintf('sizes="%s"', wp_get_attachment_image_sizes(self::$large_id, $size_array, $image_meta));
        // Build HTML for the editor.
        $img = get_image_tag(self::$large_id, '', '', '', 'medium');
        $img_https = str_replace('http://', 'https://', $img);
        $img_relative = str_replace('http://', '//', $img);
        // Manually add srcset and sizes to the markup from get_image_tag();
        $respimg = preg_replace('|<img ([^>]+) />|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img);
        $respimg_https = preg_replace('|<img ([^>]+) />|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img_https);
        $respimg_relative = preg_replace('|<img ([^>]+) />|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img_relative);
        $content = '
			<p>Image, http: protocol. Should have srcset and sizes.</p>
			%1$s

			<p>Image, http: protocol. Should have srcset and sizes.</p>
			%2$s

			<p>Image, protocol-relative. Should have srcset and sizes.</p>
			%3$s';
        $unfiltered = sprintf($content, $img, $img_https, $img_relative);
        $expected = sprintf($content, $respimg, $respimg_https, $respimg_relative);
        $actual = wp_make_content_images_responsive($unfiltered);
        $this->assertSame($expected, $actual);
    }
/**
 * Gets data about an attachment, such as alt text and captions.
 * @since 2.6.0
 * @param object|bool $product
 * @return array
 */
function wc_get_product_attachment_props($attachment_id = null, $product = false)
{
    $props = array('title' => '', 'caption' => '', 'url' => '', 'alt' => '', 'src' => '', 'srcset' => false, 'sizes' => false);
    if ($attachment = get_post($attachment_id)) {
        $props['title'] = trim(strip_tags($attachment->post_title));
        $props['caption'] = trim(strip_tags($attachment->post_excerpt));
        $props['url'] = wp_get_attachment_url($attachment_id);
        $props['alt'] = trim(strip_tags(get_post_meta($attachment_id, '_wp_attachment_image_alt', true)));
        // Large version.
        $src = wp_get_attachment_image_src($attachment_id, 'large');
        $props['full_src'] = $src[0];
        $props['full_src_w'] = $src[1];
        $props['full_src_h'] = $src[2];
        // Image source.
        $src = wp_get_attachment_image_src($attachment_id, 'shop_single');
        $props['src'] = $src[0];
        $props['src_w'] = $src[1];
        $props['src_h'] = $src[2];
        $props['srcset'] = function_exists('wp_get_attachment_image_srcset') ? wp_get_attachment_image_srcset($attachment_id, 'shop_single') : false;
        $props['sizes'] = function_exists('wp_get_attachment_image_sizes') ? wp_get_attachment_image_sizes($attachment_id, 'shop_single') : false;
        // Alt text fallbacks
        $props['alt'] = empty($props['alt']) ? $props['caption'] : $props['alt'];
        $props['alt'] = empty($props['alt']) ? trim(strip_tags($attachment->post_title)) : $props['alt'];
        $props['alt'] = empty($props['alt']) && $product ? trim(strip_tags(get_the_title($product->ID))) : $props['alt'];
    }
    return $props;
}
 /**
  * Show subcategory thumbnails.
  *
  * @param mixed $category
  * @subpackage	Loop
  */
 function woocommerce_subcategory_thumbnail($category)
 {
     $small_thumbnail_size = apply_filters('subcategory_archive_thumbnail_size', 'shop_catalog');
     $dimensions = wc_get_image_size($small_thumbnail_size);
     $thumbnail_id = get_woocommerce_term_meta($category->term_id, 'thumbnail_id', true);
     if ($thumbnail_id) {
         $image = wp_get_attachment_image_src($thumbnail_id, $small_thumbnail_size);
         $image = $image[0];
         $image_srcset = function_exists('wp_get_attachment_image_srcset') ? wp_get_attachment_image_srcset($thumbnail_id, $small_thumbnail_size) : false;
         $image_sizes = function_exists('wp_get_attachment_image_sizes') ? wp_get_attachment_image_sizes($thumbnail_id, $small_thumbnail_size) : false;
     } else {
         $image = wc_placeholder_img_src();
         $image_srcset = $image_sizes = false;
     }
     if ($image) {
         // Prevent esc_url from breaking spaces in urls for image embeds
         // Ref: https://core.trac.wordpress.org/ticket/23605
         $image = str_replace(' ', '%20', $image);
         // Add responsive image markup if available
         if ($image_srcset && $image_sizes) {
             echo '<img src="' . esc_url($image) . '" alt="' . esc_attr($category->name) . '" width="' . esc_attr($dimensions['width']) . '" height="' . esc_attr($dimensions['height']) . '" srcset="' . esc_attr($image_srcset) . '" sizes="' . esc_attr($image_sizes) . '" />';
         } else {
             echo '<img src="' . esc_url($image) . '" alt="' . esc_attr($category->name) . '" width="' . esc_attr($dimensions['width']) . '" height="' . esc_attr($dimensions['height']) . '" />';
         }
     }
 }
         echo apply_filters('the_content', $wysiwyg);
     }
     break;
     //
     // Image
     //
 //
 // Image
 //
 case 'fullwidth_image':
     $image_ID = get_post_meta($talk_ID, 'uxr_talk_transcript_' . $count . '_fullwidth_image', true);
     if (isset($image_ID) && !empty($image_ID)) {
         // Image source
         $img_src = wp_get_attachment_image_url($image_ID, 'uxr_fullwidth');
         $img_srcset = wp_get_attachment_image_srcset($image_ID, 'uxr_fullwidth');
         $img_sizes = wp_get_attachment_image_sizes($image_ID, 'uxr_fullwidth');
         // Image meta
         $image_meta = get_posts(array('p' => $image_ID, 'post_type' => 'attachment'));
         $image_caption = $image_meta[0]->post_excerpt;
         $image_more_meta = wp_get_attachment_metadata($image_ID, 'uxr_fullwidth');
         echo "\t" . '</div>' . "\n";
         echo '</div>' . "\n";
         echo '<img src="' . esc_url($img_src) . '" srcset="' . esc_attr($img_srcset) . '" sizes="' . esc_attr($img_sizes) . '" alt="" class="uxr-asset-fullwidth" />';
         echo '<div class="uxr-grid-container">' . "\n";
         echo "\t" . '<div class="uxr-contrib">' . "\n";
     }
     break;
     //
     // Links
     //
 //
Exemple #7
0
/**
 * Adds 'srcset' and 'sizes' attributes to an existing 'img' element.
 *
 * @since 4.4.0
 *
 * @see wp_get_attachment_image_srcset()
 * @see wp_get_attachment_image_sizes()
 *
 * @param string $image An HTML 'img' element to be filtered.
 * @return string Converted 'img' element with `srcset` and `sizes` attributes added.
 */
function wp_img_add_srcset_and_sizes($image)
{
    // Return early if a 'srcset' attribute already exists.
    if (false !== strpos($image, ' srcset="')) {
        return $image;
    }
    // Parse id, size, width, and height from the `img` element.
    $id = preg_match('/wp-image-([0-9]+)/i', $image, $match_id) ? (int) $match_id[1] : false;
    $size = preg_match('/size-([^\\s|"]+)/i', $image, $match_size) ? $match_size[1] : false;
    $width = preg_match('/ width="([0-9]+)"/', $image, $match_width) ? (int) $match_width[1] : false;
    $height = preg_match('/ height="([0-9]+)"/', $image, $match_height) ? (int) $match_height[1] : false;
    if ($id && false === $size) {
        $size = array($width, $height);
    }
    /*
     * If attempts to parse the size value failed, attempt to use the image
     * metadata to match the 'src' against the available sizes for an attachment.
     */
    if (!$size && !empty($id) && is_array($meta = wp_get_attachment_metadata($id))) {
        // Parse the image src value from the img element.
        $src = preg_match('/src="([^"]+)"/', $image, $match_src) ? $match_src[1] : false;
        // Return early if the src value is empty.
        if (!$src) {
            return $image;
        }
        /*
         * First, see if the file is the full size image. If not, loop through
         * the intermediate sizes until we find a file that matches.
         */
        $image_filename = wp_basename($src);
        if ($image_filename === basename($meta['file'])) {
            $size = 'full';
        } else {
            foreach ($meta['sizes'] as $image_size => $image_size_data) {
                if ($image_filename === $image_size_data['file']) {
                    $size = $image_size;
                    break;
                }
            }
        }
    }
    // If ID and size, try for 'srcset' and 'sizes' and update the markup.
    if ($id && $size && ($srcset = wp_get_attachment_image_srcset($id, $size))) {
        /*
         * Pass the 'height' and 'width' to 'wp_get_attachment_image_sizes()' to avoid
         * recalculating the image size.
         */
        $args = array('height' => $height, 'width' => $width);
        $sizes = wp_get_attachment_image_sizes($id, $size, $args);
        // Format the srcset and sizes string and escape attributes.
        $srcset_and_sizes = sprintf(' srcset="%s" sizes="%s"', esc_attr($srcset), esc_attr($sizes));
        // Add srcset and sizes attributes to the image markup.
        $image = preg_replace('/<img ([^>]+)[\\s?][\\/?]>/', '<img $1' . $srcset_and_sizes . ' />', $image);
    }
    return $image;
}
 /**
  * Returns an array of data for a variation. Used in the add to cart form.
  * @since  2.4.0
  * @param  WC_Product $variation Variation product object or ID
  * @return array
  */
 public function get_available_variation($variation)
 {
     if (is_numeric($variation)) {
         $variation = $this->get_child($variation);
     }
     if (has_post_thumbnail($variation->get_variation_id())) {
         $attachment_id = get_post_thumbnail_id($variation->get_variation_id());
         $attachment = wp_get_attachment_image_src($attachment_id, 'shop_single');
         $full_attachment = wp_get_attachment_image_src($attachment_id, 'full');
         $attachment_object = get_post($attachment_id);
         $image = $attachment ? current($attachment) : '';
         $image_link = $full_attachment ? current($full_attachment) : '';
         $image_title = get_the_title($attachment_id);
         $image_alt = trim(strip_tags(get_post_meta($attachment_id, '_wp_attachment_image_alt', true)));
         $image_caption = $attachment_object->post_excerpt;
         $image_srcset = function_exists('wp_get_attachment_image_srcset') ? wp_get_attachment_image_srcset($attachment_id, 'shop_single') : false;
         $image_sizes = function_exists('wp_get_attachment_image_sizes') ? wp_get_attachment_image_sizes($attachment_id, 'shop_single') : false;
         if (empty($image_alt)) {
             $image_alt = $image_title;
         }
     } else {
         $image = $image_link = $image_title = $image_alt = $image_srcset = $image_sizes = $image_caption = '';
     }
     $availability = $variation->get_availability();
     $availability_html = empty($availability['availability']) ? '' : '<p class="stock ' . esc_attr($availability['class']) . '">' . wp_kses_post($availability['availability']) . '</p>';
     $availability_html = apply_filters('woocommerce_stock_html', $availability_html, $availability['availability'], $variation);
     return apply_filters('woocommerce_available_variation', array('variation_id' => $variation->variation_id, 'variation_is_visible' => $variation->variation_is_visible(), 'variation_is_active' => $variation->variation_is_active(), 'is_purchasable' => $variation->is_purchasable(), 'display_price' => $variation->get_display_price(), 'display_regular_price' => $variation->get_display_price($variation->get_regular_price()), 'attributes' => $variation->get_variation_attributes(), 'image_src' => $image, 'image_link' => $image_link, 'image_title' => $image_title, 'image_alt' => $image_alt, 'image_caption' => $image_caption, 'image_srcset' => $image_srcset ? $image_srcset : '', 'image_sizes' => $image_sizes ? $image_sizes : '', 'price_html' => apply_filters('woocommerce_show_variation_price', $variation->get_price() === "" || $this->get_variation_price('min') !== $this->get_variation_price('max'), $this, $variation) ? '<span class="price">' . $variation->get_price_html() . '</span>' : '', 'availability_html' => $availability_html, 'sku' => $variation->get_sku(), 'weight' => $variation->get_weight() . ' ' . esc_attr(get_option('woocommerce_weight_unit')), 'dimensions' => $variation->get_dimensions(), 'min_qty' => 1, 'max_qty' => $variation->backorders_allowed() ? '' : $variation->get_stock_quantity(), 'backorders_allowed' => $variation->backorders_allowed(), 'is_in_stock' => $variation->is_in_stock(), 'is_downloadable' => $variation->is_downloadable(), 'is_virtual' => $variation->is_virtual(), 'is_sold_individually' => $variation->is_sold_individually() ? 'yes' : 'no', 'variation_description' => $variation->get_variation_description()), $this, $variation);
 }
 function widget($args, $instance)
 {
     extract($args);
     $title = apply_filters('widget_title', $instance['title']);
     $largeitems = intval($instance['largeitems']);
     $mediumitems = intval($instance['mediumitems']);
     $thumbnailitems = intval($instance['thumbnailitems']);
     $listitems = intval($instance['listitems']);
     $showexcerpt = $instance['showexcerpt'];
     $acf_key = "widget_" . $this->id_base . "-" . $this->number . "_pin_stories";
     $top_slot = get_option($acf_key);
     $acf_key = "widget_" . $this->id_base . "-" . $this->number . "_exclude_stories";
     $exclude = get_option($acf_key);
     $acf_key = "widget_" . $this->id_base . "-" . $this->number . "_news_listing_news_type";
     $newstypes = get_option($acf_key);
     if (!$title) {
         $title = "no_title_" . $id;
     }
     $moretitle = $instance['moretitle'];
     global $post;
     $removenews = get_transient('cached_removenews');
     if (!$removenews || !is_array($removenews)) {
         set_transient('cached_removenews', "wait", 60 * 3);
         //process expired news
         $tzone = get_option('timezone_string');
         date_default_timezone_set($tzone);
         $tdate = date('Ymd');
         $oldnews = query_posts(array('post_type' => 'news', 'meta_query' => array(array('key' => 'news_expiry_date', 'value' => $tdate, 'compare' => '<='))));
         if (count($oldnews) > 0) {
             foreach ($oldnews as $old) {
                 if ($tdate == date('Ymd', strtotime(get_post_meta($old->ID, 'news_expiry_date', true)))) {
                     // if expiry today, check the time
                     if (date('H:i:s', strtotime(get_post_meta($old->ID, 'news_expiry_time', true))) > date('H:i:s')) {
                         continue;
                     }
                 }
                 $expiryaction = get_post_meta($old->ID, 'news_expiry_action', true);
                 if ($expiryaction == 'Revert to draft status') {
                     $my_post = array();
                     $my_post['ID'] = $old->ID;
                     $my_post['post_status'] = 'draft';
                     wp_update_post($my_post);
                     delete_post_meta($old->ID, 'news_expiry_date');
                     delete_post_meta($old->ID, 'news_expiry_time');
                     delete_post_meta($old->ID, 'news_expiry_action');
                     delete_post_meta($old->ID, 'news_auto_expiry');
                     if (function_exists('wp_cache_post_change')) {
                         wp_cache_post_change($old->ID);
                     }
                     if (function_exists('wp_cache_post_change')) {
                         wp_cache_post_change($my_post);
                     }
                 }
                 if ($expiryaction == 'Change to regular news') {
                     set_post_format($old->ID, '');
                     delete_post_meta($old->ID, 'news_expiry_date');
                     delete_post_meta($old->ID, 'news_expiry_time');
                     delete_post_meta($old->ID, 'news_expiry_action');
                     delete_post_meta($old->ID, 'news_auto_expiry');
                     if (function_exists('wp_cache_post_change')) {
                         wp_cache_post_change($old->ID);
                     }
                 }
                 if ($expiryaction == 'Move to trash') {
                     $my_post = array();
                     $my_post['ID'] = $old->ID;
                     $my_post['post_status'] = 'trash';
                     delete_post_meta($old->ID, 'news_expiry_date');
                     delete_post_meta($old->ID, 'news_expiry_time');
                     delete_post_meta($old->ID, 'news_expiry_action');
                     delete_post_meta($old->ID, 'news_auto_expiry');
                     wp_update_post($my_post);
                     if (function_exists('wp_cache_post_change')) {
                         wp_cache_post_change($old->ID);
                     }
                     if (function_exists('wp_cache_post_change')) {
                         wp_cache_post_change($my_post);
                     }
                 }
             }
         }
         wp_reset_query();
     }
     echo $before_widget;
     if ($title && $title != "no_title_" . $id) {
         echo $before_title;
         echo $title;
         echo $after_title;
     }
     echo '<div id="ht-feature-news">';
     //formulate grid of news stories and formats
     $totalstories = $largeitems + $mediumitems + $thumbnailitems + $listitems;
     $newsgrid = array();
     for ($i = 1; $i <= $totalstories; $i++) {
         if ($i <= $largeitems) {
             $newsgrid[] = "L";
         } elseif ($i <= $largeitems + $mediumitems) {
             $newsgrid[] = "M";
         } elseif ($i <= $largeitems + $mediumitems + $thumbnailitems) {
             $newsgrid[] = "T";
         } elseif ($i <= $largeitems + $mediumitems + $thumbnailitems + $listitems) {
             $newsgrid[] = "Li";
         }
     }
     $siteurl = site_url();
     //manual override news stories
     //display sticky top news stories
     $num_top_slots = count($top_slot);
     $to_fill = $totalstories - $num_top_slots;
     $k = -1;
     $alreadydone = array();
     if ($num_top_slots > 0) {
         foreach ((array) $top_slot as $thisslot) {
             if (!$thisslot) {
                 continue;
             }
             $slot = get_post($thisslot);
             if ($slot->post_status != 'publish') {
                 continue;
             }
             $k++;
             $alreadydone[] = $slot->ID;
             if (function_exists('get_video_thumbnail')) {
                 $videostill = get_video_thumbnail($slot->ID);
             }
             $thistitle = $slot->post_title;
             $thisURL = get_permalink($slot->ID);
             $video = 0;
             if (has_post_format('video', $slot->ID)) {
                 $video = apply_filters('the_content', get_post_meta($slot->ID, 'news_video_url', true));
             }
             if ($newsgrid[$k] == "L") {
                 if ($video) {
                     echo $video;
                 } elseif (has_post_thumbnail($post->ID)) {
                     $img_srcset = wp_get_attachment_image_srcset(get_post_thumbnail_id($post->ID), array('newshead', 'large', 'medium', 'thumbnail'));
                     $img_sizes = wp_get_attachment_image_sizes(get_post_thumbnail_id($post->ID), 'newshead');
                     echo "<a href='{$thisURL}'>" . get_the_post_thumbnail($post->ID, 'newshead', array('class' => 'img-responsive')) . "</a>";
                     echo wpautop("<p class='news_date'>" . get_post_thumbnail_caption() . "</p>");
                 }
             }
             if ($newsgrid[$k] == "M") {
                 $image_uri = wp_get_attachment_image_src(get_post_thumbnail_id($slot->ID), 'newsmedium');
                 if ($image_uri != "") {
                     echo "<a href='{$thisURL}'><img class='img img-responsive' src='{$image_uri[0]}' width='{$image_uri[1]}' height='{$image_uri[2]}' alt='" . govintranetpress_custom_title($slot->post_title) . "' /></a>";
                 }
             }
             if ($newsgrid[$k] == "T") {
                 $image_uri = "<a class='pull-right' href='" . $thisURL . "'>" . get_the_post_thumbnail($slot->ID, 'thumbnail', array('class' => 'media-object hidden-xs')) . "</a>";
                 if ($image_uri != "") {
                     $image_url = $image_uri;
                 }
             }
             $thisdate = $slot->post_date;
             $post = get_post($slot->ID);
             setup_postdata($post);
             $thisexcerpt = get_the_excerpt();
             $thisdate = date(get_option('date_format'), strtotime($thisdate));
             $ext_icon = '';
             if (get_post_format($slot->ID) == 'link') {
                 $ext_icon = "<span class='dashicons dashicons-migrate'></span> ";
             }
             if ($newsgrid[$k] == "T") {
                 echo "<div class='media'>" . $image_url;
             }
             echo "<div class='media-body'>";
             echo "<h3 class='noborder'>" . $ext_icon . "<a href='" . $thisURL . "'>" . $thistitle . "</a>" . $ext_icon . "</h3>";
             if ($newsgrid[$k] == "Li") {
                 echo "<p>";
                 echo '<span class="listglyph">' . get_the_date(get_option('date_format'));
                 echo '</span> ';
                 echo " <span class='badge'>Featured</span>";
                 if (get_comments_number()) {
                     echo "<a href='" . $thisURL . "#comments'>";
                     printf(_n('<span class="badge">1 comment</span>', '<span class="badge">%d comments</span>', get_comments_number(), 'govintranet'), get_comments_number());
                     echo "</a>";
                 }
                 echo " <a class='news_date more' href='{$thisURL}' title='{$thistitle}'>" . __('Full story', 'govintranet') . " <span class='dashicons dashicons-arrow-right-alt2'></span></a></span></p>";
             } else {
                 if ($showexcerpt == 'on') {
                     echo "<p>";
                     echo '<span class="listglyph">' . get_the_date(get_option('date_format'));
                     echo '</span> ';
                     echo " <span class='badge'>" . __('Featured', 'govitranet') . "</span>";
                     if (get_comments_number()) {
                         echo "<a href='" . $thisURL . "#comments'>";
                         printf(_n('<span class="badge">1 comment</span>', '<span class="badge">%d comments</span>', get_comments_number(), 'govintranet'), get_comments_number());
                         echo "</a>";
                     }
                     echo "</p>";
                     echo $thisexcerpt;
                     echo "<p class='news_date'><a class='more' href='{$thisURL}' title='{$thistitle}'>" . __('Full story', 'govintranet') . " <span class='dashicons dashicons-arrow-right-alt2'></span></a></p>";
                 } else {
                     echo "<p>";
                     echo '<span class="listglyph">' . get_the_date(get_option('date_format'));
                     echo '</span> ';
                     echo " <span class='badge'>" . __('Featured', 'govitranet') . "</span>";
                     if (get_comments_number()) {
                         echo "<a href='" . $thisURL . "#comments'>";
                         printf(_n('<span class="badge">1 comment</span>', '<span class="badge">%d comments</span>', get_comments_number(), 'govintranet'), get_comments_number());
                         echo "</a>";
                     }
                     echo " <a class='news_date more' href='{$thisURL}' title='{$thistitle}'>" . __('Full story', 'govintranet') . " <span class='dashicons dashicons-arrow-right-alt2'></span></a></span></p>";
                 }
             }
             echo "</div>";
             if ($newsgrid[$k] == "T") {
                 echo "</div>";
             }
             echo "<hr class='light' />\n";
         }
     }
     //end of stickies
     //display remaining stories
     $cquery = array('post_type' => 'news', 'posts_per_page' => $totalstories, 'post__not_in' => $exclude, 'tax_query' => array(array('taxonomy' => 'post_format', 'field' => 'slug', 'terms' => array('post-format-status'), "operator" => "NOT IN")));
     if ($newstypes) {
         $cquery['tax_query'] = array("relation" => "AND", array('taxonomy' => 'news-type', 'terms' => $newstypes, 'field' => 'id'), array('taxonomy' => 'post_format', 'field' => 'slug', 'terms' => array('post-format-status'), "operator" => "NOT IN"));
     }
     $news = new WP_Query($cquery);
     if ($news->post_count == 0) {
         echo "Nothing to show.";
     }
     global $post;
     while ($news->have_posts()) {
         $news->the_post();
         $theid = get_the_id();
         if (in_array($theid, $alreadydone)) {
             //don't show if already in stickies
             continue;
         }
         $k++;
         if ($k >= $totalstories) {
             break;
         }
         $thistitle = get_the_title($theid);
         $thisURL = get_permalink($theid);
         $video = 0;
         if (has_post_format('video', $theid)) {
             $video = apply_filters('the_content', get_post_meta($theid, 'news_video_url', true));
         }
         if ($newsgrid[$k] == "L") {
             if ($video) {
                 echo $video;
             } elseif (has_post_thumbnail($post->ID)) {
                 $img_srcset = wp_get_attachment_image_srcset(get_post_thumbnail_id($post->ID), array('newshead', 'large', 'medium', 'thumbnail'));
                 $img_sizes = wp_get_attachment_image_sizes(get_post_thumbnail_id($post->ID), 'newshead');
                 echo "<a href='{$thisURL}'>" . get_the_post_thumbnail($post->ID, 'newshead', array('class' => 'img-responsive')) . "</a>";
                 echo wpautop("<p class='news_date'>" . get_post_thumbnail_caption() . "</p>");
             }
         }
         if ($newsgrid[$k] == "M") {
             $image_uri = wp_get_attachment_image_src(get_post_thumbnail_id($theid), 'newsmedium');
             if ($image_uri != "") {
                 echo "<a href='{$thisURL}'><img class='img img-responsive' src='{$image_uri[0]}' width='{$image_uri[1]}' height='{$image_uri[2]}' alt='" . govintranetpress_custom_title($post->post_title) . "' /></a>";
             }
         }
         if ($newsgrid[$k] == "T") {
             $image_uri = "<a class='pull-right' href='{$thisURL}'>" . get_the_post_thumbnail($theid, 'thumbnail', array('class' => 'media-object hidden-xs')) . "</a>";
             if ($image_uri != "") {
                 $image_url = $image_uri;
             }
         }
         $thisdate = get_the_date(get_option('date_format'));
         $thisexcerpt = get_the_excerpt();
         $ext_icon = '';
         if ($newsgrid[$k] == "T") {
             echo "<div class='media'>" . $image_url;
         }
         echo "<div class='media-body feature-news-" . strtolower($newsgrid[$k]) . "'>";
         if (get_post_format($theid) == 'link') {
             $ext_icon = "<i class='dashicons dashicons-migrate'></i> ";
         }
         echo "<h3 class='noborder'><a href='" . $thisURL . "'>" . $thistitle . "</a> " . $ext_icon . "</h3>";
         if ($newsgrid[$k] == "Li") {
             echo "<p>";
             echo '<span class="listglyph">' . get_the_date(get_option('date_format'));
             echo '</span> ';
             if (get_comments_number()) {
                 echo "<a href='" . $thisURL . "#comments'>";
                 printf(_n('<span class="badge">1 comment</span>', '<span class="badge">%d comments</span>', get_comments_number(), 'govintranet'), get_comments_number());
                 echo "</a>";
             }
             echo "</p>";
         } else {
             if ($showexcerpt == 'on') {
                 echo "<p>";
                 echo '<span class="listglyph">' . get_the_date(get_option('date_format'));
                 echo '</span> ';
                 if (get_comments_number()) {
                     echo " <a href='" . $thisURL . "#comments'>";
                     printf(_n('<span class="badge">1 comment</span>', '<span class="badge">%d comments</span>', get_comments_number(), 'govintranet'), get_comments_number());
                     echo "</a>";
                 }
                 echo "</p>";
                 echo $thisexcerpt;
                 echo "<p class='news_date'><a class='more' href='{$thisURL}' title='{$thistitle}'>" . __('Full story', 'govintranet') . " <span class='dashicons dashicons-arrow-right-alt2'></span></a></p>";
             } else {
                 echo "<p>";
                 echo '<span class="listglyph">' . get_the_date(get_option('date_format'));
                 echo '</span> ';
                 if (get_comments_number()) {
                     echo " <a href='" . $thisURL . "#comments'>";
                     printf(_n('<span class="badge">1 comment</span>', '<span class="badge">%d comments</span>', get_comments_number(), 'govintranet'), get_comments_number());
                     echo "</a>";
                 }
                 echo " <a class='news_date more' href='{$thisURL}' title='{$thistitle}'>" . __('Full story', 'govintranet') . " <span class='dashicons dashicons-arrow-right-alt2'></span></a></p>";
             }
         }
         echo "</div>";
         if ($newsgrid[$k] == "T") {
             echo "</div>";
         }
         echo "<hr class='light' />\n";
     }
     wp_reset_query();
     $landingpage = get_option('options_module_news_page');
     if (!$landingpage) {
         $landingpage_link_text = 'news';
         $landingpage = site_url() . '/newspage/';
     } else {
         $landingpage_link_text = get_the_title($landingpage[0]);
         $landingpage = get_permalink($landingpage[0]);
     }
     if (!$moretitle) {
         $moretitle = $title;
     }
     if ($moretitle = "no_title_" . $id) {
         $moretitle = __("More", "govintranet");
     }
     if (is_array($newstypes) && count($newstypes) < 2) {
         $term = intval($newstypes[0]);
         $landingpage = get_term_link($term, 'news-type');
         echo '<p class="more-updates"><strong><a title="' . $landingpage_link_text . '" class="small" href="' . $landingpage . '">' . $moretitle . '</a></strong> <span class="dashicons dashicons-arrow-right-alt2"></span></p>';
     } else {
         $landingpage_link_text = $moretitle;
         echo '<p class="more-updates"><strong><a title="' . $landingpage_link_text . '" class="small" href="' . $landingpage . '">' . $landingpage_link_text . '</a></strong> <span class="dashicons dashicons-arrow-right-alt2"></span></p>';
     }
     echo "<div class='clearfix'></div>";
     echo "</div>";
     echo $after_widget;
 }
Exemple #10
0
/**
 * Retrieves the value for an image attachment’s ‘sizes’ attribute
 *
 * @since  1.0.0
 * @access protected
 * @param  int   $id The ID of the current attachment.
 * @param  array $args Arguments for how to load and display the image.
 * @return false|string A 'sizes' value string or false.
 */
function _carelib_image_get_sizes($id, $args)
{
    if (!$args['responsive'] || !function_exists('wp_get_attachment_image_srcset')) {
        return false;
    }
    return wp_get_attachment_image_sizes($id, $args['size']);
}
            // case 'video':
            // 	$video = get_post_meta( $post_ID, 'uxr_event_flexible_content_' . $count . '_video', true);
            // 	if ( isset($video) && !empty($video) ) :
            // 		echo apply_filters('the_content', $video) . "\n";
            // 	endif;
            // break;
            //
            // Image
            //
            case 'fullwidth_image':
                $image_ID = get_post_meta($post_ID, 'uxr_event_flexible_content_' . $count . '_fullwidth_image', true);
                if (isset($image_ID) && !empty($image_ID)) {
                    // Image source
                    $img_src = wp_get_attachment_image_url($image_ID, 'large');
                    $img_srcset = wp_get_attachment_image_srcset($image_ID, 'large');
                    $img_sizes = wp_get_attachment_image_sizes($image_ID, 'large');
                    // Image meta
                    $image_meta = get_posts(array('p' => $image_ID, 'post_type' => 'attachment'));
                    $image_caption = $image_meta[0]->post_excerpt;
                    $image_more_meta = wp_get_attachment_metadata($image_ID, 'large');
                    echo "\t" . '</div>' . "\n";
                    echo '</div>' . "\n";
                    echo '<img src="' . esc_url($img_src) . '" srcset="' . esc_attr($img_srcset) . '" sizes="' . esc_attr($img_sizes) . '" alt="" class="uxr-asset-fullwidth" />';
                    echo '<div class="uxr-grid-container">' . "\n";
                    echo "\t" . '<div class="uxr-contrib">' . "\n";
                }
                break;
        }
    }
}
?>
Exemple #12
0
/**
 * Display deck of cards using Bootstrap's carousel
 *
 * @param int   $deck The ID of the card deck.
 * @param array $args Array of arguments to affect output.
 */
function msx_card_deck_carousel($deck, $args = array())
{
    $defaults = array('container_class' => 'carousel slide', 'container_id' => 'carousel-' . $deck, 'deck_class' => 'carousel-inner msx-card-deck', 'deck_id' => 'msx-card-deck-' . $deck, 'card_class' => 'item', 'image_size' => 'full', 'indicators' => true, 'controls' => false);
    $args = wp_parse_args($args, $defaults);
    $deck = (int) $deck;
    $card_deck = get_post($deck);
    if (!empty($card_deck)) {
        $output = '';
        $deck_custom = get_post_custom($card_deck->ID);
        $cards_list = explode(',', $deck_custom['cards_order'][0]);
        $cards = get_posts(array('post_type' => 'msx_card', 'post__in' => $cards_list, 'orderby' => 'post__in', 'order' => 'ASC'));
        // Add the carousel wrapper.
        $output .= '<div class="' . $args['container_class'] . '" id="' . $args['container_id'] . '" data-ride="carousel">';
        // Display indicators.
        if (!false == $args['indicators']) {
            $i = 0;
            $output .= '<ol class="carousel-indicators">';
            foreach ($cards as $card) {
                if (!empty($card)) {
                    if (0 == $i) {
                        $output .= '<li data-target="#' . $args['container_id'] . '" data-slide-to="0" class="active"></li>';
                    } else {
                        $output .= '<li data-target="#' . $args['container_id'] . '" data-slide-to="' . $i . '"></li>';
                    }
                    $i++;
                }
            }
            $output .= '</ol>';
        }
        // Start the decks of cards.
        $output .= '<div class="' . $args['deck_class'] . '" id="' . $args['deck_id'] . '">';
        // Display the cards.
        $c = 0;
        foreach ($cards as $card) {
            if (!empty($card)) {
                $c++;
                $custom = get_post_custom($card->ID);
                $format = get_post_format($card->ID);
                $card_class = 1 == $c ? $args['card_class'] . ' active' : $args['card_class'];
                $output .= sprintf('<div class="%1$s msx-card msx-card-%2$s" id="msx-card-%3$s">', $card_class, $format, $card->ID);
                switch ($format) {
                    case 'image':
                        $img_src = wp_get_attachment_image_url($custom['image'][0], $args['image_size']);
                        $img_src_set = wp_get_attachment_image_srcset($custom['image'][0], $args['image_size']);
                        $img_sizes = wp_get_attachment_image_sizes($custom['image'][0], $args['image_size']);
                        $output .= !empty($custom['target'][0]) ? '<a href="' . $custom['target'][0] . '" title="' . $card->post_title . '">' : '';
                        $output .= sprintf('<img src="%1$s" srcset="%2$s" sizes="%3$s" alt="%4$s">', $img_src, $img_src_set, $img_sizes, $card->post_title);
                        $output .= !empty($custom['target'][0]) ? '</a>' : '';
                        break;
                    case 'video':
                        $video_meta = wp_get_attachment_metadata($custom['video'][0]);
                        $video_url = wp_get_attachment_url($custom['video'][0]);
                        $video_source = sprintf('<source src="%1$s" type="%2$s">', $video_url, get_post_mime_type($custom['video'][0]));
                        $image = wp_get_attachment_image_src(get_post_thumbnail_id($card->ID), $args['image_size']);
                        $output .= sprintf('<video width="%1$s" height="%2$s" poster="%3$s" controls>%4$s</video>', $video_meta['width'], $video_meta['height'], $image[0], $video_source);
                        break;
                    case 'link':
                        if (!empty($custom['video'][0])) {
                            $output .= '<div class="embed-responsive embed-responsive-16by9">';
                            $output .= '<iframe src="' . $custom['video'][0] . '" autoload noborder></iframe>';
                            $output .= '</div>';
                        }
                        break;
                }
                $output .= '<div class="carousel-caption">';
                $output .= '<h4 class="msx-card-title">' . $card->post_title . '</h4>';
                $output .= '<p class="msx-card-content">' . $card->post_content . '</p>';
                $output .= '</div>';
                $output .= '</div>';
            }
        }
        // End the deck of cards.
        $output .= '</div>';
        if (!false == $args['controls']) {
            $output .= '<a class="left carousel-control" href="#' . $args['container_id'] . '" role="button" data-slide="prev">';
            $output .= '<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>';
            $output .= '<span class="sr-only">Previous</span>';
            $output .= '</a>';
            $output .= '<a class="right carousel-control" href="#' . $args['container_id'] . '" role="button" data-slide="next">';
            $output .= '<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>';
            $output .= '<span class="sr-only">Next</span>';
            $output .= '</a>';
        }
        $output .= '</div>';
        echo $output;
    }
}
        echo '<div class="wpcw_fe_progress_box_wrap"><div class="wpcw_fe_progress_box wpcw_fe_progress_box_error">Please log in to access these videos. <a class="button orange" href="/wp-admin/">Log in here</a></div></div>';
    }
    the_content();
    // WP_Query arguments
    $args = array('post_parent' => $post->ID, 'post_type' => array('page'), 'orderby' => 'menu_order', 'order' => 'ASC');
    // The Query
    $modules_query = new WP_Query($args);
    // The Loop
    if ($modules_query->have_posts()) {
        echo '<section class="module-container">';
        while ($modules_query->have_posts()) {
            $modules_query->the_post();
            $landing_page_image = get_field('landing_page_image');
            echo '<section class="module ' . $post->post_name . '">';
            echo '<a href="' . get_permalink() . '">';
            echo '<img src="' . esc_url($landing_page_image['url']) . '" alt="' . esc_attr($landing_page_image['alt']) . '" srcset="' . esc_attr(wp_get_attachment_image_srcset($landing_page_image['id'])) . '" sizes="' . esc_attr(wp_get_attachment_image_sizes($landing_page_image['id'])) . '" />';
            echo '<h2>' . get_the_title() . '</h2>';
            echo '</a>';
            echo '</section>';
        }
        echo '</section><!-- .module-container -->';
    }
    // Restore original Post Data
    wp_reset_postdata();
    ?>
                </div><!-- .entry-content -->

                <?php 
    edit_post_link(sprintf(__('Edit<span class="screen-reader-text"> "%s"</span>', 'twentysixteen'), the_title('', '', false)), '<footer class="entry-footer"><span class="edit-link">', '</span></footer><!-- .entry-footer -->');
    ?>
/** 
 * Build responsive image meta
 */
function build_responsive_image_meta($media_id, $size_max = 'full', $size_small = 'medium')
{
    // Get meta
    $media_meta = wp_get_attachment_metadata($media_id);
    $return = ['srcset' => wp_get_attachment_image_srcset($media_id, $size_max, $media_meta), 'size' => wp_get_attachment_image_sizes($media_id, $size_max), 'src' => wp_get_attachment_image_src($media_id, $size_small), 'meta' => $media_meta];
    //$return['meta']['caption'] = get_the_excerpt( $media_id );
    //print_r($return);die();
    return $return;
}
 /**
  * Get the HTML for the image attached to this menu item
  *
  * Any set img ID will override image src filtering
  * 
  * @return string img HTML
  */
 function get_image()
 {
     //Ignore mobile?
     if ($this->get_menu_op('disable_images_mobile') == 'on' && ubermenu_is_mobile('disable_images_mobile')) {
         return '';
     }
     //Image
     $img = apply_filters('ubermenu_item_image', '', $this);
     if ($img) {
         return $img;
     }
     //Allow ID filtering
     $img_id = apply_filters('ubermenu_item_image_id', $this->getSetting('item_image'), $this);
     //Allow src filtering
     $img_src = apply_filters('ubermenu_item_image_src', '', $this);
     //Inherit featured image dynamically
     if ($this->getSetting('inherit_featured_image') == 'on') {
         if ($this->item->type == 'post_type') {
             $thumb_id = get_post_thumbnail_id($this->item->object_id);
             if ($thumb_id) {
                 $img_id = $thumb_id;
             }
         }
     }
     if ($img_id || $img_src) {
         $atts = array();
         $img_srcset = $img_sizes = '';
         $atts['class'] = 'ubermenu-image';
         //Determine size of image to get
         $img_size = $this->getSetting('image_size');
         if ($img_size == 'inherit') {
             $img_size = $this->get_menu_op('image_size');
         }
         //echo '['.$img_size.']';
         $atts['class'] .= ' ubermenu-image-size-' . $img_size;
         //If the img_id is set, get the right image src file
         if ($img_id) {
             $img_src = wp_get_attachment_image_src($img_id, $img_size);
             if (function_exists('wp_get_attachment_image_srcset')) {
                 $img_srcset = wp_get_attachment_image_srcset($img_id, $img_size);
                 $img_sizes = wp_get_attachment_image_sizes($img_id, $img_size);
             }
         }
         //Lazy Load
         if ($this->depth > 0 && $this->get_menu_op('lazy_load_images') == 'on') {
             $atts['class'] .= ' ubermenu-image-lazyload';
             $atts['data-src'] = $img_src[0];
             if ($img_srcset) {
                 $atts['data-srcset'] = $img_srcset;
                 if ($img_sizes) {
                     $atts['data-sizes'] = $img_sizes;
                 }
             }
         } else {
             $atts['src'] = $img_src[0];
             if ($img_srcset) {
                 $atts['srcset'] = $img_srcset;
                 if ($img_sizes) {
                     $atts['sizes'] = $img_sizes;
                 }
             }
         }
         //Determine dimensions
         $img_w = '';
         $img_h = '';
         $dimensions = $this->getSetting('image_dimensions');
         switch ($dimensions) {
             //Custom Dimensions use Menu Item Settings
             case 'custom':
                 $img_w = $this->getSetting('image_width_custom');
                 $img_h = $this->getSetting('image_height_custom');
                 break;
                 //Inherit settings from main Menu Settings
             //Inherit settings from main Menu Settings
             case 'inherit':
                 $img_w = $this->get_menu_op('image_width');
                 $img_h = $this->get_menu_op('image_height');
                 break;
                 //Add width and height atts for natural width
             //Add width and height atts for natural width
             case 'natural':
                 //Done below
                 break;
             default:
                 break;
         }
         //Apply natural dimensions if not already set
         if ($this->get_menu_op('image_set_dimensions')) {
             if ($img_w == '' && $img_h == '') {
                 $img_w = $img_src[1];
                 $img_h = $img_src[2];
             }
         }
         //Add dimensions as attributes, with pixel units if missing
         if ($img_w) {
             //if( is_numeric( $img_w ) ) $img_w.='px';	//Should always be numeric only, no units
             $atts['width'] = $img_w;
         }
         if ($img_h) {
             //if( is_numeric( $img_h ) ) $img_h.='px';	//Should always be numeric only, no units
             $atts['height'] = $img_h;
         }
         //Add 'alt' & 'title'
         if ($img_id) {
             $meta = get_post_custom($img_id);
             $alt = isset($meta['_wp_attachment_image_alt']) ? $meta['_wp_attachment_image_alt'][0] : '';
             //Alt field
             $title = '';
             if ($alt == '') {
                 $title = get_the_title($img_id);
                 $alt = $title;
             }
             $atts['alt'] = $alt;
             if ($this->get_menu_op('image_title_attribute') == 'on') {
                 if ($title == '') {
                     $title = get_the_title($img_id);
                 }
                 $atts['title'] = $title;
             }
         }
         //Build attributes string
         $atts = apply_filters('ubermenu_item_image_attributes', $atts, $this);
         $attributes = '';
         foreach ($atts as $name => $val) {
             $attributes .= $name . '="' . esc_attr($val) . '" ';
         }
         $img = "<img {$attributes} />";
         //$img = "<span class='ubermenu-image'><img $attributes /></span>";
     }
     return $img;
 }
Exemple #16
0
    /**
     * @ticket 33641
     */
    function test_wp_make_content_images_responsive()
    {
        $image_meta = wp_get_attachment_metadata(self::$large_id);
        $size_array = $this->_get_image_size_array_from_name('medium');
        $srcset = sprintf('srcset="%s"', wp_get_attachment_image_srcset(self::$large_id, $size_array, $image_meta));
        $sizes = sprintf('sizes="%s"', wp_get_attachment_image_sizes(self::$large_id, $size_array, $image_meta));
        // Function used to build HTML for the editor.
        $img = get_image_tag(self::$large_id, '', '', '', 'medium');
        $img_no_size_in_class = str_replace('size-', '', $img);
        $img_no_width_height = str_replace(' width="' . $size_array[0] . '"', '', $img);
        $img_no_width_height = str_replace(' height="' . $size_array[1] . '"', '', $img_no_width_height);
        $img_no_size_id = str_replace('wp-image-', 'id-', $img);
        $img_with_sizes_attr = str_replace('<img ', '<img sizes="99vw" ', $img);
        $img_xhtml = str_replace(' />', '/>', $img);
        $img_html5 = str_replace(' />', '>', $img);
        // Manually add srcset and sizes to the markup from get_image_tag();
        $respimg = preg_replace('|<img ([^>]+) />|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img);
        $respimg_no_size_in_class = preg_replace('|<img ([^>]+) />|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img_no_size_in_class);
        $respimg_no_width_height = preg_replace('|<img ([^>]+) />|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img_no_width_height);
        $respimg_with_sizes_attr = preg_replace('|<img ([^>]+) />|', '<img $1 ' . $srcset . ' />', $img_with_sizes_attr);
        $respimg_xhtml = preg_replace('|<img ([^>]+)/>|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img_xhtml);
        $respimg_html5 = preg_replace('|<img ([^>]+)>|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img_html5);
        $content = '
			<p>Image, standard. Should have srcset and sizes.</p>
			%1$s

			<p>Image, no size class. Should have srcset and sizes.</p>
			%2$s

			<p>Image, no width and height attributes. Should have srcset and sizes (from matching the file name).</p>
			%3$s

			<p>Image, no attachment ID class. Should NOT have srcset and sizes.</p>
			%4$s

			<p>Image, with sizes attribute. Should NOT have two sizes attributes.</p>
			%5$s

			<p>Image, XHTML 1.0 style (no space before the closing slash). Should have srcset and sizes.</p>
			%6$s

			<p>Image, HTML 5.0 style. Should have srcset and sizes.</p>
			%7$s';
        $content_unfiltered = sprintf($content, $img, $img_no_size_in_class, $img_no_width_height, $img_no_size_id, $img_with_sizes_attr, $img_xhtml, $img_html5);
        $content_filtered = sprintf($content, $respimg, $respimg_no_size_in_class, $respimg_no_width_height, $img_no_size_id, $respimg_with_sizes_attr, $respimg_xhtml, $respimg_html5);
        $this->assertSame($content_filtered, wp_make_content_images_responsive($content_unfiltered));
    }
        echo $slide->post_title;
        ?>
" >
            <?php 
        if (get_field('second', $slide->ID)) {
            $image_obj = get_field('second', $slide->ID);
            $default_attr = array('class' => "wp-post-image");
            $image_id = $image_obj["id"];
            $image_meta = wp_get_attachment_metadata($image_id);
            $image = wp_get_attachment_image_src($image_id, 'full');
            if ($image) {
                $image_src = $image[0];
                $size_array = array(absint($image[1]), absint($image[2]));
            }
            $srcset_value = wp_calculate_image_srcset($size_array, $image_src, $image_meta);
            $sizes_value = wp_get_attachment_image_sizes($image_id, 'full');
            $srcset = $srcset_value ? ' srcset="' . esc_attr($srcset_value) . '"' : '';
            $sizes = $sizes_value ? ' sizes="' . esc_attr($sizes_value) . '"' : '';
            ?>
              <picture>
  <source media="(max-width: 49.999em)" <?php 
            echo $srcset;
            ?>
 <?php 
            echo $sizes;
            ?>
 >
<?php 
            echo get_the_post_thumbnail($slide->ID);
            ?>
Exemple #18
0
    /**
     * @ticket 33641
     */
    function test_wp_make_content_images_responsive()
    {
        $srcset = sprintf('srcset="%s"', wp_get_attachment_image_srcset(self::$large_id, 'medium'));
        $sizes = sprintf('sizes="%s"', wp_get_attachment_image_sizes(self::$large_id, 'medium'));
        // Function used to build HTML for the editor.
        $img = get_image_tag(self::$large_id, '', '', '', 'medium');
        $img_no_size = str_replace('size-', '', $img);
        $img_no_size_id = str_replace('wp-image-', 'id-', $img_no_size);
        // Manually add srcset and sizes to the markup from get_image_tag();
        $respimg = preg_replace('|<img ([^>]+) />|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img);
        $respimg_no_size = preg_replace('|<img ([^>]+) />|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img_no_size);
        $content = '<p>Welcome to WordPress!  This post contains important information.  After you read it, you can make it private to hide it from visitors but still have the information handy for future reference.</p>
			<p>First things first:</p>

			%1$s

			<ul>
			<li><a href="http://wordpress.org" title="Subscribe to the WordPress mailing list for Release Notifications">Subscribe to the WordPress mailing list for release notifications</a></li>
			</ul>

			%2$s

			<p>As a subscriber, you will receive an email every time an update is available (and only then).  This will make it easier to keep your site up to date, and secure from evildoers.<br />
			When a new version is released, <a href="http://wordpress.org" title="If you are already logged in, this will take you directly to the Dashboard">log in to the Dashboard</a> and follow the instructions.<br />
			Upgrading is a couple of clicks!</p>

			%3$s

			<p>Then you can start enjoying the WordPress experience:</p>
			<ul>
			<li>Edit your personal information at <a href="http://wordpress.org" title="Edit settings like your password, your display name and your contact information">Users &#8250; Your Profile</a></li>
			<li>Start publishing at <a href="http://wordpress.org" title="Create a new post">Posts &#8250; Add New</a> and at <a href="http://wordpress.org" title="Create a new page">Pages &#8250; Add New</a></li>
			<li>Browse and install plugins at <a href="http://wordpress.org" title="Browse and install plugins at the official WordPress repository directly from your Dashboard">Plugins &#8250; Add New</a></li>
			<li>Browse and install themes at <a href="http://wordpress.org" title="Browse and install themes at the official WordPress repository directly from your Dashboard">Appearance &#8250; Add New Themes</a></li>
			<li>Modify and prettify your website&#8217;s links at <a href="http://wordpress.org" title="For example, select a link structure like: http://example.com/1999/12/post-name">Settings &#8250; Permalinks</a></li>
			<li>Import content from another system or WordPress site at <a href="http://wordpress.org" title="WordPress comes with importers for the most common publishing systems">Tools &#8250; Import</a></li>
			<li>Find answers to your questions at the <a href="http://wordpress.orgs" title="The official WordPress documentation, maintained by the WordPress community">WordPress Codex</a></li>
			</ul>';
        $content_unfiltered = sprintf($content, $img, $img_no_size, $img_no_size_id);
        $content_filtered = sprintf($content, $respimg, $respimg_no_size, $img_no_size_id);
        $this->assertSame($content_filtered, wp_make_content_images_responsive($content_unfiltered));
    }
/**
 * Adds 'srcset' and 'sizes' attributes to an existing 'img' element.
 *
 * @since 4.4.0
 *
 * @see 'wp_get_attachment_image_srcset()'
 * @see 'wp_get_attachment_image_sizes()'
 *
 * @param string $image         An HTML 'img' element to be filtered.
 * @param array  $image_meta    The image meta data as returned by 'wp_get_attachment_metadata()'.
 * @param int    $attachment_id Image attachment ID.
 * @return string Converted 'img' element with 'srcset' and 'sizes' attributes added.
 */
function wp_image_add_srcset_and_sizes($image, $image_meta, $attachment_id)
{
    // Ensure the image meta exists.
    if (empty($image_meta['sizes'])) {
        return $image;
    }
    $src = preg_match('/src="([^"]+)"/', $image, $match_src) ? $match_src[1] : '';
    list($src) = explode('?', $src);
    // Return early if we couldn't get the image source.
    if (!$src) {
        return $image;
    }
    // Bail early if an image has been inserted and later edited.
    if (preg_match('/-e[0-9]{13}/', $image_meta['file'], $img_edit_hash) && strpos(wp_basename($src), $img_edit_hash[0]) === false) {
        return $image;
    }
    $width = preg_match('/ width="([0-9]+)"/', $image, $match_width) ? (int) $match_width[1] : 0;
    $height = preg_match('/ height="([0-9]+)"/', $image, $match_height) ? (int) $match_height[1] : 0;
    if (!$width || !$height) {
        /*
         * If attempts to parse the size value failed, attempt to use the image meta data to match
         * the image file name from 'src' against the available sizes for an attachment.
         */
        $image_filename = wp_basename($src);
        if ($image_filename === wp_basename($image_meta['file'])) {
            $width = (int) $image_meta['width'];
            $height = (int) $image_meta['height'];
        } else {
            foreach ($image_meta['sizes'] as $image_size_data) {
                if ($image_filename === $image_size_data['file']) {
                    $width = (int) $image_size_data['width'];
                    $height = (int) $image_size_data['height'];
                    break;
                }
            }
        }
    }
    if (!$width || !$height) {
        return $image;
    }
    $size_array = array($width, $height);
    $srcset = wp_calculate_image_srcset($src, $size_array, $image_meta, $attachment_id);
    if ($srcset) {
        $sizes = wp_get_attachment_image_sizes($size_array, $image_meta, $attachment_id, $src);
    }
    if ($srcset && $sizes) {
        // Format the 'srcset' and 'sizes' string and escape attributes.
        $srcset_and_sizes = sprintf(' srcset="%s" sizes="%s"', esc_attr($srcset), esc_attr($sizes));
        // Add 'srcset' and 'sizes' attributes to the image markup.
        $image = preg_replace('/<img ([^>]+?)[\\/ ]*>/', '<img $1' . $srcset_and_sizes . ' />', $image);
    }
    return $image;
}
/**
 * Returns a 'sizes' attribute.
 *
 * @since 2.2.0
 * @deprecated 3.0.0 Use 'wp_get_attachment_image_sizes()'
 *
 * @see wp_get_attachment_image_sizes()
 *
 * @param int          $id   Image attachment ID.
 * @param array|string $size Image size. Accepts any valid image size, or an array of width and height
 *                           values in pixels (in that order). Default 'medium'.
 * @param array        $args {
 *     Optional. Arguments to retrieve posts.
 *
 *     @type array|string $sizes An array or string containing of size information.
 *     @type int          $width A single width value used in the default 'sizes' string.
 * }
 * @return string|bool A valid source size list as a 'sizes' attribute or false.
 */
function tevkori_get_sizes_string($id, $size = 'medium', $args = null)
{
    _deprecated_function(__FUNCTION__, '3.0.0', 'wp_get_attachment_image_sizes()');
    if ($args) {
        $sizes = tevkori_get_sizes($id, $size, $args);
    } else {
        $sizes = wp_get_attachment_image_sizes($id, $size);
    }
    return $sizes ? 'sizes="' . esc_attr($sizes) . '"' : false;
}
Exemple #21
0
						<?php 
        if (function_exists('bcn_display') && !is_front_page()) {
            bcn_display();
        }
        ?>
					</div>
				</div>
				<?php 
        $video = null;
        //check if a video thumbnail exists, if so we won't use it to display as a headline image
        if (function_exists('get_video_thumbnail')) {
            $video = get_video_thumbnail();
        }
        if (!$video) {
            $img_srcset = wp_get_attachment_image_srcset(get_post_thumbnail_id($post->ID), array('newshead', 'large', 'medium', 'thumbnail'));
            $img_sizes = wp_get_attachment_image_sizes(get_post_thumbnail_id($post->ID), 'newshead');
            if (has_post_thumbnail($post->ID)) {
                echo get_the_post_thumbnail($post->ID, 'newshead', array('class' => 'img-responsive'));
                echo wpautop("<p class='news_date'>" . get_post_thumbnail_caption() . "</p>");
            }
        }
        ?>

				<h1><?php 
        the_title();
        ?>
</h1>
				<?php 
        $article_date = get_the_date();
        $mainid = $post->ID;
        $article_date = date(get_option('date_format'), strtotime($article_date));
    public static function wc_dynamic_gallery_display($product_id = 0)
    {
        /**
         * Single Product Image
         */
        global $post, $wc_dgallery_fonts_face;
        $display_back_and_forward = 'true';
        $no_image_uri = WC_Dynamic_Gallery_Functions::get_no_image_uri();
        if ($product_id < 1) {
            $product_id = $post->ID;
        }
        // Get gallery of this product
        $dgallery_ids = WC_Dynamic_Gallery_Functions::get_gallery_ids($product_id);
        if (!is_array($dgallery_ids)) {
            $dgallery_ids = array();
        }
        $main_dgallery = array();
        $ogrinal_product_id = $product_id;
        $product_id .= '_' . rand(100, 10000);
        $lightbox_class = 'lightbox';
        $thumbs_list_class = '';
        if (count($dgallery_ids) > 0) {
            // Assign image data into main gallery array
            foreach ($dgallery_ids as $img_id) {
                // Check if image id is existed on main gallery then just use it again for decrease query
                if (isset($main_dgallery[$img_id])) {
                    continue;
                }
                $image_data = get_post($img_id);
                $large_image_attribute = wp_get_attachment_image_src($img_id, 'large');
                $thumb_image_attribute = wp_get_attachment_image_src($img_id, 'shop_thumbnail');
                $alt = get_post_meta($img_id, '_wp_attachment_image_alt', true);
                $large_srcset = '';
                $large_sizes = '';
                $thumb_srcset = '';
                $thumb_sizes = '';
                if (function_exists('wp_get_attachment_image_srcset')) {
                    $large_srcset = wp_get_attachment_image_srcset($img_id, 'large');
                    $thumb_srcset = wp_get_attachment_image_srcset($img_id, 'shop_thumbnail');
                }
                if (function_exists('wp_get_attachment_image_sizes')) {
                    $large_sizes = wp_get_attachment_image_sizes($img_id, 'large');
                    $thumb_sizes = wp_get_attachment_image_sizes($img_id, 'shop_thumbnail');
                }
                $main_dgallery[$img_id] = array('caption_text' => $image_data->post_excerpt, 'alt_text' => $alt, 'thumb' => array('url' => $thumb_image_attribute[0], 'width' => $thumb_image_attribute[1], 'height' => $thumb_image_attribute[2], 'img_srcset' => $thumb_srcset, 'img_sizes' => $thumb_sizes), 'large' => array('url' => $large_image_attribute[0], 'width' => $large_image_attribute[1], 'height' => $large_image_attribute[2], 'img_srcset' => $large_srcset, 'img_sizes' => $large_sizes));
            }
        }
        ?>

		<div class="images gallery_container">
			<div class="product_gallery">
            <?php 
        $g_width = get_option(WOO_DYNAMIC_GALLERY_PREFIX . 'product_gallery_width_fixed') . 'px';
        $shop_thumbnail = wc_get_image_size('shop_thumbnail');
        $g_thumb_width = $shop_thumbnail['width'];
        $g_thumb_height = $shop_thumbnail['height'];
        $thumb_show_type = 'slider';
        $thumb_columns = get_option(WOO_DYNAMIC_GALLERY_PREFIX . 'thumb_columns', 3);
        if ('static' == $thumb_show_type) {
            $thumbs_list_class = 'a3dg-thumbs-static';
        }
        $g_auto = get_option(WOO_DYNAMIC_GALLERY_PREFIX . 'product_gallery_auto_start');
        $g_speed = get_option(WOO_DYNAMIC_GALLERY_PREFIX . 'product_gallery_speed');
        $g_effect = get_option(WOO_DYNAMIC_GALLERY_PREFIX . 'product_gallery_effect');
        $g_animation_speed = get_option(WOO_DYNAMIC_GALLERY_PREFIX . 'product_gallery_animation_speed');
        $popup_gallery = get_option(WOO_DYNAMIC_GALLERY_PREFIX . 'popup_gallery');
        $hide_thumb_1image = get_option(WOO_DYNAMIC_GALLERY_PREFIX . 'hide_thumb_1image');
        if ('static' == $thumb_show_type) {
            $display_back_and_forward = 'false';
        }
        $zoom_label = __('ZOOM +', 'woo_dgallery');
        if ('deactivate' == $popup_gallery) {
            $zoom_label = '';
            $lightbox_class = '';
        }
        $_upload_dir = wp_upload_dir();
        if (file_exists($_upload_dir['basedir'] . '/sass/woo_dynamic_gallery.min.css')) {
            echo '<link media="all" type="text/css" href="' . str_replace(array('http:', 'https:'), '', $_upload_dir['baseurl']) . '/sass/woo_dynamic_gallery.min.css?ver=' . WOO_DYNAMIC_GALLERY_VERSION . '" rel="stylesheet" />' . "\n";
        } else {
            include WOO_DYNAMIC_GALLERY_DIR . '/templates/customized_style.php';
        }
        echo '<style>';
        if ('yes' == $hide_thumb_1image && count($dgallery_ids) <= 1) {
            echo '#gallery_' . $product_id . ' .a3dg-nav{display:none;} .woocommerce #gallery_' . $product_id . ' .images { margin-bottom: 15px;}';
        }
        echo '
			</style>';
        echo '<script type ="text/javascript">
				jQuery(function() {
					var settings_defaults_' . $product_id . ' = { loader_image: "' . WOO_DYNAMIC_GALLERY_JS_URL . '/mygallery/loader.gif",
						start_at_index: 0,
						gallery_ID: "' . $product_id . '",
						lightbox_class: "' . $lightbox_class . '",
						description_wrapper: false,
						thumb_opacity: 0.5,
						animate_first_image: false,
						animation_speed: ' . $g_animation_speed . '000,
						width: false,
						height: false,
						display_next_and_prev: true,
						display_back_and_forward: ' . $display_back_and_forward . ',
						scroll_jump: 0,
						slideshow: {
							enable: true,
							autostart: ' . $g_auto . ',
							speed: ' . $g_speed . '000,
							start_label: "' . __('START SLIDESHOW', 'woo_dgallery') . '",
							stop_label: "' . __('STOP SLIDESHOW', 'woo_dgallery') . '",
							zoom_label: "' . $zoom_label . '",
							stop_on_scroll: true,
							countdown_prefix: "(",
							countdown_sufix: ")",
							onStart: false,
							onStop: false
						},
						effect: "' . $g_effect . '",
						enable_keyboard_move: true,
						cycle: true,
						callbacks: {
						init: false,
						afterImageVisible: false,
						beforeImageVisible: false
					}
				};
				jQuery("#gallery_' . $product_id . '").adGallery(settings_defaults_' . $product_id . ');
			});

            </script>';
        echo '<img style="width: 0px ! important; height: 0px ! important; display: none ! important; position: absolute;" src="' . WOO_DYNAMIC_GALLERY_IMAGES_URL . '/blank.gif">';
        echo '<div id="gallery_' . $product_id . '" class="a3-dgallery" style="width: ' . $g_width . ';">
				<div class="a3dg-image-wrapper"></div>
				<div class="a3dg-controls"> </div>
				<div class="a3dg-nav">
					<div class="a3dg-thumbs ' . $thumbs_list_class . '">
						<ul class="a3dg-thumb-list">';
        $script_colorbox = '';
        $script_fancybox = '';
        if (count($dgallery_ids) > 0) {
            $script_colorbox .= '<script type="text/javascript">';
            $script_fancybox .= '<script type="text/javascript">';
            $script_colorbox .= '(function($){';
            $script_fancybox .= '(function($){';
            $script_colorbox .= '$(function(){';
            $script_fancybox .= '$(function(){';
            $script_colorbox .= '$(document).on("click", ".a3-dgallery .lightbox", function(ev) { if( $(this).attr("rel") == "gallery_' . $product_id . '") {
								var idx = $("#gallery_' . $product_id . ' .a3dg-image img").attr("idx");';
            $script_fancybox .= '$(document).on("click", ".a3-dgallery .lightbox", function(ev) { if( $(this).attr("rel") == "gallery_' . $product_id . '") {
								var idx = $("#gallery_' . $product_id . ' .a3dg-image img").attr("idx");';
            if (count($dgallery_ids) <= 1) {
                $script_colorbox .= '$(".gallery_product_' . $product_id . '").colorbox({open:true, maxWidth:"100%" });';
                $script_fancybox .= '$.fancybox(';
            } else {
                $script_colorbox .= '$(".gallery_product_' . $product_id . '").colorbox({rel:"gallery_product_' . $product_id . '", maxWidth:"100%" }); $(".gallery_product_' . $product_id . '_"+idx).colorbox({open:true, maxWidth:"100%" });';
                $script_fancybox .= '$.fancybox([';
            }
            $common = '';
            $idx = 0;
            foreach ($dgallery_ids as $img_id) {
                if (!isset($main_dgallery[$img_id])) {
                    continue;
                }
                // Get image data from main gallery array
                $gallery_item = $main_dgallery[$img_id];
                $li_class = '';
                if ('static' == $thumb_show_type) {
                    if ($idx % $thumb_columns == 0) {
                        $li_class = 'first_item';
                    } elseif ($idx % $thumb_columns + 1 == $thumb_columns) {
                        $li_class = 'last_item';
                    }
                } else {
                    if ($idx == 0) {
                        $li_class = 'first_item';
                    } elseif ($idx == count($dgallery_ids) - 1) {
                        $li_class = 'last_item';
                    }
                }
                $image_large_url = $gallery_item['large']['url'];
                $image_thumb_url = $gallery_item['thumb']['url'];
                $thumb_height = $g_thumb_height;
                $thumb_width = $g_thumb_width;
                $width_old = $gallery_item['thumb']['width'];
                $height_old = $gallery_item['thumb']['height'];
                if ($width_old > $g_thumb_width || $height_old > $g_thumb_height) {
                    if ($height_old > $g_thumb_height && $g_thumb_height > 0) {
                        $factor = $height_old / $g_thumb_height;
                        $thumb_height = $g_thumb_height;
                        $thumb_width = $width_old / $factor;
                    }
                    if ($thumb_width > $g_thumb_width && $g_thumb_width > 0) {
                        $factor = $width_old / $g_thumb_width;
                        $thumb_height = $height_old / $factor;
                        $thumb_width = $g_thumb_width;
                    } elseif ($thumb_width == $g_thumb_width && $width_old > $g_thumb_width && $g_thumb_width > 0) {
                        $factor = $width_old / $g_thumb_width;
                        $thumb_height = $height_old / $factor;
                        $thumb_width = $g_thumb_width;
                    }
                } else {
                    $thumb_height = $height_old;
                    $thumb_width = $width_old;
                }
                echo '<li class="' . $li_class . '">';
                echo '<a alt="' . esc_attr($gallery_item['alt_text']) . '" class="gallery_product_' . $product_id . ' gallery_product_' . $product_id . '_' . $idx . '" title="' . esc_attr($gallery_item['caption_text']) . '" rel="gallery_product_' . $product_id . '" href="' . $image_large_url . '">';
                echo '<img
								org-width="' . esc_attr($gallery_item['large']['width']) . '"
								org-height="' . esc_attr($gallery_item['large']['height']) . '"
								org-sizes="' . esc_attr($gallery_item['large']['img_sizes']) . '"
								org-srcset="' . esc_attr($gallery_item['large']['img_srcset']) . '"
								sizes="' . esc_attr($gallery_item['thumb']['img_sizes']) . '"
								srcset="' . esc_attr($gallery_item['thumb']['img_srcset']) . '"
								idx="' . $idx . '"
								src="' . $image_thumb_url . '"
								alt="' . esc_attr($gallery_item['alt_text']) . '"
								data-caption="' . esc_attr($gallery_item['caption_text']) . '"
								class="image' . $idx . '"
								width="' . $thumb_width . '"
								height="' . $thumb_height . '">';
                echo '</a>';
                echo '</li>';
                if ('' != trim($gallery_item['caption_text'])) {
                    $script_fancybox .= $common . '{href:"' . $image_large_url . '",title:"' . esc_js($gallery_item['caption_text']) . '"}';
                } else {
                    $script_fancybox .= $common . '{href:"' . $image_large_url . '",title:""}';
                }
                $common = ',';
                $idx++;
            }
            if (count($dgallery_ids) <= 1) {
                $script_fancybox .= ');';
            } else {
                $script_fancybox .= '],{
    \'index\': idx
  });';
            }
            $script_colorbox .= 'ev.preventDefault();';
            $script_colorbox .= '} });';
            $script_fancybox .= '} });';
            $script_colorbox .= '});';
            $script_fancybox .= '});';
            $script_colorbox .= '})(jQuery);';
            $script_fancybox .= '})(jQuery);';
            $script_colorbox .= '</script>';
            $script_fancybox .= '</script>';
        } else {
            echo '<li>';
            echo '<a class="" rel="gallery_product_' . $product_id . '" href="' . $no_image_uri . '">';
            echo '<img org-width="" org-height="" sizes="" srcset="" src="' . $no_image_uri . '" class="image" alt="">';
            echo '</a>';
            echo '</li>';
        }
        if ('deactivate' == $popup_gallery) {
            $script_colorbox = '';
            $script_fancybox = '';
        } elseif ('colorbox' == $popup_gallery) {
            echo $script_colorbox;
        } else {
            echo $script_fancybox;
        }
        echo '</ul>
						</div>
					</div>
				</div>';
        ?>
			</div>
		</div>
	<?php 
    }