From 437657faa60a5f21160ed7acf4bbbd84e484800d Mon Sep 17 00:00:00 2001 From: Robin Cornett Date: Tue, 3 Nov 2015 16:19:37 -0500 Subject: [PATCH] Add helper function to check whether plugin can proceed --- ...ass-displayfeaturedimagegenesis-output.php | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/includes/class-displayfeaturedimagegenesis-output.php b/includes/class-displayfeaturedimagegenesis-output.php index 58613ca..cb0f1f0 100644 --- a/includes/class-displayfeaturedimagegenesis-output.php +++ b/includes/class-displayfeaturedimagegenesis-output.php @@ -47,19 +47,9 @@ class Display_Featured_Image_Genesis_Output { */ public function load_scripts() { - $version = $this->common->version; - $large = $this->common->minimum_backstretch_width(); - $medium = absint( get_option( 'medium_size_w' ) ); - $width = absint( $this->item->backstretch[1] ); - - // check if they have enabled display on subsequent pages - $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 the image is in the content, or it's page 2+ and they didn't change the setting, die - if ( empty( $this->item->backstretch ) || $width <= $medium || ( is_paged() && ! $is_paged ) || ( is_singular() && false !== $this->item->content ) ) { + if ( ! $this->can_do_things() ) { return; } - $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 ); @@ -290,4 +280,23 @@ class Display_Featured_Image_Genesis_Output { remove_action( 'genesis_before_loop', 'genesis_do_blog_template_heading' ); remove_action( 'genesis_before_loop', 'genesis_do_posts_page_heading' ); } + + /** + * Check whether plugin can output backstretch or large image + * @return boolean checks featured image size. returns true if can proceed; false if cannot + * + * @since x.y.z + */ + protected function can_do_things() { + $medium = (int) get_option( 'medium_size_w' ); + $width = (int) $this->item->backstretch[1]; + + // check if they have enabled display on subsequent pages + $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 the image is in the content, or it's page 2+ and they didn't change the setting, die + if ( empty( $this->item->backstretch ) || $width <= $medium || ( is_paged() && ! $is_paged ) || ( is_singular() && false !== $this->item->content ) ) { + return false; + } + return true; + } }