예제 #1
0
/**
 * Featured image for self-hosted videos.  Checks the vidoe attachment for sub-attachment images.  If 
 * none exist, checks the current post (if in The Loop) for its featured image.  If an image is found, 
 * it's used as the "poster" attribute in the [video] shortcode.
 *
 * @since  1.0.0
 * @access public
 * @param  array  $out
 * @return array
 */
function stargazer_video_atts($out)
{
    /* Don't show in the admin. */
    if (is_admin()) {
        return $out;
    }
    /* Only run if the user didn't set a 'poster' image. */
    if (empty($out['poster'])) {
        /* Check the 'src' attribute for an attachment file. */
        if (!empty($out['src'])) {
            $attachment_id = hybrid_get_attachment_id_from_url($out['src']);
        }
        /* If we couldn't get an attachment from the 'src' attribute, check other supported file extensions. */
        if (empty($attachment_id)) {
            $default_types = wp_get_video_extensions();
            foreach ($default_types as $type) {
                if (!empty($out[$type])) {
                    $attachment_id = hybrid_get_attachment_id_from_url($out[$type]);
                    if (!empty($attachment_id)) {
                        break;
                    }
                }
            }
        }
        /* If there's an attachment ID at this point. */
        if (!empty($attachment_id)) {
            /* Get the attachment's featured image. */
            $image = get_the_image(array('post_id' => $attachment_id, 'size' => 'full', 'format' => 'array', 'echo' => false));
        }
        /* If no image has been found and we're in the post loop, see if the current post has a featured image. */
        if (empty($image) && get_post()) {
            $image = get_the_image(array('size' => 'full', 'format' => 'array', 'echo' => false));
        }
        /* Set the 'poster' attribute if we have an image at this point. */
        if (!empty($image)) {
            $out['poster'] = $image['src'];
        }
    }
    return $out;
}
예제 #2
0
/**
 * @since      0.1.0
 * @deprecated 1.0.0
 */
function socially_awkward_get_attachment_id_from_url($url)
{
    _deprecated_function(__FUNCTION__, '1.0.0', 'hybrid_get_attachment_id_from_url()');
    return hybrid_get_attachment_id_from_url($url);
}