Change main image variable

Simplify this variable--no need for certain elements to be accessible
outside the main function.
This commit is contained in:
Robin Cornett
2015-02-27 09:10:06 -05:00
parent 416fdb2926
commit 1a6f95645d
3 changed files with 20 additions and 20 deletions
@@ -36,6 +36,7 @@ class Display_Featured_Image_Genesis_Common {
$move_excerpts = $displaysetting['move_excerpts'];
$postspage_image = get_post_thumbnail_id( $postspage );
$fallback = esc_attr( $displaysetting['default'] ); // url only
$medium = absint( get_option( 'medium_size_w' ) );
if ( is_singular() ) { // just checking for handling conditional variables set by width
$thumb_metadata = wp_get_attachment_metadata( get_post_thumbnail_id( get_the_ID() ) ); // needed only for the next line
@@ -48,9 +49,6 @@ class Display_Featured_Image_Genesis_Common {
// sitewide variables used outside this function
$item->backstretch = '';
$item->fallback_id = self::get_image_id( $fallback ); // gets image id with attached metadata
$item->large = absint( get_option( 'large_size_w' ) );
$item->medium = absint( get_option( 'medium_size_w' ) );
$item->reduce = absint( $displaysetting['less_header'] );
// Set Featured Image source ID
$image_id = ''; // blank if nothing else
@@ -73,6 +71,7 @@ class Display_Featured_Image_Genesis_Common {
}
$object = get_queried_object();
// cpt
if ( is_main_query() && ( ! is_author() && ! is_admin() && ! is_search() ) ) {
if ( $object->name ) { // results in post type on cpt archive
$post_type = $object->name;
@@ -105,7 +104,7 @@ class Display_Featured_Image_Genesis_Common {
*/
$use_tax_image = apply_filters( 'display_featured_image_genesis_use_taxonomy', self::$post_types );
if ( has_post_thumbnail() && $width > $item->medium ) {
if ( has_post_thumbnail() && $width > $medium ) {
$image_id = get_post_thumbnail_id( get_the_ID() );
}
@@ -136,11 +135,6 @@ class Display_Featured_Image_Genesis_Common {
}
$item->backstretch = wp_get_attachment_image_src( $image_id, $image_size );
$item->width = '';
if ( ! empty( $item->backstretch ) ) {
$item->width = $item->backstretch[1];
}
// set a content variable so backstretch doesn't show if full size image exists in post.
$item->content = '';
// declare this last so that $item->backstretch is set.
@@ -197,7 +191,6 @@ class Display_Featured_Image_Genesis_Common {
}
/**
* Get the ID of each image dynamically.
*
@@ -47,9 +47,12 @@ class Display_Featured_Image_Genesis_Output {
$version = Display_Featured_Image_Genesis_Common::$version;
$item = Display_Featured_Image_Genesis_Common::get_image_variables();
$large = absint( get_option( 'large_size_w' ) );
$medium = absint( get_option( 'medium_size_w' ) );
$width = $item->backstretch[1];
//* if there is no backstretch image set, or it is too small, die
if ( empty( $item->backstretch ) || $item->width <= $item->medium || is_paged() ) {
if ( empty( $item->backstretch ) || $width <= $medium || is_paged() ) {
return;
}
//* if the featured image is not part of the content, or we're not on a singular page, carry on
@@ -59,7 +62,7 @@ class Display_Featured_Image_Genesis_Output {
wp_enqueue_style( 'displayfeaturedimage-style', esc_url( $css_file ), array(), $version );
//* check if the image is large enough for backstretch
if ( $item->width > $item->large ) {
if ( $width > $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 );
@@ -70,7 +73,7 @@ class Display_Featured_Image_Genesis_Output {
}
//* otherwise it's a large image.
elseif ( $item->width <= $item->large ) {
elseif ( $width <= $large ) {
remove_action( 'genesis_before_loop', 'genesis_do_cpt_archive_title_description' );
add_action( 'genesis_before_loop', 'genesis_do_cpt_archive_title_description', 15 );
@@ -92,17 +95,20 @@ class Display_Featured_Image_Genesis_Output {
*/
public function add_body_class( $classes ) {
$item = Display_Featured_Image_Genesis_Common::get_image_variables();
$item = Display_Featured_Image_Genesis_Common::get_image_variables();
$large = absint( get_option( 'large_size_w' ) );
$medium = absint( get_option( 'medium_size_w' ) );
$width = $item->backstretch[1];
if ( empty( $item->backstretch ) || $item->width <= $item->medium ) {
if ( empty( $item->backstretch ) || $width <= $medium ) {
return $classes;
}
if ( false === $item->content || ! is_singular() ) {
if ( $item->width > $item->large ) {
if ( $width > $large ) {
$classes[] = 'has-leader';
}
elseif ( $item->width <= $item->large ) {
elseif ( $width <= $large ) {
$classes[] = 'large-featured';
}
}
@@ -124,7 +130,7 @@ class Display_Featured_Image_Genesis_Output {
// backstretch settings from plugin/featured image settings
$backstretch_settings = array(
'src' => esc_url( $item->backstretch[0] ),
'height' => esc_attr( $item->reduce ),
'height' => esc_attr( $displaysetting['less_header'] ),
);
// backstretch settings which can be filtered
$backstretch_variables = array(
@@ -207,7 +207,8 @@ class Display_Featured_Image_Genesis_Settings {
*/
public function set_default_image() {
$item = Display_Featured_Image_Genesis_Common::get_image_variables();
$item = Display_Featured_Image_Genesis_Common::get_image_variables();
$large = absint( get_option( 'large_size_w' ) );
if ( ! empty( $this->displaysetting['default'] ) ) {
$preview = wp_get_attachment_image_src( $item->fallback_id, 'medium' );
@@ -219,7 +220,7 @@ class Display_Featured_Image_Genesis_Settings {
echo '<input type="button" class="upload_default_image button" value="' . __( 'Select Image', 'display-featured-image-genesis' ) . '" />';
echo '<p class="description">' . sprintf(
__( 'If you would like to use a default image for the featured image, upload it here. Must be at least %1$s pixels wide.', 'display-featured-image-genesis' ),
absint( $item->large + 1 )
absint( $large + 1 )
) . '</p>';
}