function layers_get_feature_media($attachmentid = NULL, $size = 'medium', $video = NULL, $postid = NULL) { // Return dimensions $image_dimensions = layers_get_image_sizes($size); // Check for an image if (NULL != $attachmentid && '' != $attachmentid) { $use_image = wp_get_attachment_image($attachmentid, $size); } // Check for a video if (NULL != $video && '' != $video) { $embed_code = '[embed width="' . $image_dimensions['width'] . '" height="' . $image_dimensions['height'] . '"]' . $video . '[/embed]'; $wp_embed = new WP_Embed(); $use_video = $wp_embed->run_shortcode($embed_code); } // Set which element to return if (NULL != $postid && (is_single() && isset($use_video) || !is_single() && !is_page_template('template-blog.php') && isset($use_video) && !isset($use_image))) { $media = $use_video; } else { if (NULL == $postid && isset($use_video)) { $media = $use_video; } else { if (isset($use_image)) { $media = $use_image; } else { return NULL; } } } $media_output = do_action('layers_before_feature_media') . $media . do_action('layers_after_feature_media'); return $media_output; }
function layers_get_feature_media($attachmentid = NULL, $size = 'medium', $video = NULL, $postid = NULL) { // Return dimensions $image_dimensions = layers_get_image_sizes($size); // Mime Type $mime_type = get_post_mime_type($attachmentid); // Check for an image if (NULL != $attachmentid && '' != $attachmentid) { if (preg_match('/video\\/*/', $mime_type)) { $image_ratio = explode('-', $size); if (count($image_ratio) == 3) { $ratio = $image_ratio[1]; } else { $ratio = 'landscape'; } $use_video = layers_get_html5_video(wp_get_attachment_url($attachmentid), $image_dimensions['width'], $ratio); } else { $use_image = wp_get_attachment_image($attachmentid, $size); } } // Check for a video if (NULL != $video && '' != $video) { $embed_code = '[embed width="' . $image_dimensions['width'] . '" height="' . $image_dimensions['height'] . '"]' . $video . '[/embed]'; $wp_embed = new WP_Embed(); $use_video = $wp_embed->run_shortcode($embed_code); } // Set which element to return if (NULL != $postid && (is_single() && isset($use_video) || !is_single() && !is_page_template('template-blog.php') && isset($use_video) && !isset($use_image))) { $media = $use_video; } else { if (NULL == $postid && isset($use_video)) { $media = $use_video; } else { if (isset($use_image)) { $media = $use_image; } else { return NULL; } } } $media_output = do_action('layers_before_feature_media') . $media . do_action('layers_after_feature_media'); return $media_output; }