Esempio n. 1
0
/**
 * Display or retrieve the attachment meta.
 *
 * @since  4.0.0
 * @param  int           $post_id Attachment ID.
 * @param  bool          $echo    Display the attachment meta?
 * @return void | array
 */
function cherry_get_attachment_metadata($post_id = 0, $echo = true)
{
    $post_id = $post_id ? $post_id : get_the_ID();
    if (wp_attachment_is_image($post_id)) {
        $type = 'image';
    } elseif (cherry_attachment_is_audio($post_id)) {
        $type = 'audio';
    } elseif (cherry_attachment_is_video($post_id)) {
        $type = 'video';
    }
    // Get the attachment metadata.
    $metadata = wp_get_attachment_metadata($post_id);
    if (!$metadata) {
        return;
    }
    if (is_array($metadata)) {
        if (function_exists("cherry_{$type}_meta")) {
            $items = call_user_func("cherry_{$type}_meta", $post_id, $metadata);
            if (true !== $echo) {
                return $items;
            }
        }
    }
    if (isset($items) && !empty($items)) {
        $display = '';
        foreach ($items as $item) {
            $display .= sprintf('<li><span class="prep">%1$s</span> <span class="data">%2$s</span></li>', $item[1], $item[0]);
        }
        $display = '<ul class="media-meta">' . $display . '</ul>';
    }
    if (isset($display)) {
        $title = sprintf(__('%s Info', 'cherry'), $type);
        printf('<div class="attachment-meta"><div class="media-info"><h3 class="media-title">%1$s</h3>%2$s</div></div>', $title, $display);
    }
}
Esempio n. 2
0
/**
 * This function filters the attachment markup to be prepended to the post content.
 *
 * @author Justin Tadlock <*****@*****.**>
 * @author Cherry Team <*****@*****.**>
 * @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;
}