diff --git a/includes/class-displayfeaturedimagegenesis-admin.php b/includes/class-displayfeaturedimagegenesis-admin.php index 8e8b347..a902f17 100644 --- a/includes/class-displayfeaturedimagegenesis-admin.php +++ b/includes/class-displayfeaturedimagegenesis-admin.php @@ -92,7 +92,10 @@ class Display_Featured_Image_Genesis_Admin { $term_meta = get_option( "displayfeaturedimagegenesis_$term_id" ); if ( ! empty( $term_meta['term_image'] ) ) { $alt_tag = get_term( $term_id, $taxonomy )->name; - $id = Display_Featured_Image_Genesis_Common::get_image_id( $term_meta['term_image'] ); + $id = $term_meta['term_image']; + if ( ! is_numeric( $term_meta['term_image'] ) ) { + $id = Display_Featured_Image_Genesis_Common::get_image_id( $term_meta['term_image'] ); + } $preview = apply_filters( 'display_featured_image_genesis_admin_term_thumbnail', wp_get_attachment_image_src( $id, 'thumbnail' ), $id ); echo '' . $alt_tag . ''; } diff --git a/includes/class-displayfeaturedimagegenesis-common.php b/includes/class-displayfeaturedimagegenesis-common.php index 18c2daa..5c3c682 100644 --- a/includes/class-displayfeaturedimagegenesis-common.php +++ b/includes/class-displayfeaturedimagegenesis-common.php @@ -13,7 +13,7 @@ class Display_Featured_Image_Genesis_Common { * @var string * @since 1.4.3 */ - public static $version = '2.1.0'; + public static $version = '2.2.0'; protected static $post_types; @@ -35,7 +35,7 @@ class Display_Featured_Image_Genesis_Common { $displaysetting = get_option( 'displayfeaturedimagegenesis' ); $move_excerpts = $displaysetting['move_excerpts']; $postspage_image = get_post_thumbnail_id( $postspage ); - $fallback = esc_attr( $displaysetting['default'] ); // url only + $fallback = $displaysetting['default']; // url only $medium = absint( get_option( 'medium_size_w' ) ); if ( is_singular() ) { // just checking for handling conditional variables set by width @@ -48,7 +48,11 @@ class Display_Featured_Image_Genesis_Common { // sitewide variables used outside this function $item->backstretch = ''; - $item->fallback_id = self::get_image_id( $fallback ); // gets image id with attached metadata + $fallback_id = $fallback; + if ( ! is_numeric( $fallback ) ) { + $fallback_id = self::get_image_id( $fallback ); // gets image id with attached metadata + } + $item->fallback_id = absint( $fallback_id ); // Set Featured Image source ID $image_id = ''; // blank if nothing else @@ -85,7 +89,11 @@ class Display_Featured_Image_Genesis_Common { $post_type = $object->post_type; } if ( ! empty( $displaysetting['post_type'][$post_type] ) ) { - $image_id = self::get_image_id( $displaysetting['post_type'][$post_type] ); + $image_id = $displaysetting['post_type'][$post_type]; + // if $image_id is using the old URL + if ( ! is_numeric( $displaysetting['post_type'][$post_type] ) ) { + $image_id = self::get_image_id( $displaysetting['post_type'][$post_type] ); + } } } // taxonomy @@ -94,7 +102,11 @@ 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 = self::get_image_id( $term_meta['term_image'] ); + $image_id = $term_meta['term_image']; + // if $image_id is using the old URL + if ( ! is_numeric( $term_meta['term_image'] ) ) { + $image_id = self::get_image_id( $term_meta['term_image'] ); + } } } // any singular post/page/CPT or there is no $fallback @@ -117,6 +129,9 @@ class Display_Featured_Image_Genesis_Common { } } + // make sure the image id is an integer + $image_id = absint( $image_id ); + // turn Photon off so we can get the correct image $photon_removed = ''; if ( class_exists( 'Jetpack' ) && Jetpack::is_module_active( 'photon' ) ) { @@ -134,6 +149,7 @@ class Display_Featured_Image_Genesis_Common { if ( in_array( get_post_type(), $use_large_image ) ) { $image_size = 'large'; } + $item->backstretch = wp_get_attachment_image_src( $image_id, $image_size ); // set a content variable so backstretch doesn't show if full size image exists in post. @@ -204,6 +220,11 @@ class Display_Featured_Image_Genesis_Common { global $wpdb; $attachment_id = false; + // as of 2.2.0, if a (new) image id is passed to the function, return it as is. + if ( is_int( $attachment_url ) ) { + return $attachment_url; + } + // If there is no url, return. if ( '' == $attachment_url ) { return; diff --git a/includes/class-displayfeaturedimagegenesis-output.php b/includes/class-displayfeaturedimagegenesis-output.php index 7843f22..adcdbbe 100644 --- a/includes/class-displayfeaturedimagegenesis-output.php +++ b/includes/class-displayfeaturedimagegenesis-output.php @@ -50,11 +50,15 @@ class Display_Featured_Image_Genesis_Output { $medium = absint( get_option( 'medium_size_w' ) ); $width = absint( $item->backstretch[1] ); - //* if there is no backstretch image set, or it is too small, die - if ( empty( $item->backstretch ) || $width <= $medium || is_paged() ) { + // check if they have enabled display on subsequent pages + $displaysetting = get_option( 'displayfeaturedimagegenesis' ); + $is_paged = $displaysetting['is_paged']; + + // 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 ) ) { return; } - //* if the featured image is not part of the content, or we're not on a singular page, carry on + // 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' ); @@ -62,7 +66,7 @@ class Display_Featured_Image_Genesis_Output { $post_types = array(); $force_backstretch = apply_filters( 'display_featured_image_genesis_force_backstretch', $post_types ); - //* check if the image is large enough for backstretch + // 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 ); @@ -73,7 +77,7 @@ class Display_Featured_Image_Genesis_Output { } - //* otherwise it's a large image. + // otherwise it's a large image. elseif ( $width <= $large ) { remove_action( 'genesis_before_loop', 'genesis_do_cpt_archive_title_description' ); @@ -101,7 +105,12 @@ class Display_Featured_Image_Genesis_Output { $medium = absint( get_option( 'medium_size_w' ) ); $width = absint( $item->backstretch[1] ); - if ( empty( $item->backstretch ) || $width <= $medium || is_paged() ) { + // check if they have enabled display on subsequent pages + $displaysetting = get_option( 'displayfeaturedimagegenesis' ); + $is_paged = $displaysetting['is_paged']; + + // 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 ) ) { return $classes; } @@ -228,7 +237,7 @@ class Display_Featured_Image_Genesis_Output { */ public function do_large_image() { $item = Display_Featured_Image_Genesis_Common::get_image_variables(); - $image = sprintf( '%2$s', + $image = sprintf( '%2$s', esc_url( $item->backstretch[0] ), $item->title ); diff --git a/includes/class-displayfeaturedimagegenesis-rss.php b/includes/class-displayfeaturedimagegenesis-rss.php index 6b83081..e5b439e 100644 --- a/includes/class-displayfeaturedimagegenesis-rss.php +++ b/includes/class-displayfeaturedimagegenesis-rss.php @@ -28,14 +28,15 @@ class Display_Featured_Image_Genesis_RSS { return; } - //* if the feed is full text, filter the content + // if the feed is summary, filter the excerpt + $which_filter = 'the_excerpt_rss'; + $priority = 1000; + // if the feed is full text, filter the content if ( '0' === $rss_option ) { - add_filter( 'the_content_feed', array( $this, 'add_image_to_feed' ), 15 ); - } - //* if the feed is summaries, filter the excerpt, not the content - else { - add_filter( 'the_excerpt_rss', array( $this, 'add_image_to_feed' ), 1000, 1 ); + $which_filter = 'the_content_feed'; + $priority = 15; } + add_filter( $which_filter, array( $this, 'add_image_to_feed' ), $priority ); } @@ -48,12 +49,12 @@ class Display_Featured_Image_Genesis_RSS { */ public function add_image_to_feed( $content ) { - //* if the post doesn't have a thumbnail, we're done here + // if the post doesn't have a thumbnail, we're done here if ( ! has_post_thumbnail() ) { return $content; } - //* first check: see if the featured image already exists in full in the content + // first check: see if the featured image already exists in full in the content $size = 'original'; if ( class_exists( 'SendImagesRSS' ) ) { $simplify = get_option( 'sendimagesrss_simplify_feed' ); @@ -68,28 +69,28 @@ class Display_Featured_Image_Genesis_RSS { $image_content = strpos( $content, 'src="' . $post_thumbnail[0] ); $rss_option = get_option( 'rss_use_excerpt' ); - //* if the featured image already exists in all its glory in the content, we're done here + // if the featured image already exists in all its glory in the content, we're done here if ( false !== $image_content && '0' === $rss_option ) { return $content; } - //* reset size to large so we don't send huge files to the feed + // reset size to large so we don't send huge files to the feed $size = 'large'; if ( class_exists( 'SendImagesRSS' ) ) { $simplify = get_option( 'sendimagesrss_simplify_feed' ); $alt_feed = get_option( 'sendimagesrss_alternate_feed' ); - //* if the user is using Send Images to RSS, send the right images to the right feeds + // if the user is using Send Images to RSS, send the right images to the right feeds if ( ! $simplify && ( ( $alt_feed && is_feed( 'email' ) ) || ! $alt_feed ) ) { $size = 'mailchimp'; $class = 'rss-mailchimp'; } } - $align = ''; - $style = 'display:block;margin:10px auto;'; - $class = 'rss-featured-image'; + $align = ''; + $style = 'display:block;margin:10px auto;'; + $class = 'rss-featured-image'; - //* if the feed output is descriptions only, change image size to thumbnail with small alignment + // if the feed output is descriptions only, change image size to thumbnail with small alignment if ( '1' === $rss_option ) { $size = 'thumbnail'; $align = 'left'; @@ -97,8 +98,9 @@ class Display_Featured_Image_Genesis_RSS { $class = 'rss-small'; } - //* whew. build the image! - $image = get_the_post_thumbnail( get_the_ID(), $size, array( 'align' => $align, 'style' => $style, 'class' => $class ) ); + // whew. build the image! + $image = get_the_post_thumbnail( get_the_ID(), $size, array( 'align' => $align, 'style' => $style, 'class' => $class ) ); + $image = apply_filters( 'display_featured_image_genesis_modify_rss_image', $image ); $content = $image . $content; @@ -106,4 +108,4 @@ class Display_Featured_Image_Genesis_RSS { } -} \ No newline at end of file +} diff --git a/includes/class-displayfeaturedimagegenesis-settings.php b/includes/class-displayfeaturedimagegenesis-settings.php index dec7d23..c948483 100644 --- a/includes/class-displayfeaturedimagegenesis-settings.php +++ b/includes/class-displayfeaturedimagegenesis-settings.php @@ -74,7 +74,8 @@ class Display_Featured_Image_Genesis_Settings { 'exclude_front' => 0, 'keep_titles' => 0, 'move_excerpts' => 0, - 'feed_image' => 0 + 'is_paged' => 0, + 'feed_image' => 0, ); $this->displaysetting = get_option( 'displayfeaturedimagegenesis', $defaults ); @@ -126,6 +127,14 @@ class Display_Featured_Image_Genesis_Settings { 'display_featured_image_section' ); + add_settings_field( + 'displayfeaturedimagegenesis[is_paged]', + '', + array( $this, 'check_is_paged' ), + 'displayfeaturedimagegenesis', + 'display_featured_image_section' + ); + add_settings_field( 'displayfeaturedimagegenesis[feed_image]', '', @@ -207,17 +216,24 @@ class Display_Featured_Image_Genesis_Settings { */ public function set_default_image() { - $item = Display_Featured_Image_Genesis_Common::get_image_variables(); $large = Display_Featured_Image_Genesis_Common::minimum_backstretch_width(); + $id = ''; if ( ! empty( $this->displaysetting['default'] ) ) { - $preview = wp_get_attachment_image_src( $item->fallback_id, 'medium' ); + $id = $this->displaysetting['default']; + if ( ! is_numeric( $this->displaysetting['default'] ) ) { + $id = Display_Featured_Image_Genesis_Common::get_image_id( $this->displaysetting['default'] ); + } + $preview = wp_get_attachment_image_src( absint( $id ), 'medium' ); echo '
'; echo ''; echo '
'; } - echo ''; - echo ''; + echo ''; + echo ''; + if ( ! empty( $this->displaysetting['default'] ) ) { + echo ''; + } echo '

' . sprintf( __( 'If you would like to use a default image for the featured image, upload it here. Must be at least %1$s pixels wide.', 'display-featured-image-genesis' ), absint( $large + 1 ) @@ -257,6 +273,17 @@ class Display_Featured_Image_Genesis_Settings { echo ''; } + /** + * option to show featured image on page 2+ of blog/archives + * @return 0 1 checkbox + * + * @since 2.2.0 + */ + public function check_is_paged() { + echo ''; + echo ''; + } + /** * option to add images to feed * @return 0 1 checkbox @@ -283,25 +310,32 @@ class Display_Featured_Image_Genesis_Settings { $post_type = $post->name; if ( empty( $this->displaysetting['post_type'][$post_type] ) ) { - $this->displaysetting['post_type'][$post_type] = ''; + $this->displaysetting['post_type'][$post_type] = $id = ''; } + echo '

'; echo '

' . $post->label . '

'; if ( ! empty( $this->displaysetting['post_type'][$post_type] ) ) { - $id = Display_Featured_Image_Genesis_Common::get_image_id( $this->displaysetting['post_type'][$post_type] ); - $preview = wp_get_attachment_image_src( $id, 'medium' ); + $id = $this->displaysetting['post_type'][$post_type]; + if ( ! is_numeric( $this->displaysetting['post_type'][$post_type] ) ) { + $id = Display_Featured_Image_Genesis_Common::get_image_id( $this->displaysetting['post_type'][$post_type] ); + } + $preview = wp_get_attachment_image_src( absint( $id ), 'medium' ); echo '
'; echo ''; echo '
'; } - echo ''; - echo ''; + + echo ''; + echo ''; if ( ! empty( $this->displaysetting['post_type'][$post_type] ) ) { + echo ''; echo '

' . sprintf( __( 'View your %2$s archive.', 'display-featured-image-genesis' ), esc_url( get_post_type_archive_link( $post_type ) ), $post->label ) . '

'; } + echo '
'; } @@ -365,6 +399,8 @@ class Display_Featured_Image_Genesis_Settings { $new_value['move_excerpts'] = $this->one_zero( $new_value['move_excerpts'] ); + $new_value['is_paged'] = $this->one_zero( $new_value['is_paged'] ); + $new_value['feed_image'] = $this->one_zero( $new_value['feed_image'] ); foreach ( $this->post_types as $post_type ) { @@ -386,11 +422,14 @@ class Display_Featured_Image_Genesis_Settings { */ protected function validate_image( $new_value ) { - $new_value = esc_url( $new_value ); - $valid = $this->is_valid_img_ext( $new_value ); + // if the image was selected using the old URL method + if ( ! is_numeric( $new_value ) ) { + $new_value = Display_Featured_Image_Genesis_Common::get_image_id( $new_value ); + } + $new_value = absint( $new_value ); $large = Display_Featured_Image_Genesis_Common::minimum_backstretch_width(); - $id = Display_Featured_Image_Genesis_Common::get_image_id( $new_value ); - $source = wp_get_attachment_image_src( $id, 'full' ); + $source = wp_get_attachment_image_src( $new_value, 'full' ); + $valid = $this->is_valid_img_ext( $source[0] ); $width = $source[1]; $reset = __( ' The Default Featured Image has been reset to the last valid setting.', 'display-featured-image-genesis' ); @@ -408,18 +447,7 @@ class Display_Featured_Image_Genesis_Settings { 'error' ); } - // if the image is external to the WP site, we cannot use it. - elseif ( ! $source ) { - $message = __( 'Sorry, your image must be uploaded directly to your WordPress site.', 'display-featured-image-genesis' ) . $reset; - $new_value = $this->displaysetting['default']; - add_settings_error( - $this->displaysetting['default'], - esc_attr( 'external' ), - $message, - 'error' - ); - } // if file is an image, but is too small, throw it back elseif ( $width <= $large ) { $message = __( 'Sorry, your image is too small.', 'display-featured-image-genesis' ) . $reset; @@ -446,11 +474,14 @@ class Display_Featured_Image_Genesis_Settings { */ protected function validate_post_type_image( $new_value ) { - $new_value = esc_url( $new_value ); - $valid = $this->is_valid_img_ext( $new_value ); + // if the image was selected using the old URL method + if ( ! is_numeric( $new_value ) ) { + $new_value = Display_Featured_Image_Genesis_Common::get_image_id( $new_value ); + } + $new_value = absint( $new_value ); $medium = get_option( 'medium_size_w' ); - $id = Display_Featured_Image_Genesis_Common::get_image_id( $new_value ); - $source = wp_get_attachment_image_src( $id, 'full' ); + $source = wp_get_attachment_image_src( $new_value, 'full' ); + $valid = $this->is_valid_img_ext( $source[0] ); $width = $source[1]; // ok for field to be empty @@ -467,18 +498,7 @@ class Display_Featured_Image_Genesis_Settings { 'error' ); } - // if the image is external to the WP site, we cannot use it. - elseif ( ! $source ) { - $message = __( 'Sorry, your image must be uploaded directly to your WordPress site.', 'display-featured-image-genesis' ); - $new_value = false; - add_settings_error( - $this->displaysetting['default'], - esc_attr( 'external' ), - $message, - 'error' - ); - } // if file is an image, but is too small, throw it back elseif ( $width <= $medium ) { $message = __( 'Sorry, your image is too small.', 'display-featured-image-genesis' ); @@ -505,11 +525,14 @@ class Display_Featured_Image_Genesis_Settings { */ protected function validate_taxonomy_image( $new_value ) { - $new_value = esc_url( $new_value ); - $valid = $this->is_valid_img_ext( $new_value ); + // if the image was selected using the old URL method + if ( ! is_numeric( $new_value ) ) { + $new_value = Display_Featured_Image_Genesis_Common::get_image_id( $new_value ); + } + $new_value = absint( $new_value ); $medium = get_option( 'medium_size_w' ); - $id = Display_Featured_Image_Genesis_Common::get_image_id( $new_value ); - $source = wp_get_attachment_image_src( $id, 'full' ); + $source = wp_get_attachment_image_src( $new_value, 'full' ); + $valid = $this->is_valid_img_ext( $source[0] ); $width = $source[1]; // ok for field to be empty @@ -598,6 +621,10 @@ class Display_Featured_Image_Genesis_Settings { '

' . __( 'Move Excerpts/Archive Descriptions', 'display-featured-image-genesis' ) . '

' . '

' . __( 'By default, archive descriptions (set on the Genesis Archive Settings pages) show below the Default Featured Image, while the archive title displays on top of the image. If you check this box, all headlines, descriptions, and optional excerpts will display in a box overlaying the Featured Image.', 'display-featured-image-genesis' ) . '

'; + $paged_help = + '

' . __( 'Show Featured Image on Subsequent Blog Pages', 'display-featured-image-genesis' ) . '

' . + '

' . __( 'Featured Images do not normally show on the second (and following) page of term/blog/post archives. Check this setting to ensure that they do.', 'display-featured-image-genesis' ) . '

'; + $feed_help = '

' . __( 'Add Featured Image to Feed?', 'display-featured-image-genesis' ) . '

' . '

' . __( 'This plugin does not add the Featured Image to your content, so normally you will not see your Featured Image in the feed. If you select this option, however, the Featured Image (if it is set) will be added to each entry in your RSS feed.', 'display-featured-image-genesis' ) . '

' . @@ -640,6 +667,12 @@ class Display_Featured_Image_Genesis_Settings { 'content' => $excerpts_help, ) ); + $screen->add_help_tab( array( + 'id' => 'displayfeaturedimage_paged-help', + 'title' => __( 'Subsequent Pages', 'display-featured-image-genesis' ), + 'content' => $paged_help, + ) ); + $screen->add_help_tab( array( 'id' => 'displayfeaturedimage_feed-help', 'title' => __( 'RSS Feed', 'display-featured-image-genesis' ), diff --git a/includes/class-displayfeaturedimagegenesis-taxonomies.php b/includes/class-displayfeaturedimagegenesis-taxonomies.php index 0db505f..69d7c27 100644 --- a/includes/class-displayfeaturedimagegenesis-taxonomies.php +++ b/includes/class-displayfeaturedimagegenesis-taxonomies.php @@ -14,11 +14,14 @@ class Display_Featured_Image_Genesis_Taxonomies { */ public function add_taxonomy_meta_fields() { - echo '
'; + $tax = get_current_screen()->taxonomy; + + echo '
'; echo ''; - echo ''; - echo ''; - echo '

' . __( 'Set Featured Image for Taxonomy','display-featured-image-genesis' ) . '

'; + echo ''; + echo ''; + echo ''; + echo '

' . sprintf( __( 'Set Featured Image for new %s','display-featured-image-genesis' ), $tax ) . '

'; echo '
'; } @@ -36,19 +39,26 @@ class Display_Featured_Image_Genesis_Taxonomies { $t_id = $term->term_id; $displaysetting = get_option( "displayfeaturedimagegenesis_$t_id" ); $medium = get_option( 'medium_size_w' ); + $id = ''; - echo ''; + echo ''; echo ''; echo ''; if ( ! empty( $displaysetting['term_image'] ) ) { - $id = Display_Featured_Image_Genesis_Common::get_image_id( $displaysetting['term_image'] ); - $preview = wp_get_attachment_image_src( $id, 'medium' ); + $id = $displaysetting['term_image']; + if ( ! is_numeric( $displaysetting['term_image'] ) ) { + $id = Display_Featured_Image_Genesis_Common::get_image_id( $displaysetting['term_image'] ); + } + $preview = wp_get_attachment_image_src( absint( $id ), 'medium' ); echo '
'; echo ''; echo '
'; } - echo ''; - echo ''; + echo ''; + echo ''; + if ( ! empty( $displaysetting['term_image'] ) ) { + echo ''; + } echo '

' . sprintf( __( 'Set Featured Image for %1$s.', 'display-featured-image-genesis' ), esc_html( $term->name ) diff --git a/includes/class-displayfeaturedimagegenesis.php b/includes/class-displayfeaturedimagegenesis.php index 5697d5c..13e1304 100644 --- a/includes/class-displayfeaturedimagegenesis.php +++ b/includes/class-displayfeaturedimagegenesis.php @@ -123,13 +123,20 @@ class Display_Featured_Image_Genesis { ) ); } - //* new setting for titles added in 2.0.0 + // new setting for titles added in 2.0.0 if ( empty( $displaysetting['keep_titles'] ) ) { $this->update_settings( array( 'keep_titles' => 0 ) ); } + // new setting for subsequent pages added in 2.2.0 + if ( empty( $displaysetting['is_paged'] ) ) { + $this->update_settings( array( + 'is_paged' => 0 + ) ); + } + } /** diff --git a/includes/helper-functions.php b/includes/helper-functions.php index ca41245..34b39f7 100644 --- a/includes/helper-functions.php +++ b/includes/helper-functions.php @@ -25,7 +25,10 @@ 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 = Display_Featured_Image_Genesis_Common::get_image_id( $term_meta['term_image'] ); + $image_id = $term_meta['term_image']; + if ( ! is_numeric( $term_meta['term_image'] ) ) { + $image_id = Display_Featured_Image_Genesis_Common::get_image_id( $term_meta['term_image'] ); + } break; } } @@ -107,7 +110,10 @@ function display_featured_image_genesis_get_cpt_image_id() { $post_type = $object->post_type; } if ( ! empty( $displaysetting['post_type'][$post_type] ) ) { - $image_id = Display_Featured_Image_Genesis_Common::get_image_id( $displaysetting['post_type'][$post_type] ); + $image_id = $displaysetting['post_type'][$post_type]; + if ( ! is_numeric( $displaysetting['post_type'][$post_type] ) ) { + $image_id = Display_Featured_Image_Genesis_Common::get_image_id( $displaysetting['post_type'][$post_type] ); + } } return $image_id; diff --git a/includes/js/settings-upload.js b/includes/js/settings-upload.js index ee061a3..84d9896 100644 --- a/includes/js/settings-upload.js +++ b/includes/js/settings-upload.js @@ -2,10 +2,11 @@ jQuery(document).ready(function($){ var custom_uploader; var target_input; + var preview; - $('.upload_default_image').click(function(e) { + $( '.upload_default_image' ).click(function(e) { - target_input = $(this).prev('.upload_image_url'); + target_input = $(this).prev( '.upload_image_id' ); e.preventDefault(); @@ -25,10 +26,16 @@ jQuery(document).ready(function($){ }); //When a file is selected, grab the URL and set it as the text field's value - custom_uploader.on('select', function() { + custom_uploader.on( 'select', function() { - attachment = custom_uploader.state().get('selection').first().toJSON(); - $(target_input).val(attachment.url); + attachment = custom_uploader.state().get( 'selection' ).first().toJSON(); + preview = $( target_input ).prevAll( '#upload_logo_preview' ); + previewImage = $( '

' ); + $( target_input ).val( attachment.id ); + if ( $( preview ).length ) { + $( preview ).remove(); + } + $( target_input ).before( previewImage ); }); //Open the uploader dialog @@ -36,4 +43,16 @@ jQuery(document).ready(function($){ }); + $( '.delete_image' ).click( function(e) { + + target_input = $(this).prevAll( '.upload_image_id' ); + previewView = $(this).prevAll( '#upload_logo_preview' ); + + e.preventDefault(); + + $( target_input ).val( '' ); + $( previewView ).remove(); + + }); + }); diff --git a/includes/widgets/displayfeaturedimagegenesis-cpt-archive-widget.php b/includes/widgets/displayfeaturedimagegenesis-cpt-archive-widget.php index 6348c0d..d50eea2 100644 --- a/includes/widgets/displayfeaturedimagegenesis-cpt-archive-widget.php +++ b/includes/widgets/displayfeaturedimagegenesis-cpt-archive-widget.php @@ -110,7 +110,10 @@ class Display_Featured_Image_Genesis_Widget_CPT extends WP_Widget { $image_id = $postspage_image; } else { - $image_id = Display_Featured_Image_Genesis_Common::get_image_id( $option['post_type'][$post_type->name] ); + $image_id = $option['post_type'][$post_type->name]; + if ( ! is_numeric( $option['post_type'][$post_type->name] ) ) { + $image_id = 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 ) { diff --git a/includes/widgets/displayfeaturedimagegenesis-taxonomy-widget.php b/includes/widgets/displayfeaturedimagegenesis-taxonomy-widget.php index 5857709..1a245c3 100644 --- a/includes/widgets/displayfeaturedimagegenesis-taxonomy-widget.php +++ b/includes/widgets/displayfeaturedimagegenesis-taxonomy-widget.php @@ -97,7 +97,10 @@ class Display_Featured_Image_Genesis_Widget_Taxonomy extends WP_Widget { } if ( $term_meta ) { - $image_id = Display_Featured_Image_Genesis_Common::get_image_id( $term_meta['term_image'] ); + $image_id = $term_meta['term_image']; + if ( ! is_numeric( $term_meta['term_image'] ) ) { + $image_id = 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 = '' . esc_html( $title ) . '';