different metadata function to play nice with Photon

This commit is contained in:
Robin Cornett
2014-11-18 19:48:16 -05:00
parent 8b5e4ef970
commit f32f3074d7
2 changed files with 18 additions and 11 deletions
@@ -32,12 +32,13 @@ class Display_Featured_Image_Genesis_Common {
$move_excerpts = $displaysetting['move_excerpts'];
$postspage_image = get_post_thumbnail_id( $postspage );
if ( is_singular() ) {
$image_id = get_post_thumbnail_id( $post->ID );
$post_thumbnail = wp_get_attachment_image_src( $image_id, 'original' );
if ( is_singular() ) { // just checking for handling conditional variables set by width
$thumbnail_id = get_post_thumbnail_id( $post->ID );
$metadata = wp_get_attachment_metadata( $thumbnail_id ); // needed only for the next line
$width = $metadata['width'];
}
// variables used outside this function
// sitewide variables used outside this function
$item->fallback = esc_attr( $displaysetting['default'] ); // url only
$item->fallback_id = self::get_image_id( $item->fallback ); // gets image id with attached metadata
$item->large = absint( get_option( 'large_size_w' ) );
@@ -54,14 +55,20 @@ class Display_Featured_Image_Genesis_Common {
// if it's a home page with a static front page, and there is a featured image set on the home page
if ( is_home() && 'page' === $frontpage && ! empty( $postspage_image ) ) {
$image_id = get_post_thumbnail_id( $postspage );
$image_id = $postspage_image;
}
// any singular post/page/CPT with either a post_thumbnail larger than medium size OR there is no $item->fallback
elseif ( is_singular() && ( $post_thumbnail[1] > $item->medium || empty( $item->fallback ) ) && ! in_array( get_post_type(), self::use_fallback_image() ) ) {
elseif ( is_singular() && ( $width > $item->medium || empty( $item->fallback ) ) && ! in_array( get_post_type(), self::use_fallback_image() ) ) {
$image_id = get_post_thumbnail_id( $post->ID );
}
//now actually set the backstretch image source, which includes some metadata
$metadata = wp_get_attachment_metadata( $image_id );
$item->backstretch = wp_get_attachment_image_src( $image_id, 'displayfeaturedimage_backstretch' );
$item->width = '';
if ( ! empty( $item->backstretch ) ) {
$item->width = $metadata['width'];
}
// set a content variable so backstretch doesn't show if full size image exists in post.
$item->content = '';
@@ -39,7 +39,7 @@ class Display_Featured_Image_Genesis_Output {
$item = Display_Featured_Image_Genesis_Common::get_image_variables();
// if there is no backstretch image set, or it is too small, die
if ( empty( $item->backstretch ) || $item->backstretch[1] <= $item->medium ) {
if ( empty( $item->backstretch ) || $item->width <= $item->medium ) {
return;
}
// if the featured image is not part of the content, or we're not on a singular page, carry on
@@ -48,7 +48,7 @@ class Display_Featured_Image_Genesis_Output {
wp_enqueue_style( 'displayfeaturedimage-style', plugins_url( 'includes/css/display-featured-image-genesis.css', dirname( __FILE__ ) ), array(), $version );
//check if the image is large enough for backstretch
if ( $item->backstretch[1] > $item->large ) {
if ( $item->width > $item->large ) {
wp_enqueue_script( 'displayfeaturedimage-backstretch', plugins_url( '/includes/js/backstretch.js', dirname( __FILE__ ) ), array( 'jquery' ), $version, true );
wp_enqueue_script( 'displayfeaturedimage-backstretch-set', plugins_url( '/includes/js/backstretch-set.js', dirname( __FILE__ ) ), array( 'jquery', 'displayfeaturedimage-backstretch' ), $version, true );
@@ -78,15 +78,15 @@ class Display_Featured_Image_Genesis_Output {
$item = Display_Featured_Image_Genesis_Common::get_image_variables();
if ( empty( $item->backstretch ) || $item->backstretch[1] <= $item->medium ) {
if ( empty( $item->backstretch ) || $item->width <= $item->medium ) {
return $classes;
}
if ( false === $item->content || ! is_singular() ) {
if ( $item->backstretch[1] > $item->large ) {
if ( $item->width > $item->large ) {
$classes[] = 'has-leader';
}
elseif ( $item->backstretch[1] <= $item->large ) {
elseif ( $item->width <= $item->large ) {
$classes[] = 'large-featured';
}
}