本文整理汇总了PHP中img_caption_shortcode函数的典型用法代码示例。如果您正苦于以下问题:PHP img_caption_shortcode函数的具体用法?PHP img_caption_shortcode怎么用?PHP img_caption_shortcode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了img_caption_shortcode函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_new_img_caption_shortcode_new_format_and_linked_image_with_newline
function test_new_img_caption_shortcode_new_format_and_linked_image_with_newline()
{
$linked_image = "<a href='#'>{$this->img_content}</a>";
$result = img_caption_shortcode(array('width' => 20), $linked_image . "\n\n" . $this->html_content);
$img_preg = preg_quote($linked_image);
$content_preg = preg_quote($this->html_content);
$this->assertEquals(1, preg_match_all("~{$img_preg}.*wp-caption-text~", $result, $_r));
$this->assertEquals(1, preg_match_all("~wp-caption-text.*{$content_preg}~", $result, $_r));
}
示例2: carelib_get_attachment_image
/**
* Output a formatted attachment image.
*
* @since 1.0.0
* @access public
* @return string
*/
function carelib_get_attachment_image()
{
if (!wp_attachment_is_image()) {
return false;
}
$image = wp_get_attachment_image(get_the_ID(), 'full', false, array('class' => 'aligncenter'));
if (has_excerpt()) {
$src = wp_get_attachment_image_src(get_the_ID(), 'full');
$image = img_caption_shortcode(array('align' => 'aligncenter', 'width' => esc_attr($src[1]), 'caption' => get_the_excerpt()), wp_get_attachment_image(get_the_ID(), 'full', false));
}
return apply_filters("{$GLOBALS['carelib_prefix']}_carelib_attachment_image", $image);
}
示例3: alpha_attachment_image
/**
* Output a formatted attachment image.
*
* @since 1.0.0
* @access public
* @return void
*/
function alpha_attachment_image()
{
if (!wp_attachment_is_image()) {
return;
}
alpha_null_the_content();
$image = wp_get_attachment_image(get_the_ID(), 'full', false, array('class' => 'aligncenter'));
if (has_excerpt()) {
$src = wp_get_attachment_image_src(get_the_ID(), 'full');
$image = img_caption_shortcode(array('align' => 'aligncenter', 'width' => esc_attr($src[1]), 'caption' => get_the_excerpt()), wp_get_attachment_image(get_the_ID(), 'full', false));
}
echo $image;
}
示例4: tamatebako_attachment_image
/**
* Display Attachment Image with caption if available.
* @since 0.1.0
*/
function tamatebako_attachment_image($mime = '', $file = '')
{
/* If image has excerpt / caption. */
if (has_excerpt()) {
/* Image URL */
$src = wp_get_attachment_image_src(get_the_ID(), 'full');
/* Display image with caption */
return img_caption_shortcode(array('align' => 'aligncenter', 'width' => esc_attr($src[1]), 'caption' => get_the_excerpt()), wp_get_attachment_image(get_the_ID(), 'full', false));
} else {
/* Display image without caption. */
return wp_get_attachment_image(get_the_ID(), 'full', false, array('class' => 'aligncenter'));
}
}
示例5: wp_get_attachment_image_src
if (is_attachment(get_the_ID())) {
// If viewing a single attachment.
?>
<?php
if (has_excerpt()) {
// If the image has an excerpt/caption.
?>
<?php
$src = wp_get_attachment_image_src(get_the_ID(), 'full');
?>
<div class="featured-media">
<?php
echo img_caption_shortcode(array('align' => 'aligncenter', 'width' => esc_attr($src[1]), 'caption' => get_the_excerpt()), wp_get_attachment_image(get_the_ID(), 'saga-large', false));
?>
</div><!-- .featured-media -->
<?php
} else {
// If the image doesn't have a caption.
?>
<div class="featured-media">
<?php
echo wp_get_attachment_image(get_the_ID(), 'saga-large', false, array('class' => 'aligncenter'));
?>
</div><!-- .featured-media -->
<?php
示例6: shortcode
public static function shortcode($atts, $content = '', $tag = 'cn_thumb')
{
// Grab an instance of the Connections object.
$instance = Connections_Directory();
$permitted = array('attachment', 'featured', 'path', 'url', 'logo', 'photo');
$defaults = array('type' => 'url', 'source' => NULL, 'align' => 'alignnone', 'height' => 0, 'width' => 0, 'negate' => FALSE, 'grayscale' => FALSE, 'brightness' => 0, 'colorize' => NULL, 'contrast' => 0, 'detect_edges' => FALSE, 'emboss' => FALSE, 'gaussian_blur' => FALSE, 'blur' => FALSE, 'sketchy' => FALSE, 'sharpen' => FALSE, 'smooth' => NULL, 'opacity' => 100, 'crop_mode' => 1, 'crop_focus' => array(0.5, 0.5), 'crop_only' => FALSE, 'canvas_color' => '#FFFFFF', 'quality' => 90);
$defaults = apply_filters('cn_thumb_shortcode_atts', $defaults);
$atts = shortcode_atts($defaults, $atts, $tag);
if (!in_array($atts['type'], $permitted)) {
return __('Valid image source type not supplied.', 'connections');
}
/*
* Convert some of the $atts values in the array to boolean because the Shortcode API passes all values as strings.
*/
cnFormatting::toBoolean($atts['negate']);
cnFormatting::toBoolean($atts['grayscale']);
cnFormatting::toBoolean($atts['detect_edges']);
cnFormatting::toBoolean($atts['emboss']);
cnFormatting::toBoolean($atts['gaussian_blur']);
cnFormatting::toBoolean($atts['blur']);
cnFormatting::toBoolean($atts['sketchy']);
cnFormatting::toBoolean($atts['sharpen']);
// cnFormatting::toBoolean( $atts['crop'] );
cnFormatting::toBoolean($atts['crop_only']);
switch ($atts['type']) {
case 'attachment':
$source = wp_get_attachment_url(absint($atts['source']));
break;
case 'featured':
$source = wp_get_attachment_url(get_post_thumbnail_id());
break;
case 'path':
$source = $atts['source'];
break;
case 'url':
$source = esc_url($atts['source']);
break;
case 'logo':
$result = $instance->retrieve->entry(absint($atts['source']));
$entry = new cnEntry($result);
$meta = $entry->getImageMeta(array('type' => 'logo'));
if (is_wp_error($meta)) {
// Display the error messages.
return implode(PHP_EOL, $meta->get_error_messages());
}
$source = $meta['url'];
break;
case 'photo':
$result = $instance->retrieve->entry(absint($atts['source']));
$entry = new cnEntry($result);
$meta = $entry->getImageMeta(array('type' => 'photo'));
if (is_wp_error($meta)) {
// Display the error messages.
return implode(PHP_EOL, $meta->get_error_messages());
}
$source = $meta['url'];
break;
}
// Unset $atts['source'] because passing that $atts to cnImage::get() extracts and overwrite the $source var.
unset($atts['source']);
$image = cnImage::get($source, $atts, 'data');
if (is_wp_error($image)) {
// Display the error messages.
return implode(PHP_EOL, $image->get_error_messages());
} elseif ($image === FALSE) {
return __('An error has occured while creating the thumbnail.', 'connections');
}
$out = img_caption_shortcode(array('align' => $atts['align'], 'width' => $image['width']), '<img class="cn-image" src="' . $image['url'] . '" width="' . $image['width'] . '" height="' . $image['height'] . '" />' . $content);
if (defined('WP_DEBUG') && WP_DEBUG === TRUE) {
$out = $out . '<pre>' . $image['log'] . '</pre>';
}
return $out;
}
示例7: daysinjapan_fixed_img_caption_shortcode
function daysinjapan_fixed_img_caption_shortcode($attr, $content = null)
{
$caption = img_caption_shortcode($attr, $content);
$caption = str_replace('class="wp-caption', 'class="wp-caption entry-image', $caption);
return $caption;
}
示例8: format_image
/**
* Formats the image HTML. This method is only called if the `$image` property isn't set. It uses
* the `$image_args` property to set up the image.
*
* @since 1.0.0
* @access public
* @return void
*/
public function format_image()
{
/* If there is no image URL, return false. */
if (empty($this->image_args['src'])) {
return;
}
/* Check against min. width. If the image width is too small return. */
if (0 < $this->args['min_width'] && isset($this->image_args['width']) && $this->image_args['width'] < $this->args['min_width']) {
return;
}
/* Check against min. height. If the image height is too small return. */
if (0 < $this->args['min_height'] && isset($this->image_args['height']) && $this->image_args['height'] < $this->args['min_height']) {
return;
}
/* Empty classes array. */
$classes = array();
/* If there is alt text, set it. Otherwise, default to the post title. */
$image_alt = !empty($this->image_args['alt']) ? $this->image_args['alt'] : get_post_field('post_title', $this->args['post_id']);
/* If there's a width/height for the image. */
if (isset($this->image_args['width']) && isset($this->image_args['height'])) {
/* Set a class based on the orientation. */
$classes[] = $this->image_args['height'] > $this->image_args['width'] ? 'portrait' : 'landscape';
/* If an explicit width/height is not set, use the info from the image. */
if (empty($this->args['width']) && empty($this->args['height'])) {
$this->args['width'] = $this->image_args['width'];
$this->args['height'] = $this->image_args['height'];
}
}
/* If there is a width or height, set them as HMTL-ready attributes. */
$width = $this->args['width'] ? ' width="' . esc_attr($this->args['width']) . '"' : '';
$height = $this->args['height'] ? ' height="' . esc_attr($this->args['height']) . '"' : '';
/* Add the meta key(s) to the classes array. */
if (!empty($this->args['meta_key'])) {
$classes = array_merge($classes, (array) $this->args['meta_key']);
}
/* Add the $size to the class. */
$classes[] = $this->args['size'];
/* Get the custom image class. */
if (!empty($this->args['image_class'])) {
if (!is_array($this->args['image_class'])) {
$this->args['image_class'] = preg_split('#\\s+#', $this->args['image_class']);
}
$classes = array_merge($classes, $this->args['image_class']);
}
/* Sanitize all the classes. */
$classes = $this->sanitize_class($classes);
/* Join all the classes into a single string and make sure there are no duplicates. */
$class = join(' ', $classes);
/* Add the image attributes to the <img /> element. */
$html = sprintf('<img src="%s" alt="%s" class="%s"%s itemprop="image" />', esc_attr($this->image_args['src']), esc_attr(strip_tags($image_alt)), $class, $width . $height);
/* If $link_to_post is set to true, link the image to its post. */
if ($this->args['link_to_post']) {
$html = '<a href="' . get_permalink($this->args['post_id']) . '" title="' . esc_attr(get_post_field('post_title', $this->args['post_id'])) . '">' . $html . '</a>';
}
/* If there is a $post_thumbnail_id, apply the WP filters normally associated with get_the_post_thumbnail(). */
if (!empty($this->image_args['post_thumbnail_id'])) {
$html = apply_filters('post_thumbnail_html', $html, $this->args['post_id'], $this->image_args['post_thumbnail_id'], $this->args['size'], '');
}
/* If we're showing a caption. */
if (true === $this->args['caption'] && !empty($this->image_args['caption'])) {
$html = img_caption_shortcode(array('caption' => $this->image_args['caption'], 'width' => $this->args['width']), $html);
}
$this->image = $html;
}
示例9: get_the_image_format
/**
* Formats an image with appropriate alt text and class. Adds a link to the post if argument is set. Should
* only be called if there is an image to display, but will handle it if not.
*
* @since 0.7.0
* @access private
* @param array $args Arguments for how to load and display the image.
* @param array $image Array of image attributes ($image, $classes, $alt, $caption).
* @return string $image Formatted image (w/link to post if the option is set).
*/
function get_the_image_format($args = array(), $image = false)
{
/* If there is no image URL, return false. */
if (empty($image['src'])) {
return false;
}
/* Extract the arguments for easy-to-use variables. */
extract($args);
/* If there is alt text, set it. Otherwise, default to the post title. */
$image_alt = !empty($image['alt']) ? $image['alt'] : get_post_field('post_title', $post_id);
/* If there is a width or height, set them as HMTL-ready attributes. */
$width = $width ? ' width="' . esc_attr($width) . '"' : '';
$height = $height ? ' height="' . esc_attr($height) . '"' : '';
/* Loop through the custom field keys and add them as classes. */
if (is_array($meta_key)) {
foreach ($meta_key as $key) {
$classes[] = $key;
}
}
/* Add the $size to the class. */
$classes[] = $size;
/* Get the custom image class. */
if (!empty($image_class)) {
if (!is_array($image_class)) {
$image_class = preg_split('#\\s+#', $image_class);
}
$classes = array_merge($classes, $image_class);
}
/* Sanitize all the classes. */
$classes = array_map('sanitize_html_class', $classes);
/* Join all the classes into a single string and make sure there are no duplicates. */
$class = join(' ', array_unique($classes));
/* Add the image attributes to the <img /> element. */
$html = '<img src="' . $image['src'] . '" alt="' . esc_attr(strip_tags($image_alt)) . '" class="' . esc_attr($class) . '"' . $width . $height . ' />';
/* If $link_to_post is set to true, link the image to its post. */
if ($link_to_post) {
$html = '<a href="' . get_permalink($post_id) . '" title="' . esc_attr(get_post_field('post_title', $post_id)) . '">' . $html . '</a>';
}
/* If there is a $post_thumbnail_id, apply the WP filters normally associated with get_the_post_thumbnail(). */
if (!empty($image['post_thumbnail_id'])) {
$html = apply_filters('post_thumbnail_html', $html, $post_id, $image['post_thumbnail_id'], $size, '');
}
/* If we're showing a caption. */
if (true === $args['caption'] && !empty($image['caption'])) {
$html = img_caption_shortcode(array('caption' => $image['caption'], 'width' => $args['width']), $html);
}
return $html;
}
示例10: cherry_attachment_content
/**
* This function filters the attachment markup to be prepended to the post content.
*
* @author Justin Tadlock <justin@justintadlock.com>
* @author Cherry Team <support@cherryframework.com>
* @since 4.0.0
* @param string $p The attachment HTML output.
*/
function cherry_attachment_content($p)
{
if (is_attachment()) {
$attr = array('align' => 'aligncenter', 'width' => '', 'caption' => '');
$post_id = get_the_ID();
if (wp_attachment_is_image($post_id)) {
$src = wp_get_attachment_image_src(get_the_ID(), 'full');
if (is_array($src) && !empty($src)) {
$attr['width'] = esc_attr($src[1]);
$content = wp_get_attachment_image(get_the_ID(), 'full', false, array('class' => 'aligncenter'));
}
} elseif (cherry_attachment_is_audio($post_id) || cherry_attachment_is_video($post_id)) {
$attr['width'] = cherry_get_content_width();
$content = $p;
} else {
return $p;
}
if (!has_excerpt()) {
return $content;
}
$attr['caption'] = get_the_excerpt();
$output = img_caption_shortcode($attr, $content);
return $output;
}
return $p;
}
示例11: filtered_caption_shortcode
function filtered_caption_shortcode($attr, $content = null)
{
if (isset($attr['caption']) && strpos($attr['caption'], '<') !== false) {
$attr['caption'] = wp_kses($attr['caption'], 'post');
}
return img_caption_shortcode($attr, $content);
}
示例12: media_credit_caption_shortcode
/**
* Modified Caption shortcode.
*
* Fixes the new style caption shortcode parsing and then calls the stock
* shortcode function.
*
* @param array $attr Attributes attributed to the shortcode.
* @param string $content Optional. Shortcode content.
* @return string
*/
function media_credit_caption_shortcode($attr, $content = null)
{
// New-style shortcode with the caption inside the shortcode with the link and image tags.
if (!isset($attr['caption'])) {
if (preg_match('#((?:\\[media-credit[^\\]]+\\]\\s*)(?:<a [^>]+>\\s*)?<img [^>]+>(?:\\s*</a>)?(?:\\s*\\[/media-credit\\])?)(.*)#is', $content, $matches)) {
$content = $matches[1];
$attr['caption'] = trim($matches[2]);
}
}
return img_caption_shortcode($attr, $content);
}
示例13: wpse_74735_caption_shortcode
/**
* Add the new class to the caption.
*
* @param array $attr Shortcode attributes
* @param string $content Caption text
* @return string
*/
static function wpse_74735_caption_shortcode($attr, $content = NULL)
{
$caption = img_caption_shortcode($attr, $content);
$caption = str_replace('a href="', 'a class="mp-item" href="', $caption);
return $caption;
}
示例14: format_image
/**
* Formats the image HTML. This method is only called if the `$image` property isn't set. It uses
* the `$image_args` property to set up the image.
*
* @since 1.0.0
* @access public
* @return void
*/
public function format_image()
{
// If there is no image URL, return false.
if (empty($this->image_args['src'])) {
return;
}
// Check against min. width. If the image width is too small return.
if (0 < $this->args['min_width'] && isset($this->image_args['width']) && $this->image_args['width'] < $this->args['min_width']) {
return;
}
// Check against min. height. If the image height is too small return.
if (0 < $this->args['min_height'] && isset($this->image_args['height']) && $this->image_args['height'] < $this->args['min_height']) {
return;
}
// Empty classes array.
$classes = array();
// If there is alt text, set it. Otherwise, default to the post title.
$image_alt = !empty($this->image_args['alt']) ? $this->image_args['alt'] : get_post_field('post_title', $this->args['post_id']);
// If there's a width/height for the image.
if (isset($this->image_args['width']) && isset($this->image_args['height'])) {
// Set a class based on the orientation.
$classes[] = $this->image_args['height'] > $this->image_args['width'] ? 'portrait' : 'landscape';
// Set class based on the content width (defined by theme).
if (0 < $GLOBALS['content_width']) {
if ($GLOBALS['content_width'] == $this->image_args['width']) {
$classes[] = 'cw-equal';
} elseif ($GLOBALS['content_width'] <= $this->image_args['width']) {
$classes[] = 'cw-lesser';
} elseif ($GLOBALS['content_width'] >= $this->image_args['width']) {
$classes[] = 'cw-greater';
}
}
// If an explicit width/height is not set, use the info from the image.
if (empty($this->args['width']) && empty($this->args['height'])) {
$this->args['width'] = $this->image_args['width'];
$this->args['height'] = $this->image_args['height'];
}
}
// If there is a width or height, set them as HMTL-ready attributes.
$width = $this->args['width'] ? ' width="' . esc_attr($this->args['width']) . '"' : '';
$height = $this->args['height'] ? ' height="' . esc_attr($this->args['height']) . '"' : '';
// srcset attribute
$srcset = !empty($this->srcsets) ? sprintf(' srcset="%s"', esc_attr(join(', ', $this->srcsets))) : '';
// Add the meta key(s) to the classes array.
if (!empty($this->args['meta_key'])) {
$classes = array_merge($classes, (array) $this->args['meta_key']);
}
// Add the $size to the class.
$classes[] = $this->args['size'];
// Get the custom image class.
if (!empty($this->args['image_class'])) {
if (!is_array($this->args['image_class'])) {
$this->args['image_class'] = preg_split('#\\s+#', $this->args['image_class']);
}
$classes = array_merge($classes, $this->args['image_class']);
}
// Sanitize all the classes.
$classes = $this->sanitize_class($classes);
// Join all the classes into a single string and make sure there are no duplicates.
$class = join(' ', $classes);
// Add the image attributes to the <img /> element.
$html = sprintf('<img src="%s"%s alt="%s" class="%s"%s itemprop="image" />', esc_attr($this->image_args['src']), $srcset, esc_attr(strip_tags($image_alt)), $class, $width . $height);
// If $link is set to true, link the image to its post.
if (false !== $this->args['link']) {
if ('post' === $this->args['link'] || true === $this->args['link']) {
$url = get_permalink($this->args['post_id']);
} elseif ('file' === $this->args['link']) {
$url = $this->image_args['src'];
} elseif ('attachment' === $this->args['link'] && isset($this->image_args['id'])) {
$url = get_permalink($this->image_args['id']);
}
if (!empty($url)) {
$link_class = $this->args['link_class'] ? sprintf(' class="%s"', esc_attr($this->args['link_class'])) : '';
$html = sprintf('<a href="%s"%s>%s</a>', esc_url($url), $link_class, $html);
}
}
// If there is a $post_thumbnail_id, apply the WP filters normally associated with get_the_post_thumbnail().
if (!empty($this->image_args['post_thumbnail_id'])) {
$html = apply_filters('post_thumbnail_html', $html, $this->args['post_id'], $this->image_args['post_thumbnail_id'], $this->args['size'], '');
}
// If we're showing a caption.
if (true === $this->args['caption'] && !empty($this->image_args['caption'])) {
$html = img_caption_shortcode(array('caption' => $this->image_args['caption'], 'width' => $this->args['width']), $html);
}
$this->image = $html;
}
示例15: wpse_138126_thumbnail_caption
function wpse_138126_thumbnail_caption($html, $post_id, $post_thumbnail_id, $size, $attr)
{
if ($post = get_post($post_thumbnail_id)) {
if ($size = wp_get_attachment_image_src($post->ID, $size)) {
$width = $size[1];
} else {
$width = 0;
}
$html = img_caption_shortcode(array('caption' => trim("{$post->post_excerpt} {$post->post_content}"), 'align' => 'alignright', 'width' => $width), $html);
}
return $html;
}