From fbe3ec197fdba67ad19cb97801cef5054d5325b5 Mon Sep 17 00:00:00 2001 From: Robin Cornett Date: Mon, 4 Apr 2016 10:43:54 -0400 Subject: [PATCH] Fix conditionals to prevent plugin output early --- ...ass-displayfeaturedimagegenesis-output.php | 38 +++++++++++-------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/includes/class-displayfeaturedimagegenesis-output.php b/includes/class-displayfeaturedimagegenesis-output.php index e400968..5a68430 100644 --- a/includes/class-displayfeaturedimagegenesis-output.php +++ b/includes/class-displayfeaturedimagegenesis-output.php @@ -37,21 +37,7 @@ class Display_Featured_Image_Genesis_Output { public function manage_output() { $this->setting = displayfeaturedimagegenesis_get_setting(); - $exclude_front = $this->setting['exclude_front']; - $post_type = get_post_type(); - $skip = isset( $this->setting['skip'][ $post_type ] ) && $this->setting['skip'][ $post_type ] ? true : false; - /** - * Creates display_featured_image_genesis_skipped_posttypes filter to check - * whether get_post_type array should not run plugin on this post type. - * @uses is_in_array() - */ - $post_types = array( 'attachment', 'revision', 'nav_menu_item' ); - if ( is_admin() || Display_Featured_Image_Genesis_Common::is_in_array( 'skipped_posttypes', $post_types ) || $skip || ( $exclude_front && is_front_page() ) ) { - return; - } - - // if the output is disabled for this specific post, quit - if ( is_singular() && get_post_meta( get_the_ID(), '_displayfeaturedimagegenesis_disable', true ) ) { + if ( $this->quit_now() ) { return; } @@ -307,6 +293,28 @@ class Display_Featured_Image_Genesis_Output { remove_action( 'genesis_before_loop', 'genesis_do_posts_page_heading' ); } + /** + * Check plugin settings/filters to see if the featured image should output on this post/etc. at all. + * Returns true to quit now; false to carry on. + * @return bool + */ + protected function quit_now() { + $exclude_front = is_front_page() && $this->setting['exclude_front']; + $post_type = get_post_type(); + $skip_post_type = is_singular() && isset( $this->setting['skip'][ $post_type ] ) && $this->setting['skip'][ $post_type ] ? true : false; + $skip_singular = is_singular() && get_post_meta( get_the_ID(), '_displayfeaturedimagegenesis_disable', true ); + /** + * Creates display_featured_image_genesis_skipped_posttypes filter to check + * whether get_post_type array should not run plugin on this post type. + * @uses is_in_array() + */ + $post_types = array( 'attachment', 'revision', 'nav_menu_item' ); + if ( is_admin() || Display_Featured_Image_Genesis_Common::is_in_array( 'skipped_posttypes', $post_types ) || $skip_post_type || $exclude_front || $skip_singular ) { + return true; + } + return false; + } + /** * Check whether plugin can output backstretch or large image * @return boolean checks featured image size. returns true if can proceed; false if cannot