diff --git a/includes/class-displayfeaturedimagegenesis-common.php b/includes/class-displayfeaturedimagegenesis-common.php index 6e403fb..a69a875 100644 --- a/includes/class-displayfeaturedimagegenesis-common.php +++ b/includes/class-displayfeaturedimagegenesis-common.php @@ -34,14 +34,8 @@ class Display_Featured_Image_Genesis_Common { add_filter( 'jetpack_photon_override_image_downsize', '__return_true' ); // turn Photon off so we can get the correct image - /** - * create a filter for user to optionally force post types to use the large image instead of backstretch - * - * @since 2.0.0 - */ - $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, true ) ) { + $image_size = 'displayfeaturedimage_backstretch'; + if ( self::displayfeaturedimage_array( 'use_large_image' ) ) { $image_size = 'large'; } @@ -98,18 +92,10 @@ class Display_Featured_Image_Genesis_Common { $fallback = $displaysetting['default']; $fallback_id = displayfeaturedimagegenesis_check_image_id( $fallback ); - /** - * create a filter to use the fallback image - * @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', array() ); - // set here with fallback preemptively, if it exists if ( ! empty( $fallback ) ) { $image_id = $fallback_id; - - if ( in_array( get_post_type(), $use_fallback, true ) ) { + if ( self::displayfeaturedimage_array( 'use_default' ) ) { return (int) $image_id; } } @@ -127,14 +113,7 @@ class Display_Featured_Image_Genesis_Common { $post_type = get_post_type(); if ( ! empty( $displaysetting['post_type'][ $post_type ] ) ) { $image_id = displayfeaturedimagegenesis_check_image_id( $displaysetting['post_type'][ $post_type ] ); - - /** - * use the custom post type featured image - * - * @since 2.2.1 - */ - $use_cpt = apply_filters( 'displayfeaturedimagegenesis_use_post_type_image', array() ); - if ( in_array( get_post_type(), $use_cpt, true ) ) { + if ( self::displayfeaturedimage_array( 'use_post_type_image' ) ) { return (int) $image_id; } } @@ -156,14 +135,7 @@ class Display_Featured_Image_Genesis_Common { $term_image = display_featured_image_genesis_get_term_image_id(); if ( ! empty( $term_image ) ) { $image_id = $term_image; - - /** - * 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', array() ); - - if ( in_array( get_post_type(), $use_tax_image, true ) ) { + if ( self::displayfeaturedimage_array( 'use_taxonomy' ) ) { return (int) $image_id; } } @@ -292,6 +264,19 @@ class Display_Featured_Image_Genesis_Common { return empty( $result ) || ! is_numeric( $result[0] ) ? false : intval( $result[0] ); } + /** + * Set up filter to check for post type rules. Variable, based on $value passed in. + * @param $value string for filter name + * @param array $post_types affected post types (empty array by default) + * @return bool + * + * @since x.y.z + */ + public static function displayfeaturedimage_array( $value, $post_types = array() ) { + $post_types = apply_filters( "display_featured_image_genesis_$value", $post_types ); + return in_array( get_post_type(), $post_types, true ); + } + /** * add a filter to change the minimum width required for backstretch image * @return integer sets the minimum width for backstretch effect diff --git a/includes/class-displayfeaturedimagegenesis-output.php b/includes/class-displayfeaturedimagegenesis-output.php index f4ceb95..67286d8 100644 --- a/includes/class-displayfeaturedimagegenesis-output.php +++ b/includes/class-displayfeaturedimagegenesis-output.php @@ -25,9 +25,8 @@ class Display_Featured_Image_Genesis_Output { $this->displaysetting = $settings->get_display_setting(); $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, true ) ) || ( $skip && is_front_page() ) ) { + if ( is_admin() || ( Display_Featured_Image_Genesis_Common::displayfeaturedimage_array( 'skipped_posttypes', $post_types ) ) || ( $skip && is_front_page() ) ) { return; } @@ -52,11 +51,10 @@ class Display_Featured_Image_Genesis_Output { wp_enqueue_style( 'displayfeaturedimage-style', esc_url( $css_file ), array(), $this->common->version ); add_filter( 'body_class', array( $this, 'add_body_class' ) ); - $large = $this->common->minimum_backstretch_width(); - $width = absint( $this->item->backstretch[1] ); - $force_backstretch = apply_filters( 'display_featured_image_genesis_force_backstretch', array() ); + $large = $this->common->minimum_backstretch_width(); + $width = absint( $this->item->backstretch[1] ); - if ( $width > $large || in_array( get_post_type(), $force_backstretch, true ) ) { + if ( $width > $large || Display_Featured_Image_Genesis_Common::displayfeaturedimage_array( 'force_backstretch' ) ) { $this->do_backstretch_image_things(); } else { $this->do_large_image_things(); @@ -305,9 +303,7 @@ class Display_Featured_Image_Genesis_Output { */ protected function move_excerpts() { $move_excerpts = $this->displaysetting['move_excerpts']; - $omit_excerpt = apply_filters( 'display_featured_image_genesis_omit_excerpt', array() ); - - if ( $move_excerpts && ! in_array( get_post_type(), $omit_excerpt, true ) ) { + if ( $move_excerpts && ! Display_Featured_Image_Genesis_Common::displayfeaturedimage_array( 'omit_excerpt' ) ) { return true; } return false; @@ -319,11 +315,9 @@ class Display_Featured_Image_Genesis_Output { * @since 2.2.0 */ protected function move_title() { - $do_not_move_title = apply_filters( 'display_featured_image_genesis_do_not_move_titles', array() ); $keep_titles = $this->displaysetting['keep_titles']; - // if titles will be moved to overlay backstretch image - if ( ! $keep_titles && ! in_array( get_post_type(), $do_not_move_title, true ) ) { + if ( ! $keep_titles && ! Display_Featured_Image_Genesis_Common::displayfeaturedimage_array( 'do_not_move_titles' ) ) { return true; } return false; diff --git a/includes/class-displayfeaturedimagegenesis-rss.php b/includes/class-displayfeaturedimagegenesis-rss.php index 4351086..b9eb81e 100644 --- a/includes/class-displayfeaturedimagegenesis-rss.php +++ b/includes/class-displayfeaturedimagegenesis-rss.php @@ -20,11 +20,9 @@ class Display_Featured_Image_Genesis_RSS { $settings = new Display_Featured_Image_Genesis_Settings(); $displaysetting = $settings->get_display_setting(); $feed_image = $displaysetting['feed_image']; - $post_types = array(); - $skipped_types = apply_filters( 'display_featured_image_genesis_skipped_posttypes', $post_types ); // if the user isn't sending images to the feed, we're done - if ( ! $feed_image || ( in_array( get_post_type(), $skipped_types, true ) ) ) { + if ( ! $feed_image || Display_Featured_Image_Genesis_Common::displayfeaturedimage_array( 'skipped_posttypes' ) ) { return; }