From 0f6430682d9df8b7ea003d507a4490b3e812ce8d Mon Sep 17 00:00:00 2001 From: Robin Cornett Date: Sat, 6 Jun 2015 17:57:28 -0400 Subject: [PATCH] Fix $variables --- ...ass-displayfeaturedimagegenesis-common.php | 39 +++----- ...ass-displayfeaturedimagegenesis-output.php | 95 ++++++++----------- ...s-displayfeaturedimagegenesis-settings.php | 7 +- 3 files changed, 58 insertions(+), 83 deletions(-) diff --git a/includes/class-displayfeaturedimagegenesis-common.php b/includes/class-displayfeaturedimagegenesis-common.php index ca39b10..823b256 100644 --- a/includes/class-displayfeaturedimagegenesis-common.php +++ b/includes/class-displayfeaturedimagegenesis-common.php @@ -15,8 +15,6 @@ class Display_Featured_Image_Genesis_Common { */ public $version = '2.2.2'; - protected $post_types; - /** * set and retreive variables for the featured image. * @return $item @@ -25,8 +23,6 @@ class Display_Featured_Image_Genesis_Common { */ public function get_image_variables() { - $this->post_types = array(); - $item = new stdClass(); // variables internal to this function @@ -52,7 +48,7 @@ class Display_Featured_Image_Genesis_Common { * * @since 2.0.0 */ - $use_large_image = apply_filters( 'display_featured_image_genesis_use_large_image', $this->post_types ); + $use_large_image = apply_filters( 'display_featured_image_genesis_use_large_image', array() ); $image_size = 'displayfeaturedimage_backstretch'; if ( in_array( get_post_type(), $use_large_image ) ) { $image_size = 'large'; @@ -72,15 +68,14 @@ class Display_Featured_Image_Genesis_Common { $item->content = strpos( $post->post_content, 'src="' . $fullsize[0] ); if ( false !== $item->content ) { - $source_id = ''; + $source_id = ''; $term_image = display_featured_image_genesis_get_term_image_id(); $default_image = display_featured_image_genesis_get_default_image_id(); // reset backstretch image source to term image if it exists and the featured image is being used in content. if ( ! empty( $term_image ) ) { $source_id = $term_image; - } - // else, reset backstretch image source to fallback. - elseif ( ! empty( $fallback ) ) { + } elseif ( ! empty( $fallback ) ) { + // else, reset backstretch image source to fallback. $source_id = $default_image; } $item->backstretch = wp_get_attachment_image_src( $source_id, $image_size ); @@ -140,7 +135,7 @@ class Display_Featured_Image_Genesis_Common { * @var filter * @since 2.0.0 (deprecated old use_fallback_image function from 1.2.2) */ - $use_fallback = apply_filters( 'display_featured_image_genesis_use_default', $this->post_types ); + $use_fallback = apply_filters( 'display_featured_image_genesis_use_default', array() ); // set here with fallback preemptively, if it exists if ( ! empty( $fallback ) ) { @@ -162,12 +157,10 @@ class Display_Featured_Image_Genesis_Common { $post_type = ''; if ( $object->name ) { // results in post type on cpt archive $post_type = $object->name; - } - elseif ( $object->taxonomy ) { // on a tax/term/category + } elseif ( $object->taxonomy ) { // on a tax/term/category $tax_object = get_taxonomy( $object->taxonomy ); $post_type = $tax_object->object_type[0]; - } - elseif ( $object->post_type ) { // on singular + } elseif ( $object->post_type ) { // on singular $post_type = $object->post_type; } if ( ! empty( $displaysetting['post_type'][ $post_type ] ) ) { @@ -178,7 +171,7 @@ class Display_Featured_Image_Genesis_Common { * * @since 2.2.1 */ - $use_cpt = apply_filters( 'displayfeaturedimagegenesis_use_post_type_image', $this->post_types ); + $use_cpt = apply_filters( 'displayfeaturedimagegenesis_use_post_type_image', array() ); if ( in_array( get_post_type(), $use_cpt ) ) { return $image_id; } @@ -205,7 +198,7 @@ class Display_Featured_Image_Genesis_Common { * create filter to use taxonomy image if single post doesn't have a thumbnail, but one of its terms does. * @var filter */ - $use_tax_image = apply_filters( 'display_featured_image_genesis_use_taxonomy', $this->post_types ); + $use_tax_image = apply_filters( 'display_featured_image_genesis_use_taxonomy', array() ); if ( in_array( get_post_type(), $use_tax_image ) ) { return $image_id; @@ -241,11 +234,9 @@ class Display_Featured_Image_Genesis_Common { if ( is_singular() ) { $title = get_the_title(); - } - elseif ( is_home() && 'page' === $frontpage ) { + } elseif ( is_home() && 'page' === $frontpage ) { $title = get_post( $postspage )->post_title; - } - elseif ( is_category() || is_tag() || is_tax() ) { + } elseif ( is_category() || is_tag() || is_tax() ) { $term = is_tax() ? get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ) : get_queried_object(); if ( ! $term || ! isset( $term->meta ) ) { return; @@ -254,14 +245,12 @@ class Display_Featured_Image_Genesis_Common { if ( empty( $title ) && $a11ycheck ) { $title = $term->name; } - } - elseif ( is_author() ) { + } elseif ( is_author() ) { $title = get_the_author_meta( 'headline', (int) get_query_var( 'author' ) ); if ( empty( $title ) && $a11ycheck ) { $title = get_the_author_meta( 'display_name', (int) get_query_var( 'author' ) ); } - } - elseif ( is_post_type_archive() && genesis_has_post_type_archive_support() ) { + } elseif ( is_post_type_archive() && genesis_has_post_type_archive_support() ) { $title = genesis_get_cpt_option( 'headline' ); if ( empty( $title ) && $a11ycheck ) { $title = post_type_archive_title( '', false ); @@ -289,7 +278,7 @@ class Display_Featured_Image_Genesis_Common { } // If there is no url, return. - if ( '' == $attachment_url ) { + if ( '' === $attachment_url ) { return; } diff --git a/includes/class-displayfeaturedimagegenesis-output.php b/includes/class-displayfeaturedimagegenesis-output.php index fd569a6..e0c7dce 100644 --- a/includes/class-displayfeaturedimagegenesis-output.php +++ b/includes/class-displayfeaturedimagegenesis-output.php @@ -9,9 +9,14 @@ class Display_Featured_Image_Genesis_Output { + protected $common; + protected $description; + protected $displaysetting; + public function __construct( $common, $description ) { - $this->common = $common; - $this->description = $description; + $this->common = $common; + $this->description = $description; + $this->displaysetting = get_option( 'displayfeaturedimagegenesis' ); } /** @@ -21,14 +26,8 @@ class Display_Featured_Image_Genesis_Output { */ public function manage_output() { - $displaysetting = get_option( 'displayfeaturedimagegenesis' ); - $skip = $displaysetting['exclude_front']; - - $post_types = array(); - $post_types[] = 'attachment'; - $post_types[] = 'revision'; - $post_types[] = 'nav_menu_item'; - + $skip = $this->displaysetting['exclude_front']; + $post_types = array( 'attachment', 'revision', 'nav_menu_item' ); $skipped_types = apply_filters( 'display_featured_image_genesis_skipped_posttypes', $post_types ); if ( is_admin() || ( in_array( get_post_type(), $skipped_types ) ) || ( $skip && is_front_page() ) ) { @@ -56,44 +55,36 @@ class Display_Featured_Image_Genesis_Output { $width = absint( $item->backstretch[1] ); // check if they have enabled display on subsequent pages - $displaysetting = get_option( 'displayfeaturedimagegenesis' ); - $is_paged = ! empty( $displaysetting['is_paged'] ) ? $displaysetting['is_paged'] : 0; + $is_paged = ! empty( $this->displaysetting['is_paged'] ) ? $this->displaysetting['is_paged'] : 0; - // if there is no backstretch image set, or it is too small, or it's page 2+ and they didn't change the setting, die - if ( empty( $item->backstretch ) || $width <= $medium || ( is_paged() && ! $is_paged ) ) { + // if there is no backstretch image set, or it is too small, or the image is in the content, or it's page 2+ and they didn't change the setting, die + if ( empty( $item->backstretch ) || $width <= $medium || ( is_paged() && ! $is_paged ) || ( is_singular() && false !== $item->content ) ) { return; } - // if the featured image is not part of the content, or we're not on a singular page, carry on - if ( false === $item->content || ! is_singular() ) { - $css_file = apply_filters( 'display_featured_image_genesis_css_file', plugin_dir_url( __FILE__ ) . 'css/display-featured-image-genesis.css' ); - wp_enqueue_style( 'displayfeaturedimage-style', esc_url( $css_file ), array(), $version ); + $css_file = apply_filters( 'display_featured_image_genesis_css_file', plugin_dir_url( __FILE__ ) . 'css/display-featured-image-genesis.css' ); + wp_enqueue_style( 'displayfeaturedimage-style', esc_url( $css_file ), array(), $version ); - $post_types = array(); - $force_backstretch = apply_filters( 'display_featured_image_genesis_force_backstretch', $post_types ); - // check if the image is large enough for backstretch - if ( $width > $large || in_array( get_post_type(), $force_backstretch ) ) { + $force_backstretch = apply_filters( 'display_featured_image_genesis_force_backstretch', array() ); + // check if the image is large enough for backstretch + if ( $width > $large || in_array( get_post_type(), $force_backstretch ) ) { - 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 ); + 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 ); - $hook = apply_filters( 'display_featured_image_move_backstretch_image', 'genesis_after_header' ); - add_action( esc_attr( $hook ), array( $this, 'do_backstretch_image_title' ) ); + $hook = apply_filters( 'display_featured_image_move_backstretch_image', 'genesis_after_header' ); + add_action( esc_attr( $hook ), array( $this, 'do_backstretch_image_title' ) ); + } elseif ( $width <= $large ) { // otherwise it's a large image. + + remove_action( 'genesis_before_loop', 'genesis_do_cpt_archive_title_description' ); + add_action( 'genesis_before_loop', 'genesis_do_cpt_archive_title_description', 15 ); + + $hook = 'genesis_before_loop'; + if ( is_singular() && ! is_page_template( 'page_blog.php' ) ) { + $hook = apply_filters( 'display_featured_image_genesis_move_large_image', $hook ); } - - // otherwise it's a large image. - 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 ); - - $hook = 'genesis_before_loop'; - if ( is_singular() && ! is_page_template( 'page_blog.php' ) ) { - $hook = apply_filters( 'display_featured_image_genesis_move_large_image', $hook ); - } - add_action( esc_attr( $hook ), array( $this, 'do_large_image' ), 12 ); // works for both HTML5 and XHTML - } + add_action( esc_attr( $hook ), array( $this, 'do_large_image' ), 12 ); // works for both HTML5 and XHTML } } @@ -111,8 +102,7 @@ class Display_Featured_Image_Genesis_Output { $width = absint( $item->backstretch[1] ); // check if they have enabled display on subsequent pages - $displaysetting = get_option( 'displayfeaturedimagegenesis' ); - $is_paged = ! empty( $displaysetting['is_paged'] ) ? $displaysetting['is_paged'] : 0; + $is_paged = ! empty( $this->displaysetting['is_paged'] ) ? $this->displaysetting['is_paged'] : 0; // if there is no backstretch image set, or it is too small, or it's page 2+ and they didn't change the setting, die if ( empty( $item->backstretch ) || $width <= $medium || ( is_paged() && ! $is_paged ) ) { @@ -122,8 +112,7 @@ class Display_Featured_Image_Genesis_Output { if ( false === $item->content || ! is_singular() ) { if ( $width > $large ) { $classes[] = 'has-leader'; - } - elseif ( $width <= $large ) { + } elseif ( $width <= $large ) { $classes[] = 'large-featured'; } } @@ -138,14 +127,13 @@ class Display_Featured_Image_Genesis_Output { */ public function do_backstretch_image_title() { - $item = $this->common->get_image_variables(); - $displaysetting = get_option( 'displayfeaturedimagegenesis' ); - $keep_titles = $displaysetting['keep_titles']; + $item = $this->common->get_image_variables(); + $keep_titles = $this->displaysetting['keep_titles']; // backstretch settings from plugin/featured image settings $backstretch_settings = array( 'src' => esc_url( $item->backstretch[0] ), - 'height' => absint( $displaysetting['less_header'] ), + 'height' => absint( $this->displaysetting['less_header'] ), ); // backstretch settings which can be filtered $backstretch_variables = array( @@ -164,8 +152,7 @@ class Display_Featured_Image_Genesis_Output { * @var filter * @since 2.2.0 */ - $post_types = array(); - $do_not_move_title = apply_filters( 'display_featured_image_genesis_do_not_move_titles', $post_types ); + $do_not_move_title = apply_filters( 'display_featured_image_genesis_do_not_move_titles', array() ); // if titles will be moved to overlay backstretch image if ( ! $keep_titles && ! in_array( get_post_type(), $do_not_move_title ) ) { @@ -184,14 +171,13 @@ class Display_Featured_Image_Genesis_Output { do_action( 'display_featured_image_genesis_before_title' ); - $move_excerpts = $displaysetting['move_excerpts']; - $post_types = array(); + $move_excerpts = $this->displaysetting['move_excerpts']; /** * create a filter to not move excerpts if move excerpts is enabled * @var filter * @since 2.0.0 (deprecated old function from 1.3.3) */ - $omit_excerpt = apply_filters( 'display_featured_image_genesis_omit_excerpt', $post_types ); + $omit_excerpt = apply_filters( 'display_featured_image_genesis_omit_excerpt', array() ); // if move excerpts is enabled if ( $move_excerpts && ! in_array( get_post_type(), $omit_excerpt ) ) { @@ -202,10 +188,7 @@ class Display_Featured_Image_Genesis_Output { genesis_do_author_title_description(); genesis_do_cpt_archive_title_description(); - } - - // if titles are being moved to overlay the image - elseif ( ! $keep_titles && ! in_array( get_post_type(), $do_not_move_title ) ) { + } elseif ( ! $keep_titles && ! in_array( get_post_type(), $do_not_move_title ) ) { // if titles are being moved to overlay the image if ( ! empty( $item->title ) && ! is_front_page() ) { diff --git a/includes/class-displayfeaturedimagegenesis-settings.php b/includes/class-displayfeaturedimagegenesis-settings.php index c1eb048..fb2f322 100644 --- a/includes/class-displayfeaturedimagegenesis-settings.php +++ b/includes/class-displayfeaturedimagegenesis-settings.php @@ -13,7 +13,10 @@ class Display_Featured_Image_Genesis_Settings { * variable set for featured image option * @var option */ - protected $common, $page, $displaysetting, $post_types; + protected $common; + protected $page; + protected $displaysetting; + protected $post_types; public function __construct( $common ) { $this->common = $common; @@ -165,7 +168,7 @@ class Display_Featured_Image_Genesis_Settings { 'title' => esc_attr( $post->label ), 'callback' => 'set_cpt_image', 'section' => $sections['cpt']['id'], - 'args' => array( 'post_type' => $post, ), + 'args' => array( 'post_type' => $post ), ); } }