From 50f278092b0469ce1f88c4a3d0d7c2f833e99d49 Mon Sep 17 00:00:00 2001 From: Robin Cornett Date: Thu, 16 Oct 2014 10:18:38 -0400 Subject: [PATCH 1/4] default to show on cpt archive --- includes/class-displayfeaturedimagegenesis-output.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/includes/class-displayfeaturedimagegenesis-output.php b/includes/class-displayfeaturedimagegenesis-output.php index 1dbecbd..e50f28a 100644 --- a/includes/class-displayfeaturedimagegenesis-output.php +++ b/includes/class-displayfeaturedimagegenesis-output.php @@ -18,7 +18,7 @@ class Display_Featured_Image_Genesis_Output { if ( in_array( get_post_type(), $this->get_skipped_posttypes() ) ) { return; } - elseif ( is_home() || is_singular() ) { + elseif ( is_home() || is_singular() || is_post_type_archive() ) { add_action( 'wp_enqueue_scripts', array( $this, 'load_scripts' ) ); add_filter( 'body_class', array( $this, 'add_body_class' ) ); } @@ -41,7 +41,7 @@ class Display_Featured_Image_Genesis_Output { if ( is_home() && !empty( $postspage_image ) ) { $item->original = wp_get_attachment_image_src( get_post_thumbnail_id( $postspage ), 'original' ); } - elseif ( !empty( $fallback ) && !has_post_thumbnail() ) { + elseif ( !empty( $fallback ) && ( ! has_post_thumbnail() || is_post_type_archive() ) ) { $fallback_id = $this->get_image_id( $fallback ); $item->original = wp_get_attachment_image_src( $fallback_id, 'original' ); } @@ -53,6 +53,9 @@ class Display_Featured_Image_Genesis_Output { if ( is_home() ) { $item->title = get_post( $postspage )->post_title; } + elseif ( is_post_type_archive() ) { + $item->title = ''; + } else { $item->title = get_the_title(); } @@ -140,7 +143,7 @@ class Display_Featured_Image_Genesis_Output { $item = $this->get_image_variables(); - if ( ! is_home() ) { + if ( ! is_home() && ! is_post_type_archive() ) { remove_action( 'genesis_entry_header', 'genesis_do_post_title' ); // HTML5 remove_action( 'genesis_post_title', 'genesis_do_post_title' ); // XHTML } From a0007e1ae66f6e278e6452716704235f802ff366 Mon Sep 17 00:00:00 2001 From: Robin Cornett Date: Thu, 16 Oct 2014 21:23:19 -0400 Subject: [PATCH 2/4] default shows site-wide --- ...displayfeaturedimagegenesis-customizer.php | 2 +- ...ass-displayfeaturedimagegenesis-output.php | 32 +++++++++++-------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/includes/class-displayfeaturedimagegenesis-customizer.php b/includes/class-displayfeaturedimagegenesis-customizer.php index e5f242b..ff4ab2e 100644 --- a/includes/class-displayfeaturedimagegenesis-customizer.php +++ b/includes/class-displayfeaturedimagegenesis-customizer.php @@ -1,7 +1,7 @@ get_skipped_posttypes() ) ) { + $fallback = get_option( 'displayfeaturedimage_default' ); + if ( ( empty( $fallback ) && !is_home() && !is_singular() ) || ( in_array( get_post_type(), $this->get_skipped_posttypes() ) ) ) { return; } - elseif ( is_home() || is_singular() || is_post_type_archive() ) { + else { add_action( 'wp_enqueue_scripts', array( $this, 'load_scripts' ) ); add_filter( 'body_class', array( $this, 'add_body_class' ) ); } @@ -34,14 +35,18 @@ class Display_Featured_Image_Genesis_Output { $item = new stdClass(); global $post; $fallback = get_option( 'displayfeaturedimage_default' ); + $frontpage = get_option( 'show_on_front' ); // either 'posts' or 'page' $postspage = get_option( 'page_for_posts' ); $postspage_image = get_post_thumbnail_id( $postspage ); // Set Featured Image Source - if ( is_home() && !empty( $postspage_image ) ) { - $item->original = wp_get_attachment_image_src( get_post_thumbnail_id( $postspage ), 'original' ); + if ( is_home() && $frontpage === 'page' && !empty( $postspage_image ) ) { + $item->original = wp_get_attachment_image_src( $postspage_image, 'original' ); } - elseif ( !empty( $fallback ) && ( ! has_post_thumbnail() || is_post_type_archive() ) ) { + elseif ( is_singular() && has_post_thumbnail() ) { + $item->original = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'original' ); + } + elseif ( !empty( $fallback ) ) { $fallback_id = $this->get_image_id( $fallback ); $item->original = wp_get_attachment_image_src( $fallback_id, 'original' ); } @@ -50,15 +55,16 @@ class Display_Featured_Image_Genesis_Output { } // Set Post/Page Title - if ( is_home() ) { - $item->title = get_post( $postspage )->post_title; - } - elseif ( is_post_type_archive() ) { - $item->title = ''; - } - else { + if ( is_singular() && ! is_front_page() ) { $item->title = get_the_title(); } + elseif ( is_home() && $frontpage === 'page' ) { + $item->title = get_post( $postspage )->post_title; + } + else { + $item->title = ''; + } + $item->large = get_option( 'large_size_w' ); $item->medium = get_option( 'medium_size_w' ); $item->reduce = get_option( 'displayfeaturedimage_less_header', 0 ); @@ -143,7 +149,7 @@ class Display_Featured_Image_Genesis_Output { $item = $this->get_image_variables(); - if ( ! is_home() && ! is_post_type_archive() ) { + if ( is_singular() || !is_front_page() ) { remove_action( 'genesis_entry_header', 'genesis_do_post_title' ); // HTML5 remove_action( 'genesis_post_title', 'genesis_do_post_title' ); // XHTML } From 096c7a3292e01911308469be35fa6112d4341667 Mon Sep 17 00:00:00 2001 From: Robin Cornett Date: Tue, 21 Oct 2014 18:16:00 -0400 Subject: [PATCH 3/4] default, upload moved to Media --- display-featured-image-genesis.php | 5 +- ...ass-displayfeaturedimagegenesis-common.php | 42 +++++++++ ...displayfeaturedimagegenesis-customizer.php | 57 ------------ ...ass-displayfeaturedimagegenesis-output.php | 89 ++++++++----------- ...s-displayfeaturedimagegenesis-settings.php | 57 +++++++++++- .../class-displayfeaturedimagegenesis.php | 19 ++-- includes/js/settings-upload.js | 35 ++++++++ languages/display-featured-image-genesis.pot | 86 +++++++++--------- 8 files changed, 229 insertions(+), 161 deletions(-) create mode 100644 includes/class-displayfeaturedimagegenesis-common.php delete mode 100644 includes/class-displayfeaturedimagegenesis-customizer.php create mode 100644 includes/js/settings-upload.js diff --git a/display-featured-image-genesis.php b/display-featured-image-genesis.php index 216a1d6..f0eb9b0 100644 --- a/display-featured-image-genesis.php +++ b/display-featured-image-genesis.php @@ -12,7 +12,7 @@ * Plugin Name: Display Featured Image for Genesis * Plugin URI: http://github.com/robincornett/display-featured-image-genesis/ * Description: This plugin requires the Genesis Framework. It varies the display of the post or page featured image, depending on size. - * Version: 1.2.0 + * Version: 1.2.1 * Author: Robin Cornett * Author URI: http://robincornett.com * License: GPL-2.0+ @@ -26,14 +26,17 @@ if ( ! defined( 'WPINC' ) ) { // Include classes require plugin_dir_path( __FILE__ ) . 'includes/class-displayfeaturedimagegenesis.php'; +require plugin_dir_path( __FILE__ ) . 'includes/class-displayfeaturedimagegenesis-common.php'; require plugin_dir_path( __FILE__ ) . 'includes/class-displayfeaturedimagegenesis-output.php'; require plugin_dir_path( __FILE__ ) . 'includes/class-displayfeaturedimagegenesis-settings.php'; // Instantiate dependent classes +$displayfeaturedimagegenesis_common = new Display_Featured_Image_Genesis_Common(); $displayfeaturedimagegenesis_output = new Display_Featured_Image_Genesis_Output(); $displayfeaturedimagegenesis_settings = new Display_Featured_Image_Genesis_Settings(); $displayfeaturedimage = new Display_Featured_Image_Genesis( + $displayfeaturedimagegenesis_common, $displayfeaturedimagegenesis_output, $displayfeaturedimagegenesis_settings ); diff --git a/includes/class-displayfeaturedimagegenesis-common.php b/includes/class-displayfeaturedimagegenesis-common.php new file mode 100644 index 0000000..5ade1d3 --- /dev/null +++ b/includes/class-displayfeaturedimagegenesis-common.php @@ -0,0 +1,42 @@ +get_var( $wpdb->prepare( "SELECT wposts.ID FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta WHERE wposts.ID = wpostmeta.post_id AND wpostmeta.meta_key = '_wp_attached_file' AND wpostmeta.meta_value = '%s' AND wposts.post_type = 'attachment'", $attachment_url ) ); + + } + + return $attachment_id; + } +} diff --git a/includes/class-displayfeaturedimagegenesis-customizer.php b/includes/class-displayfeaturedimagegenesis-customizer.php deleted file mode 100644 index ff4ab2e..0000000 --- a/includes/class-displayfeaturedimagegenesis-customizer.php +++ /dev/null @@ -1,57 +0,0 @@ -statuses = array( '' => __( 'No Image', 'display-featured-image-genesis' ) ); - - parent::__construct( $manager, $id, $args ); - - $this->add_tab( 'upload-new', __( 'Upload New', 'display-featured-image-genesis' ), array( $this, 'tab_upload_new' ) ); - $this->add_tab( 'uploaded', __( 'Uploaded', 'display-featured-image-genesis' ), array( $this, 'tab_uploaded' ) ); - - if ( $this->setting->default ) - $this->add_tab( 'default', __( 'Default', 'display-featured-image-genesis' ), array( $this, 'tab_default_background' ) ); - - // Early priority to occur before $this->manager->prepare_controls(); - add_action( 'customize_controls_init', array( $this, 'prepare_control' ), 5 ); - } - -} - - global $wp_customize; - - $wp_customize->add_section( 'displayfeaturedimage-settings', array( - 'title' => __( 'Default Featured Image', 'display-featured-image-genesis' ), - 'priority' => 105, - ) ); - - $wp_customize->add_setting( 'displayfeaturedimage_default', array( - 'type' => 'option', - ) ); - - $wp_customize->add_control( new Display_Featured_Image_Genesis_Customizer( $wp_customize, 'displayfeaturedimage_default', array( - 'label' => __( 'Display Featured Image for Genesis', 'display-featured-image-genesis' ), - 'description' => __( 'You may set a default image to be used as the backstretch or large featured image if no image is selected for the post/page.', 'display-featured-image-genesis' ), - 'section' => 'displayfeaturedimage-settings', - 'settings' => 'displayfeaturedimage_default', - ) ) ); diff --git a/includes/class-displayfeaturedimagegenesis-output.php b/includes/class-displayfeaturedimagegenesis-output.php index 94bccf6..143b741 100644 --- a/includes/class-displayfeaturedimagegenesis-output.php +++ b/includes/class-displayfeaturedimagegenesis-output.php @@ -35,23 +35,29 @@ class Display_Featured_Image_Genesis_Output { $item = new stdClass(); global $post; $fallback = get_option( 'displayfeaturedimage_default' ); + $fallback_id = Display_Featured_Image_Genesis_Common::get_image_id( $fallback ); $frontpage = get_option( 'show_on_front' ); // either 'posts' or 'page' $postspage = get_option( 'page_for_posts' ); $postspage_image = get_post_thumbnail_id( $postspage ); + if ( is_singular() ) { + $originalthumb = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'displayfeaturedimage_backstretch' ); + } + + $item->large = get_option( 'large_size_w' ); + $item->medium = get_option( 'medium_size_w' ); + $item->reduce = get_option( 'displayfeaturedimage_less_header', 0 ); // Set Featured Image Source - if ( is_home() && $frontpage === 'page' && !empty( $postspage_image ) ) { - $item->original = wp_get_attachment_image_src( $postspage_image, 'original' ); + if ( is_home() && $frontpage === 'page' && !empty( $postspage_image ) ) { // if on the blog page and it has a post_thumbnail + $item->original = wp_get_attachment_image_src( $postspage_image, 'displayfeaturedimage_backstretch' ); } - elseif ( is_singular() && has_post_thumbnail() ) { - $item->original = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'original' ); - } - elseif ( !empty( $fallback ) ) { - $fallback_id = $this->get_image_id( $fallback ); - $item->original = wp_get_attachment_image_src( $fallback_id, 'original' ); + // any singular post/page/CPT with either a post_thumbnail larger than medium size OR there is no $fallback + elseif ( is_singular() && ( $originalthumb[1] > $item->medium || empty( $fallback ) ) && !in_array( get_post_type(), $this->use_fallback_image() ) ) { + $item->original = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'displayfeaturedimage_backstretch' ); } + // otherwise use $fallback. should include !is_singular AND $fallback, and is_singular with either a small image or no post_thumbnail else { - $item->original = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'original' ); + $item->original = wp_get_attachment_image_src( $fallback_id, 'displayfeaturedimage_backstretch' ); } // Set Post/Page Title @@ -65,10 +71,13 @@ class Display_Featured_Image_Genesis_Output { $item->title = ''; } - $item->large = get_option( 'large_size_w' ); - $item->medium = get_option( 'medium_size_w' ); - $item->reduce = get_option( 'displayfeaturedimage_less_header', 0 ); - $item->content = strpos( $post->post_content, $item->original[0] ); + // declare this last so that $item->original is set. + if ( !empty( $post->post_content ) ) { + $item->content = strpos( $post->post_content, $item->original[0] ); + } + else { + $item->content = ''; + } return $item; @@ -84,6 +93,16 @@ class Display_Featured_Image_Genesis_Output { return apply_filters( 'display_featured_image_genesis_skipped_posttypes', array( 'attachment', 'revision', 'nav_menu_item' ) ); } + /** + * use fallback image as backstretch + * @return filter creates a new filter for themes/plugins to use to use the fallback image even if a large featured image is in place + * + * @since 1.2.1 + */ + public function use_fallback_image() { + return apply_filters( 'display_featured_image_genesis_use_default', array( 'attachment', 'revision', 'nav_menu_item' ) ); + } + /** * enqueue plugin styles and scripts. * @return enqueue @@ -93,18 +112,18 @@ class Display_Featured_Image_Genesis_Output { public function load_scripts() { $item = $this->get_image_variables(); - if ( ( !empty( $item->original ) && $item->content === false ) || is_home() ) { + if ( ( !empty( $item->original ) && $item->content === false ) || ( !is_singular() && !empty( $item->original ) ) ) { wp_enqueue_style( 'displayfeaturedimage-style', plugins_url( 'includes/css/display-featured-image-genesis.css', dirname( __FILE__ ) ), array(), 1.0 ); - if ( ( ( $item->original[1] ) > $item->large ) ) { + if ( $item->original[1] > $item->large ) { wp_enqueue_script( 'displayfeaturedimage-backstretch', plugins_url( '/includes/js/backstretch.js', dirname( __FILE__ ) ), array( 'jquery' ), '1.0.0' ); wp_enqueue_script( 'displayfeaturedimage-backstretch-set', plugins_url( '/includes/js/backstretch-set.js', dirname( __FILE__ ) ), array( 'jquery', 'displayfeaturedimage-backstretch' ), '1.0.0' ); wp_localize_script( 'displayfeaturedimage-backstretch-set', 'BackStretchVars', array( - 'src' => $item->original[0], + 'src' => esc_url( $item->original[0] ), 'height' => esc_attr( $item->reduce ) - )); + ) ); add_action( 'genesis_after_header', array( $this, 'do_backstretch_image_title' ) ); @@ -128,7 +147,7 @@ class Display_Featured_Image_Genesis_Output { $item = $this->get_image_variables(); - if ( !empty( $item->original ) && $item->content === false ) { + if ( ( !empty( $item->original ) && $item->content === false ) || ( !is_singular() && !empty( $item->original ) ) ) { if ( $item->original[1] > $item->large ) { $classes[] = 'has-leader'; } @@ -149,7 +168,7 @@ class Display_Featured_Image_Genesis_Output { $item = $this->get_image_variables(); - if ( is_singular() || !is_front_page() ) { + if ( is_singular() && !is_front_page() ) { remove_action( 'genesis_entry_header', 'genesis_do_post_title' ); // HTML5 remove_action( 'genesis_post_title', 'genesis_do_post_title' ); // XHTML } @@ -170,36 +189,4 @@ class Display_Featured_Image_Genesis_Output { echo get_the_post_thumbnail( $post->ID, 'large', array( 'class' => 'aligncenter featured', 'alt' => the_title_attribute( 'echo=0' ) ) ); } - /** - * Get the ID of each image dynamically. - * - * @since 1.2.0 - * - * @author Philip Newcomer - * @link http://philipnewcomer.net/2012/11/get-the-attachment-id-from-an-image-url-in-wordpress/ - */ - protected function get_image_id( $attachment_url ) { - global $wpdb; - $attachment_id = false; - - // Get the upload directory paths - $upload_dir_paths = wp_upload_dir(); - - // Make sure the upload path base directory exists in the attachment URL, to verify that we're working with a media library image - if ( false !== strpos( $attachment_url, $upload_dir_paths['baseurl'] ) ) { - - // If this is the URL of an auto-generated thumbnail, get the URL of the original image - $attachment_url = preg_replace( '(-\d{3,4}x\d{3,4}.)', '.', $attachment_url ); - - // Remove the upload path base directory from the attachment URL - $attachment_url = str_replace( $upload_dir_paths['baseurl'] . '/', '', $attachment_url ); - - // Finally, run a custom database query to get the attachment ID from the modified attachment URL - $attachment_id = $wpdb->get_var( $wpdb->prepare( "SELECT wposts.ID FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta WHERE wposts.ID = wpostmeta.post_id AND wpostmeta.meta_key = '_wp_attached_file' AND wpostmeta.meta_value = '%s' AND wposts.post_type = 'attachment'", $attachment_url ) ); - - } - - return $attachment_id; - } - } diff --git a/includes/class-displayfeaturedimagegenesis-settings.php b/includes/class-displayfeaturedimagegenesis-settings.php index 4d589a4..77c339a 100644 --- a/includes/class-displayfeaturedimagegenesis-settings.php +++ b/includes/class-displayfeaturedimagegenesis-settings.php @@ -17,6 +17,8 @@ class Display_Featured_Image_Genesis_Settings { */ public function register_settings() { register_setting( 'media', 'displayfeaturedimage_less_header', 'absint' ); + register_setting( 'media', 'displayfeaturedimage_default' ); + add_settings_section( 'display_featured_image_section', @@ -33,6 +35,16 @@ class Display_Featured_Image_Genesis_Settings { 'display_featured_image_section' ); + add_settings_field( + 'displayfeaturedimage_default', + '', + array( $this, 'set_default_image' ), + 'media', + 'display_featured_image_section' + ); + + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); + } /** @@ -42,7 +54,7 @@ class Display_Featured_Image_Genesis_Settings { * @since 1.1.0 */ public function section_description() { - echo '

' . __( 'Change this setting to reduce the maximum height of the backstretch image.', 'display-featured-image-genesis' ) . '

'; + echo '

' . __( 'The Display Featured Image for Genesis plugin has two optional settings: 1) change the height of the backstretch effect, and 2) set a default backstretch image to use if no featured image is set.', 'display-featured-image-genesis' ) . '

'; } /** @@ -60,6 +72,33 @@ class Display_Featured_Image_Genesis_Settings { } + /** + * Default image uploader + * + * @return image + * + * @since 1.2.1 + */ + public function set_default_image() { + $value = get_option( 'displayfeaturedimage_default' ); + $id = Display_Featured_Image_Genesis_Common::get_image_id( $value ); + $url = wp_get_attachment_image_src( $id, 'medium' ); + $original = wp_get_attachment_image_src( $id, 'original' ); + $large = get_option( 'large_size_w' ); + + if ( $value && $original[1] >= $large ) { + echo '
'; + echo ''; + echo '
'; + } + elseif ( $value && $original[1] <= $large ) { + echo '

' . __( 'Sorry, your image is too small to serve as the default featured image.', 'display-featured-image-genesis' ) . '

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

' . __( 'If you would like to use a default image for the featured image, upload it here. Must be a backstretch sized image.', 'display-featured-image-genesis' ) . '

'; + } + /** * Help tab for media screen * @return help tab with verbose information for plugin @@ -81,4 +120,20 @@ class Display_Featured_Image_Genesis_Settings { } + /** + * enqueue admin scripts + * @return scripts to use image uploader + * + * @since 1.2.1 + */ + public function enqueue_scripts() { + wp_register_script( 'displayfeaturedimage-upload', plugins_url( '/includes/js/settings-upload.js', dirname( __FILE__ ) ), array( 'jquery', 'media-upload', 'thickbox' ), '1.0.0' ); + + if ( 'options-media' == get_current_screen()->id ) { + wp_enqueue_media(); + wp_enqueue_script( 'displayfeaturedimage-upload' ); + } + + } + } diff --git a/includes/class-displayfeaturedimagegenesis.php b/includes/class-displayfeaturedimagegenesis.php index e4729bc..5923642 100644 --- a/includes/class-displayfeaturedimagegenesis.php +++ b/includes/class-displayfeaturedimagegenesis.php @@ -15,7 +15,11 @@ * @package DisplayFeaturedImageGenesis */ class Display_Featured_Image_Genesis { - function __construct( $output, $settings ) { + + public static $instance; + + function __construct( $common, $output, $settings ) { + $this->common = $common; $this->output = $output; $this->settings = $settings; } @@ -26,9 +30,11 @@ class Display_Featured_Image_Genesis { add_action( 'admin_notices', array( $this, 'error_message' ) ); return; } + + add_image_size( 'displayfeaturedimage_backstretch', 2000 ); + add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) ); add_action( 'admin_init', array( $this->settings, 'register_settings' ) ); - add_action( 'customize_register', array( $this, 'load_customizer' ) ); add_action( 'load-options-media.php', array( $this->settings, 'help' ) ); add_action( 'get_header', array( $this->output, 'manage_output' ) ); } @@ -79,13 +85,4 @@ class Display_Featured_Image_Genesis { load_plugin_textdomain( 'display-featured-image-genesis', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); } - /** - * Set up Customizer options for default featured image - * - * @since 1.2.0 - */ - function load_customizer() { - require plugin_dir_path( __FILE__ ) . 'class-displayfeaturedimagegenesis-customizer.php'; - } - } diff --git a/includes/js/settings-upload.js b/includes/js/settings-upload.js new file mode 100644 index 0000000..063aca1 --- /dev/null +++ b/includes/js/settings-upload.js @@ -0,0 +1,35 @@ +jQuery(document).ready(function($){ + + var custom_uploader; + + $('#upload_default_image').click(function(e) { + + e.preventDefault(); + + //If the uploader object has already been created, reopen the dialog + if (custom_uploader) { + custom_uploader.open(); + return; + } + + //Extend the wp.media object + custom_uploader = wp.media.frames.file_frame = wp.media({ + title: 'Choose Image', + button: { + text: 'Choose Image' + }, + multiple: false + }); + + //When a file is selected, grab the URL and set it as the text field's value + custom_uploader.on('select', function() { + attachment = custom_uploader.state().get('selection').first().toJSON(); + $('#default_image_url').val(attachment.url); + }); + + //Open the uploader dialog + custom_uploader.open(); + + }); + +}); \ No newline at end of file diff --git a/languages/display-featured-image-genesis.pot b/languages/display-featured-image-genesis.pot index 1afd657..f45d5ac 100644 --- a/languages/display-featured-image-genesis.pot +++ b/languages/display-featured-image-genesis.pot @@ -4,9 +4,10 @@ # msgid "" msgstr "" -"Project-Id-Version: Display Featured Image for Genesis 1.2.0\n" +"Project-Id-Version: Display Featured Image for Genesis 1.2.1\n" "POT-Creation-Date: 2014-09-17 21:11-0500\n" -"PO-Revision-Date: 2014-10-15 15:45-0500\n""Last-Translator: Robin Cornett \n" +"PO-Revision-Date: 2014-10-21 18:03-0500\n" +"Last-Translator: Robin Cornett \n" "Language-Team: Robin Cornett \n" "Language: en_US\n" "MIME-Version: 1.0\n" @@ -24,62 +25,55 @@ msgstr "" "X-Poedit-SearchPath-0: .\n" "X-Textdomain-Support: yes\n" -#: ../includes/class-displayfeaturedimagegenesis-customizer.php:25 -msgid "No Image" -msgstr "" - -#: ../includes/class-displayfeaturedimagegenesis-customizer.php:29 -msgid "Upload New" -msgstr "" - -#: ../includes/class-displayfeaturedimagegenesis-customizer.php:30 -msgid "Uploaded" -msgstr "" - -#: ../includes/class-displayfeaturedimagegenesis-customizer.php:33 -msgid "Default" -msgstr "" - -#: ../includes/class-displayfeaturedimagegenesis-customizer.php:52 -msgid "Default Featured Image" -msgstr "" - -#: ../includes/class-displayfeaturedimagegenesis-customizer.php:62 -#: ../includes/class-displayfeaturedimagegenesis-settings.php:23 -#: ../includes/class-displayfeaturedimagegenesis-settings.php:78 +#: ../includes/class-displayfeaturedimagegenesis-settings.php:25 +#: ../includes/class-displayfeaturedimagegenesis-settings.php:120 msgid "Display Featured Image for Genesis" msgstr "" -#: ../includes/class-displayfeaturedimagegenesis-customizer.php:63 -msgid "" -"You may set a default image to be used as the backstretch or large featured " -"image if no image is selected for the post/page." -msgstr "" - -#: ../includes/class-displayfeaturedimagegenesis-settings.php:30 +#: ../includes/class-displayfeaturedimagegenesis-settings.php:32 msgid "Height" msgstr "" -#: ../includes/class-displayfeaturedimagegenesis-settings.php:45 -msgid "" -"Change this setting to reduce the maximum height of the backstretch image." +#: ../includes/class-displayfeaturedimagegenesis-settings.php:40 +msgid "Default Featured Image" msgstr "" #: ../includes/class-displayfeaturedimagegenesis-settings.php:57 +msgid "" +"The Display Featured Image for Genesis plugin has two optional settings: 1) " +"change the height of the backstretch effect, and 2) set a default " +"backstretch image to use if no featured image is set." +msgstr "" + +#: ../includes/class-displayfeaturedimagegenesis-settings.php:69 msgid "Pixels to remove " msgstr "" -#: ../includes/class-displayfeaturedimagegenesis-settings.php:59 +#: ../includes/class-displayfeaturedimagegenesis-settings.php:71 msgid "" "Changing this number will reduce the backstretch image height by this number " "of pixels. Default is zero." msgstr "" -#: ../includes/class-displayfeaturedimagegenesis-settings.php:73 +#: ../includes/class-displayfeaturedimagegenesis-settings.php:95 +msgid "Sorry, your image is too small to serve as the default featured image." +msgstr "" + +#: ../includes/class-displayfeaturedimagegenesis-settings.php:98 +msgid "Select Default Image" +msgstr "" + +#: ../includes/class-displayfeaturedimagegenesis-settings.php:99 +msgid "" +"If you would like to use a default image for the featured image, upload it " +"here. Must be a backstretch sized image." +msgstr "" + +#: ../includes/class-displayfeaturedimagegenesis-settings.php:112 msgid "Reducto!" msgstr "" -#: ../includes/class-displayfeaturedimagegenesis-settings.php:74 +#: ../includes/class-displayfeaturedimagegenesis-settings.php:113 msgid "" "Depending on how your header/nav are set up, or if you just do not want your " "backstretch image to extend to the bottom of the user screen, you may want " @@ -87,13 +81,25 @@ msgid "" "image, making it shorter." msgstr "" -#: ../includes/class-displayfeaturedimagegenesis.php:63 +#: ../includes/class-displayfeaturedimagegenesis-settings.php:115 +msgid "Set a Default Featured Image" +msgstr "" + +#: ../includes/class-displayfeaturedimagegenesis-settings.php:116 +msgid "" +"You may set a large image to be used sitewide if a featured image is not " +"available. This image will show on posts, pages, and archives. It must be " +"larger than your site's Large Image setting, or else it will not " +"display. This is for a backstretch image only." +msgstr "" + +#: ../includes/class-displayfeaturedimagegenesis.php:65 msgid "" "Sorry, Display Featured Image for Genesis works only with the Genesis " "Framework. It has been deactivated." msgstr "" -#: ../includes/class-displayfeaturedimagegenesis.php:67 +#: ../includes/class-displayfeaturedimagegenesis.php:69 #, php-format msgid "" "Sorry, Display Featured Image for Genesis works only with the Genesis " From 8662a766217a49086895ce1afcf52f67a07caa89 Mon Sep 17 00:00:00 2001 From: Robin Cornett Date: Tue, 21 Oct 2014 19:22:38 -0400 Subject: [PATCH 4/4] updated readme --- README.md | 21 ++++++++++++++++++++- readme.txt | 24 +++++++++++++++++++++--- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 521c510..a54ea6a 100644 --- a/README.md +++ b/README.md @@ -10,8 +10,9 @@ This plugin takes a different approach to how we use and display featured images * display the image above your post/page content, centered and up to the width of the content, if your image is larger than your Medium Media Setting, and less than or equal to your Large Media Setting. * display _nothing_ if your featured image width is less than or equal to your Medium Media Setting. * display _nothing_ if your featured image is already displayed in your content (the original image, not a resized version). +* display a _default featured image_ as a backstretch image if one is uploaded. -__New in 1.2.0:__ you can now use the WordPress Customizer to set a _Default Featured Image_ to be used site-wide. This image will be used on any post/page/custom post type which does not have a featured image set. +__New in 1.2.0:__ on the Media Settings page, you can now upload a _Default Featured Image_ to be used site-wide. This image will be used on any post/page/custom post type which does not have a featured image set, plus archive and taxonomy pages. _Note: This plugin works with the Genesis Framework and child themes only._ @@ -70,6 +71,19 @@ function rgc_skip_post_types( $post_types ) { It seems that you can also include [conditional tags](http://codex.wordpress.org/Conditional_Tags) in the above, eg `$post_types[] = is_front_page();` to stop the featured image from displaying. This is most helpful if you have set a default featured image in the Customizer. +### Can I force my site to use the default image on a post type even if it has its own Featured Image? + +Yes! You'll want to add a filter to your theme (functions.php file). Here's an example: + +```php +add_filter( 'display_featured_image_genesis_use_default', 'rgc_force_default_image' ); +function rgc_force_default_image( $post_types ) { + $post_types[] = 'attorney'; + + return $post_types; +} +``` + ### The backstretch image is a little too tall. If you do not want the height of the backstretch image to be quite the height of the user's window, you can reduce it by just a hair. Go to Settings > Media and change the 'Height' number from the default of 0. The higher this number is, the shorter your image will be. Feel free to experiment, as no images are harmed by changing this number. @@ -87,6 +101,11 @@ Additionally/alternatively, you could set a max-height for the backstretch image ## Changelog +###1.2.1 +* moved default image from Customizer to Media Settings page +* new filter for forcing default image for any post type +* common class + ###1.2.0 * new feature: default featured image to display if no image is set * better method naming/organization diff --git a/readme.txt b/readme.txt index 072bc79..a3527ae 100644 --- a/readme.txt +++ b/readme.txt @@ -18,9 +18,9 @@ This plugin takes a different approach to how we use and display featured images * display the image as a _backstretch_ (screen width) image if the image is wider than your site's Large Media Setting. * display the image above your post/page content, centered and up to the width of the content, if your image is larger than your Medium Media Setting, and less than or equal to your Large Media Setting. * display _nothing_ if your featured image width is less than or equal to your Medium Media Setting. -* display _nothing_ if your featured image is already displayed in your content (the original image, not a resized version). +* display a _default featured image_ as a backstretch image if one is uploaded. -__New in 1.2.0:__ you can now use the WordPress Customizer to set a _Default Featured Image_ to be used site-wide. This image will be used on any post/page/custom post type which does not have a featured image set. +__New in 1.2.0:__ on the Media Settings page, you can now upload a _Default Featured Image_ to be used site-wide. This image will be used on any post/page/custom post type which does not have a featured image set, plus archive and taxonomy pages. _Note: This plugin works with the Genesis Framework and child themes only._ @@ -46,6 +46,19 @@ You'll want to add a filter to your theme (functions.php file). Here's an exampl It seems that you can also include [conditional tags](http://codex.wordpress.org/Conditional_Tags) in the above, eg `$post_types[] = is_front_page();` to stop the featured image from displaying. This is most helpful if you have set a default featured image in the Customizer. += Can I force my site to use the default image on a post type even if it has its own Featured Image? = + +Yes! You'll want to add a filter to your theme (functions.php file). Here's an example: + +```php +add_filter( 'display_featured_image_genesis_use_default', 'rgc_force_default_image' ); +function rgc_force_default_image( $post_types ) { + $post_types[] = 'attorney'; + + return $post_types; +} +``` + = The backstretch image is a little too tall. = If you do not want the height of the backstretch image to be quite the height of the user's window, you can reduce it by just a hair. Go to Settings > Media and change the 'Height' number from the default of 0. The higher this number is, the shorter your image will be. Feel free to experiment, as no images are harmed by changing this number. @@ -63,11 +76,16 @@ Additionally/alternatively, you could set a max-height for the backstretch image 2. Use the WordPress Customizer to set a Default Featured Image. == Upgrade Notice == -= 1.2.0 = += 1.2.1 = New feature: Set a Default Featured Image == Changelog == += 1.2.1 = +* moved default image from Customizer to Media Settings page +* new filter for forcing default image for any post type +* common class + = 1.2.0 = * new feature: default featured image to display if no image is set * better method naming/organization