diff --git a/includes/class-displayfeaturedimagegenesis-admin.php b/includes/class-displayfeaturedimagegenesis-admin.php
index 0c6b21e..9812bae 100644
--- a/includes/class-displayfeaturedimagegenesis-admin.php
+++ b/includes/class-displayfeaturedimagegenesis-admin.php
@@ -105,7 +105,7 @@ class Display_Featured_Image_Genesis_Admin {
$taxonomy = filter_input( INPUT_POST, 'taxonomy', FILTER_SANITIZE_STRING );
$taxonomy = ! is_null( $taxonomy ) ? $taxonomy : get_current_screen()->taxonomy;
$alt = get_term( $term_id, $taxonomy )->name;
- $id = is_numeric( $term_meta['term_image'] ) ? $term_meta['term_image'] : $this->common->get_image_id( $term_meta['term_image'] );
+ $id = is_numeric( $term_meta['term_image'] ) ? $term_meta['term_image'] : Display_Featured_Image_Genesis_Common::get_image_id( $term_meta['term_image'] );
$preview = apply_filters(
'display_featured_image_genesis_admin_term_thumbnail',
diff --git a/includes/class-displayfeaturedimagegenesis-common.php b/includes/class-displayfeaturedimagegenesis-common.php
index d52abd9..f1ed3d1 100644
--- a/includes/class-displayfeaturedimagegenesis-common.php
+++ b/includes/class-displayfeaturedimagegenesis-common.php
@@ -21,7 +21,7 @@ class Display_Featured_Image_Genesis_Common {
*
* @since 1.1.0
*/
- public function get_image_variables() {
+ public static function get_image_variables() {
$item = new stdClass();
@@ -60,7 +60,7 @@ class Display_Featured_Image_Genesis_Common {
*
* @since 2.2.0
*/
- $image_id = apply_filters( 'display_featured_image_genesis_image_id', $this->set_image_id() );
+ $image_id = apply_filters( 'display_featured_image_genesis_image_id', self::set_image_id() );
$item->backstretch = wp_get_attachment_image_src( $image_id, $image_size );
@@ -94,7 +94,7 @@ class Display_Featured_Image_Genesis_Common {
}
// $title is set by new title function
- $title = $this->set_item_title();
+ $title = self::set_item_title();
/**
* Optional filter to change the title text
@@ -112,7 +112,7 @@ class Display_Featured_Image_Genesis_Common {
*
* @since 2.2.1
*/
- protected function set_image_id( $image_id = '' ) {
+ protected static function set_image_id( $image_id = '' ) {
$frontpage = get_option( 'show_on_front' ); // either 'posts' or 'page'
$postspage = get_option( 'page_for_posts' );
@@ -131,7 +131,7 @@ class Display_Featured_Image_Genesis_Common {
$fallback_id = $fallback;
if ( ! is_numeric( $fallback ) ) {
- $fallback_id = $this->get_image_id( $fallback ); // gets image id with attached metadata
+ $fallback_id = self::get_image_id( $fallback ); // gets image id with attached metadata
}
$fallback_id = absint( $fallback_id );
@@ -169,7 +169,7 @@ class Display_Featured_Image_Genesis_Common {
$post_type = $object->post_type;
}
if ( ! empty( $displaysetting['post_type'][ $post_type ] ) ) {
- $image_id = is_numeric( $displaysetting['post_type'][ $post_type ] ) ? $displaysetting['post_type'][ $post_type ] : $this->get_image_id( $displaysetting['post_type'][ $post_type ] );
+ $image_id = is_numeric( $displaysetting['post_type'][ $post_type ] ) ? $displaysetting['post_type'][ $post_type ] : self::get_image_id( $displaysetting['post_type'][ $post_type ] );
/**
* use the custom post type featured image
@@ -188,7 +188,7 @@ class Display_Featured_Image_Genesis_Common {
$term_meta = get_option( "displayfeaturedimagegenesis_$t_id" );
// if there is a term image
if ( ! empty( $term_meta['term_image'] ) ) {
- $image_id = is_numeric( $term_meta['term_image'] ) ? $term_meta['term_image'] : $this->get_image_id( $term_meta['term_image'] );
+ $image_id = is_numeric( $term_meta['term_image'] ) ? $term_meta['term_image'] : self::get_image_id( $term_meta['term_image'] );
}
}
@@ -222,7 +222,7 @@ class Display_Featured_Image_Genesis_Common {
}
- protected function set_item_title( $title = '' ) {
+ protected static function set_item_title( $title = '' ) {
$frontpage = get_option( 'show_on_front' ); // either 'posts' or 'page'
$postspage = get_option( 'page_for_posts' );
@@ -264,7 +264,7 @@ class Display_Featured_Image_Genesis_Common {
* @author Philip Newcomer
* @link http://philipnewcomer.net/2012/11/get-the-attachment-id-from-an-image-url-in-wordpress/
*/
- public function get_image_id( $attachment_url = '' ) {
+ public static function get_image_id( $attachment_url = '' ) {
$attachment_id = false;
diff --git a/includes/class-displayfeaturedimagegenesis-output.php b/includes/class-displayfeaturedimagegenesis-output.php
index e0c7dce..ebc1a45 100644
--- a/includes/class-displayfeaturedimagegenesis-output.php
+++ b/includes/class-displayfeaturedimagegenesis-output.php
@@ -12,6 +12,7 @@ class Display_Featured_Image_Genesis_Output {
protected $common;
protected $description;
protected $displaysetting;
+ protected $item;
public function __construct( $common, $description ) {
$this->common = $common;
@@ -26,6 +27,7 @@ class Display_Featured_Image_Genesis_Output {
*/
public function manage_output() {
+ $this->item = Display_Featured_Image_Genesis_Common::get_image_variables();
$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 );
@@ -49,16 +51,15 @@ class Display_Featured_Image_Genesis_Output {
public function load_scripts() {
$version = $this->common->version;
- $item = $this->common->get_image_variables();
$large = $this->common->minimum_backstretch_width();
$medium = absint( get_option( 'medium_size_w' ) );
- $width = absint( $item->backstretch[1] );
+ $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( $item->backstretch ) || $width <= $medium || ( is_paged() && ! $is_paged ) || ( is_singular() && false !== $item->content ) ) {
+ if ( empty( $this->item->backstretch ) || $width <= $medium || ( is_paged() && ! $is_paged ) || ( is_singular() && false !== $this->item->content ) ) {
return;
}
@@ -96,20 +97,19 @@ class Display_Featured_Image_Genesis_Output {
*/
public function add_body_class( $classes ) {
- $item = $this->common->get_image_variables();
$large = $this->common->minimum_backstretch_width();
$medium = absint( get_option( 'medium_size_w' ) );
- $width = absint( $item->backstretch[1] );
+ $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 it's page 2+ and they didn't change the setting, die
- if ( empty( $item->backstretch ) || $width <= $medium || ( is_paged() && ! $is_paged ) ) {
+ if ( empty( $this->item->backstretch ) || $width <= $medium || ( is_paged() && ! $is_paged ) ) {
return $classes;
}
- if ( false === $item->content || ! is_singular() ) {
+ if ( false === $this->item->content || ! is_singular() ) {
if ( $width > $large ) {
$classes[] = 'has-leader';
} elseif ( $width <= $large ) {
@@ -127,12 +127,11 @@ class Display_Featured_Image_Genesis_Output {
*/
public function do_backstretch_image_title() {
- $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] ),
+ 'src' => esc_url( $this->item->backstretch[0] ),
'height' => absint( $this->displaysetting['less_header'] ),
);
// backstretch settings which can be filtered
@@ -190,7 +189,7 @@ class Display_Featured_Image_Genesis_Output {
} 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() ) {
+ if ( ! empty( $this->item->title ) && ! is_front_page() ) {
$class = 'archive-title';
if ( is_singular() ) {
@@ -201,7 +200,7 @@ class Display_Featured_Image_Genesis_Output {
if ( genesis_html5() ) {
$itemprop = 'itemprop="headline"';
}
- $title = $item->title;
+ $title = $this->item->title;
$title_output = sprintf( '
%s
', $class, $itemprop, $title );
$title_output = apply_filters( 'display_featured_image_genesis_modify_title_overlay', $title_output, esc_attr( $class ), esc_attr( $itemprop ), $title );
@@ -224,7 +223,7 @@ class Display_Featured_Image_Genesis_Output {
echo '';
// if javascript not enabled, do a fallback background image
- printf( '', esc_url( $item->backstretch[0] ) );
+ printf( '', esc_url( $this->item->backstretch[0] ) );
// close big-leader
echo '';
@@ -237,10 +236,9 @@ class Display_Featured_Image_Genesis_Output {
* @since 1.0.0
*/
public function do_large_image() {
- $item = $this->common->get_image_variables();
$image = sprintf( '
',
- esc_url( $item->backstretch[0] ),
- esc_attr( $item->title )
+ esc_url( $this->item->backstretch[0] ),
+ esc_attr( $this->item->title )
);
$image = apply_filters( 'display_featured_image_genesis_large_image_output', $image );
diff --git a/includes/class-displayfeaturedimagegenesis-settings.php b/includes/class-displayfeaturedimagegenesis-settings.php
index fb2f322..05eca82 100644
--- a/includes/class-displayfeaturedimagegenesis-settings.php
+++ b/includes/class-displayfeaturedimagegenesis-settings.php
@@ -281,7 +281,7 @@ class Display_Featured_Image_Genesis_Settings {
*/
public function set_cpt_image( $args ) {
- $item = $this->common->get_image_variables();
+ $item = Display_Featured_Image_Genesis_Common::get_image_variables();
$post_type = $args['post_type']->name;
if ( empty( $this->displaysetting['post_type'][ $post_type ] ) ) {
@@ -320,7 +320,7 @@ class Display_Featured_Image_Genesis_Settings {
}
if ( ! is_numeric( $id ) ) {
- $id = $this->common->get_image_id( $id );
+ $id = Display_Featured_Image_Genesis_Common::get_image_id( $id );
}
$preview = wp_get_attachment_image_src( absint( $id ), 'medium' );
@@ -339,7 +339,7 @@ class Display_Featured_Image_Genesis_Settings {
* @since x.y.z
*/
public function render_buttons( $id, $name ) {
- $id = is_numeric( $id ) ? $id : $this->common->get_image_id( $id );
+ $id = is_numeric( $id ) ? $id : Display_Featured_Image_Genesis_Common::get_image_id( $id );
$id = $id ? (int) $id : '';
printf( '', esc_attr( $name ), $id );
printf( '',
@@ -446,10 +446,10 @@ class Display_Featured_Image_Genesis_Settings {
// if the image was selected using the old URL method
if ( ! is_numeric( $new_value ) ) {
- $new_value = (int) $this->common->get_image_id( $new_value );
+ $new_value = (int) Display_Featured_Image_Genesis_Common::get_image_id( $new_value );
}
if ( ! is_numeric( $old_value ) ) {
- $old_value = (int) $this->common->get_image_id( $old_value );
+ $old_value = (int) Display_Featured_Image_Genesis_Common::get_image_id( $old_value );
}
$source = wp_get_attachment_image_src( $new_value, 'full' );
$valid = $this->is_valid_img_ext( $source[0] );
@@ -497,7 +497,7 @@ class Display_Featured_Image_Genesis_Settings {
// if the image was selected using the old URL method
if ( ! is_numeric( $new_value ) ) {
- $new_value = $this->common->get_image_id( $new_value );
+ $new_value = Display_Featured_Image_Genesis_Common::get_image_id( $new_value );
}
$new_value = (int) $new_value;
$medium = get_option( 'medium_size_w' );
diff --git a/includes/helper-functions.php b/includes/helper-functions.php
index 54de5ea..13b8f4e 100644
--- a/includes/helper-functions.php
+++ b/includes/helper-functions.php
@@ -26,11 +26,7 @@ function display_featured_image_genesis_get_term_image_id() {
$t_id = $term->term_id;
$term_meta = get_option( "displayfeaturedimagegenesis_$t_id" );
if ( ! empty( $term_meta['term_image'] ) ) {
- $image_id = $term_meta['term_image'];
- if ( ! is_numeric( $term_meta['term_image'] ) ) {
- $common = new Display_Featured_Image_Genesis_Common();
- $image_id = $common->get_image_id( $term_meta['term_image'] );
- }
+ $image_id = is_numeric( $term_meta['term_image'] ) ? $term_meta['term_image'] : Display_Featured_Image_Genesis_Common::get_image_id( $term_meta['term_image'] );
break;
}
}
@@ -66,11 +62,7 @@ function display_featured_image_genesis_get_default_image_id() {
$image_id = '';
$displaysetting = get_option( 'displayfeaturedimagegenesis' );
$fallback = $displaysetting['default'];
- $image_id = $fallback;
- if ( ! is_numeric( $fallback ) ) {
- $common = new Display_Featured_Image_Genesis_Common();
- $image_id = $common->get_image_id( $fallback ); // gets image id with attached metadata
- }
+ $image_id = is_numeric( $fallback ) ? $fallback : Display_Featured_Image_Genesis_Common::get_image_id( $fallback );
return absint( $image_id );
@@ -108,20 +100,14 @@ function display_featured_image_genesis_get_cpt_image_id() {
}
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 ] ) ) {
- $image_id = $displaysetting['post_type'][ $post_type ];
- if ( ! is_numeric( $displaysetting['post_type'][ $post_type ] ) ) {
- $common = new Display_Featured_Image_Genesis_Common();
- $image_id = $common->get_image_id( $displaysetting['post_type'][ $post_type ] );
- }
+ $image_id = is_numeric( $displaysetting['post_type'][ $post_type ] ) ? $displaysetting['post_type'][ $post_type ] : Display_Featured_Image_Genesis_Common::get_image_id( $displaysetting['post_type'][ $post_type ] );
}
return absint( $image_id );
diff --git a/includes/widgets/displayfeaturedimagegenesis-cpt-archive-widget.php b/includes/widgets/displayfeaturedimagegenesis-cpt-archive-widget.php
index 75ebc96..e9c93d9 100644
--- a/includes/widgets/displayfeaturedimagegenesis-cpt-archive-widget.php
+++ b/includes/widgets/displayfeaturedimagegenesis-cpt-archive-widget.php
@@ -107,10 +107,8 @@ class Display_Featured_Image_Genesis_Widget_CPT extends WP_Widget {
$image = '';
if ( 'post' === $instance['post_type'] ) {
$image_id = $postspage_image;
- }
- else {
- $common = new Display_Featured_Image_Genesis_Common();
- $image_id = is_numeric( $option['post_type'][ $post_type->name ] ) ? $option['post_type'][ $post_type->name ] : $common->get_image_id( $option['post_type'][ $post_type->name ] );
+ } else {
+ $image_id = is_numeric( $option['post_type'][ $post_type->name ] ) ? $option['post_type'][ $post_type->name ] : Display_Featured_Image_Genesis_Common::get_image_id( $option['post_type'][ $post_type->name ] );
}
$image_src = wp_get_attachment_image_src( $image_id, $instance['image_size'] );
if ( $image_src ) {
@@ -119,7 +117,7 @@ class Display_Featured_Image_Genesis_Widget_CPT extends WP_Widget {
if ( $instance['show_image'] && $image ) {
$role = empty( $instance['show_title'] ) ? '' : 'aria-hidden="true"';
- printf( '%s', $permalink, esc_html( $title ), esc_attr( $instance['image_alignment'] ), $role, $image );
+ printf( '%s', esc_url( $permalink ), esc_html( $title ), esc_attr( $instance['image_alignment'] ), esc_attr( $role ), $image );
}
if ( $instance['show_title'] ) {
@@ -138,8 +136,7 @@ class Display_Featured_Image_Genesis_Widget_CPT extends WP_Widget {
$intro_text = '';
if ( post_type_supports( $instance['post_type'], 'genesis-cpt-archives-settings' ) ) {
$intro_text = genesis_get_cpt_option( 'intro_text', $instance['post_type'] );
- }
- elseif ( 'post' === $instance['post_type'] ) {
+ } elseif ( 'post' === $instance['post_type'] ) {
$intro_text = get_post( $postspage )->post_excerpt;
if ( 'posts' === $frontpage || ( 'page' === $frontpage && ! $postspage ) ) {
$intro_text = get_bloginfo( 'description' );
diff --git a/includes/widgets/displayfeaturedimagegenesis-taxonomy-widget.php b/includes/widgets/displayfeaturedimagegenesis-taxonomy-widget.php
index 1cac0c2..12d0f16 100644
--- a/includes/widgets/displayfeaturedimagegenesis-taxonomy-widget.php
+++ b/includes/widgets/displayfeaturedimagegenesis-taxonomy-widget.php
@@ -97,8 +97,7 @@ class Display_Featured_Image_Genesis_Widget_Taxonomy extends WP_Widget {
}
if ( $term_meta ) {
- $common = new Display_Featured_Image_Genesis_Common();
- $image_id = is_numeric( $term_meta['term_image'] ) ? $term_meta['term_image'] : $common->get_image_id( $term_meta['term_image'] );
+ $image_id = is_numeric( $term_meta['term_image'] ) ? $term_meta['term_image'] : Display_Featured_Image_Genesis_Common::get_image_id( $term_meta['term_image'] );
$image_src = wp_get_attachment_image_src( $image_id, $instance['image_size'] );
if ( $image_src ) {
$image = '
';