public function render($classNames = null, $alt = null, $title = null) { $this->classNames = $classNames; add_filter('get_image_tag_class', [$this, 'getClassNames'], 10); $img = self::removeHeightAndWidthAttributes(get_image_tag($this->ID, $alt, $title, null, null)); remove_filter('get_image_tag_class', [$this, 'getClassNames'], 10); return $img; }
function get_image_send_to_editor($id, $alt, $title, $align, $url = '', $rel = false, $size = 'medium') { $html = get_image_tag($id, $alt, $title, $align, $size); $rel = $rel ? ' rel="attachment wp-att-' . attribute_escape($id) . '"' : ''; if ($url) { $html = '<a href="' . clean_url($url) . "\"{$rel}>{$html}</a>"; } $html = apply_filters('image_send_to_editor', $html, $id, $alt, $title, $align, $url, $size); return $html; }
function get_image_send_to_editor($id, $alt, $title, $align, $url='', $rel = false, $size='medium') { $html = get_image_tag($id, $alt, $title, $align, $size); $rel = $rel ? ' rel="attachment wp-att-'.attribute_escape($id).'"' : ''; if ( $url ) $html = "<a href='".attribute_escape($url)."'$rel>$html</a>"; $html = apply_filters( 'image_send_to_editor', $html, $id, $alt, $title, $align, $url ); return $html; }
function ubik_imagery_feed($id = '', $size = '', $alt = '', $align = 'none') { // The `get_image_tag` function requires a simple alignment e.g. "none", "left", etc. $align = str_replace('align', '', $align); // Size limiter for feeds $size_default = apply_filters('ubik_imagery_feed_default_size', 'medium'); $sizes_metadata = ubik_imagery_sizes_metadata(); // Default size filter applies here as well if (empty($size)) { $size = $size_default; } // Scale down images for the feed; @TODO: replace with an image that has the same aspect ratio if (isset($sizes_metadata[$size])) { if ($sizes_metadata[$size]['width'] > $sizes_metadata[$size_default]['width']) { $size = $size_default; } } // Default image element generator cribbed from WordPress core return apply_filters('ubik_imagery_feed', get_image_tag($id, $alt, $title = '', $align, $size)); }
/** * {@internal Missing Short Description}} * * @since unknown * * @param unknown_type $id * @param unknown_type $alt * @param unknown_type $title * @param unknown_type $align * @param unknown_type $url * @param unknown_type $rel * @param unknown_type $size * @return unknown */ function get_image_send_to_editor($id, $caption, $title, $align, $url='', $rel = false, $size='medium', $alt = '') { $html = get_image_tag($id, $alt, $title, $align, $size); $rel = $rel ? ' rel="attachment wp-att-' . esc_attr($id).'"' : ''; if ( $url ) $html = '<a href="' . esc_attr($url) . "\"$rel>$html</a>"; $html = apply_filters( 'image_send_to_editor', $html, $id, $caption, $title, $align, $url, $size, $alt ); return $html; }
function pcomm_image_send_to_editor($html, $id, $caption, $title, $align, $url, $size, $alt) { add_filter('disable_captions', create_function('$a', 'return true;')); // Manipulate the HTML if (!$align) { $div_align = 'alignleft'; } else { $div_align = $align; } $html = get_image_tag($id, $alt, $title, $align = 'none', $size); $sizes = wp_get_attachment_image_src($id, $size); $width = $sizes[1]; $height = $sizes[2]; $hwstring = 'width="' . $width . '" height="' . $height . '"'; if ($url) { $html = '<a href="' . esc_attr($url) . ' ">' . $html . '</a>'; } if (!$caption) { return '<div id="attachment_' . $id . '" class="wp-attachment align' . $div_align . '">' . $html . '</div>'; } else { return '<div style="width:' . $width . 'px;" id="attachment_' . $id . '" class="wp-attachment wp-caption align' . $div_align . '">' . '<a href="' . $url . ' ">' . '<img ' . $hwstring . ' src=' . $url . ' alt=' . $title . ' />' . '</a>' . '<p class="wp-caption-text">' . $caption . '</p></div>'; } }
/** * Retrieves the image HTML to send to the editor. * * @since 2.5.0 * * @param int $id Image attachment id. * @param string $caption Image caption. * @param string $title Image title attribute. * @param string $align Image CSS alignment property. * @param string $url Optional. Image src URL. Default empty. * @param string $rel Optional. Image rel attribute. Default empty. * @param string|array $size Optional. Image size. Accepts any valid image size, or an array of width * and height values in pixels (in that order). Default 'medium'. * @param string $alt Optional. Image alt attribute. Default empty. * @return string The HTML output to insert into the editor. */ function get_image_send_to_editor($id, $caption, $title, $align, $url = '', $rel = '', $size = 'medium', $alt = '') { $html = get_image_tag($id, $alt, '', $align, $size); if (!$rel) { $rel = ' rel="attachment wp-att-' . esc_attr($id) . '"'; } else { $rel = ' rel="' . esc_attr($rel) . '"'; } if ($url) { $html = '<a href="' . esc_attr($url) . "\"{$rel}>{$html}</a>"; } /** * Filter the image HTML markup to send to the editor. * * @since 2.5.0 * * @param string $html The image HTML markup to send. * @param int $id The attachment id. * @param string $caption The image caption. * @param string $title The image title. * @param string $align The image alignment. * @param string $url The image source URL. * @param string|array $size Size of image. Image size or array of width and height values * (in that order). Default 'medium'. * @param string $alt The image alternative, or alt, text. */ $html = apply_filters('image_send_to_editor', $html, $id, $caption, $title, $align, $url, $size, $alt); return $html; }
/** * @ticket 33641 */ function test_wp_make_content_images_responsive_with_preexisting_srcset() { // Generate HTML and add a dummy srcset attribute. $image_html = get_image_tag(self::$large_id, '', '', '', 'medium'); $image_html = preg_replace('|<img ([^>]+) />|', '<img $1 ' . 'srcset="image2x.jpg 2x" />', $image_html); // The content filter should return the image unchanged. $this->assertSame($image_html, wp_make_content_images_responsive($image_html)); }
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); }
/** * @param $column * @return void * @since 1.0.0 * @uses fiat_thumb, thumb * * Insert representative thumbnail image into Admin Dashboard view * for All Posts/Pages if we are on the "thumb" column * */ public function fiat_custom_columns($column) { global $post; $post_id = $post->ID; switch ($column) { case 'thumb': if (has_post_thumbnail($post_id)) { // Determine if our image size has been created and use // that size/attribute combination // else get the post-thumbnail image and apply custom sizing to // size it to fit in the admin dashboard $thumbnail_id = get_post_thumbnail_id($post_id); $tpm = wp_get_attachment_metadata($thumbnail_id); $sizes = $tpm['sizes']; // Default to thumbnail size (as this will be sized down reducing the bandwidth until the image thumbnail is regenerated) $fiat_image_size = 'thumbnail'; // Review the sizes this particular image has been set to if (is_array($sizes)) { foreach ($sizes as $s => $k) { if ($this->fiat_image_size == $s) { // our size is present, set it and break out $fiat_image_size = $this->fiat_image_size; break; } } } /** * Check if WooCommerce is active * If so, only return anchor link markup to inline edit thumbnail * WooCommerce will supply the image markup **/ if ($this->fiat_on_woocommerce_products_list()) { $thumb_url = ''; } else { if ('thumbnail' == $fiat_image_size) { // size down this time $thumb_url = wp_get_attachment_image($thumbnail_id, array(60, 60)); } else { // use native sized image $thumb_url = get_image_tag($thumbnail_id, '', '', '', $fiat_image_size); } } // Here it is! $this->fiat_nonce = wp_create_nonce('set_post_thumbnail-' . $post_id); $template_html = '<a title="' . __('Change featured image', 'featured-image-admin-thumb-fiat') . '" href="%1$s" id="set-post-thumbnail" class="fiat_thickbox" data-thumbnail-id="%3$d">%2$s<span class="genericon genericon-edit fiat-icon"></span></a>'; $html = sprintf($template_html, home_url() . '/wp-admin/media-upload.php?post_id=' . $post_id . '&type=image&TB_iframe=1&_wpnonce=' . $this->fiat_nonce, $thumb_url, $thumbnail_id); // Click me to change! echo $html; } else { // This nonce "action" parameter must match the Ajax Referrer action used in the js and PHP // wp-admin/includes/ajax-actions.php wp-includes/pluggable.php // It's like dealing with the IRS. :-) $this->fiat_nonce = wp_create_nonce('set_post_thumbnail-' . $post_id); $set_featured_image = sprintf(__('Set %s featured image', 'featured-image-admin-thumb-fiat'), '<br/>'); $set_edit_markup = $this->fiat_on_woocommerce_products_list() ? '<span class="genericon genericon-edit fiat-icon"></span>' : $set_featured_image; $template_html = '<a title="' . __('Set featured image', 'featured-image-admin-thumb-fiat') . '" href="%1$s" id="set-post-thumbnail" class="fiat_thickbox" >%2$s</a>'; $html = sprintf($template_html, home_url() . '/wp-admin/media-upload.php?post_id=' . $post_id . '&type=image&TB_iframe=1&_wpnonce=' . $this->fiat_nonce, $set_edit_markup); // Click me! echo $html; } break; } }
function scwd_single_do_tax_image($title) { global $post, $SCWD_CUSTOM; if (is_single()) { global $post; // to do: get tax dynamically $tax = 'category'; $image_size = 'Panoramic Large'; if (false !== ($image_id = $SCWD_CUSTOM->acf_get_field('_feature_image'))) { print '<div class="tax-image">' . get_image_tag($image_id, $post->post_title, $post->post_title, '', $image_size) . '</div>'; } else { print apply_filters('taxonomy-images-list-the-terms', '', array('before' => '', 'after' => '', 'before_image' => '<div class="tax-image">', 'after_image' => '</div>', 'image_size' => $image_size, 'taxonomy' => $tax)); } } }
/** * Simple print of a image tag. * * @param int $image_id * @param string|array $size * @param array $options */ function print_image($image_id, $size, array $options = []) { echo get_image_tag($image_id, $size, $options); }
public function get_image_html($size = 'medium', $term_tax_id = false, $title = true, $align = 'none') { $o = ''; if (false === $term_tax_id) { global $wp_query; $obj = $wp_query->get_queried_object(); if (isset($obj->term_taxonomy_id)) { $term_tax_id = $obj->term_taxonomy_id; } else { return false; } } $term_tax_id = (int) $term_tax_id; if (isset($this->settings[$term_tax_id])) { $attachment_id = (int) $this->settings[$term_tax_id]; $alt = get_post_meta($attachment_id, '_wp_attachment_image_alt', true); $attachment = get_post($attachment_id); /* Just in case an attachment was deleted, but there is still a record for it in this plugins settings. */ if ($attachment !== NULL) { $o = get_image_tag($attachment_id, $alt, '', $align, $size); } } return $o; }
/** * @group 170 */ function test_tevkori_filter_content_images_with_preexisting_srcset() { // Make image. $id = $this->_test_img(); // Generate HTML and add a dummy srcset attribute. $image_html = get_image_tag($id, '', '', '', 'medium'); $image_html = preg_replace('|<img ([^>]+) />|', '<img $1 ' . 'srcset="image2x.jpg 2x" />', $image_html); // The content filter should return the image unchanged. $this->assertSame($image_html, tevkori_filter_content_images($image_html)); }
/** * {@internal Missing Short Description}} * * @since unknown * * @param unknown_type $id * @param unknown_type $alt * @param unknown_type $title * @param unknown_type $align * @param unknown_type $url * @param unknown_type $rel * @param unknown_type $size * @return unknown */ function get_image_send_to_editor($id, $alt, $title, $align, $url = '', $rel = false, $size = 'medium') { $htmlalt = empty($alt) ? $title : $alt; $html = get_image_tag($id, $htmlalt, $title, $align, $size); $rel = $rel ? ' rel="attachment wp-att-' . esc_attr($id) . '"' : ''; if ($url) { $html = '<a target="_blank" href="' . esc_url($url) . "\"{$rel}>{$html}</a>"; } $html = apply_filters('image_send_to_editor', $html, $id, $alt, $title, $align, $url, $size); return $html; }
/** * {@internal Missing Short Description}} * * @since 2.5.0 * * @param integer $id image attachment id * @param string $caption image caption * @param string $alt image alt attribute * @param string $title image title attribute * @param string $align image css alignment property * @param string $url image src url * @param string|bool $rel image rel attribute * @param string $size image size (thumbnail, medium, large, full or added with add_image_size() ) * @return string the html to insert into editor */ function get_image_send_to_editor($id, $caption, $title, $align, $url = '', $rel = false, $size = 'medium', $alt = '') { $html = get_image_tag($id, $alt, '', $align, $size); $rel = $rel ? ' rel="attachment wp-att-' . esc_attr($id) . '"' : ''; if ($url) { $html = '<a href="' . esc_attr($url) . "\"{$rel}>{$html}</a>"; } /** * Filter the image HTML markup to send to the editor. * * @since 2.5.0 * * @param string $html The image HTML markup to send. * @param int $id The attachment id. * @param string $caption The image caption. * @param string $title The image title. * @param string $align The image alignment. * @param string $url The image source URL. * @param string $size The image size. * @param string $alt The image alternative, or alt, text. */ $html = apply_filters('image_send_to_editor', $html, $id, $caption, $title, $align, $url, $size, $alt); return $html; }
function pixlr_image_replace($id, $alt, $title, $align, $rel = false, $url = '', $size = 'medium') { $htmlalt = empty($alt) ? $title : $alt; $html_pixlr = get_image_tag($id, $htmlalt, $title, $align, $size); if ($url) { $html_pixlr = "<a href=\"javascript:pixlr.overlay.show({image:'" . $url . "'});\"><img src=\"" . $url . "\"/></a>"; } return $html_pixlr; }