From 212960eb199258005aac786bd4dfee6042ea3b97 Mon Sep 17 00:00:00 2001 From: Robin Cornett Date: Tue, 23 Sep 2014 14:17:24 -0400 Subject: [PATCH 1/4] XHTML hook, wp.org readme --- ...ass-displayfeaturedimagegenesis-output.php | 5 +- includes/js/backstretch-set.js | 2 +- readme.txt | 74 +++++++++++++++++++ 3 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 readme.txt diff --git a/includes/class-displayfeaturedimagegenesis-output.php b/includes/class-displayfeaturedimagegenesis-output.php index dc5afd6..03f435c 100644 --- a/includes/class-displayfeaturedimagegenesis-output.php +++ b/includes/class-displayfeaturedimagegenesis-output.php @@ -18,7 +18,7 @@ class Display_Featured_Image_Genesis_Output { $item = new stdClass(); global $post; if ( is_home() ) { - $postspage = get_option( 'page_for_posts' ); + $postspage = get_option( 'page_for_posts' ); $item->original = wp_get_attachment_image_src( get_post_thumbnail_id( $postspage ), 'original' ); } else { @@ -113,7 +113,8 @@ class Display_Featured_Image_Genesis_Output { add_action( 'genesis_after_header', array( $this, 'do_backstretch_image' ) ); } elseif ( ( $item->original[1] <= $item->large ) && ( $item->original[1] > $item->medium ) ) { - add_action( 'genesis_before_entry', array( $this, 'do_large_image' ) ); + add_action( 'genesis_before_entry', array( $this, 'do_large_image' ) ); // HTML5 + add_action( 'genesis_before_post_content', array( $this, 'do_large_image' ) ); // XHTML } } diff --git a/includes/js/backstretch-set.js b/includes/js/backstretch-set.js index ea59e9c..ed5eb4f 100644 --- a/includes/js/backstretch-set.js +++ b/includes/js/backstretch-set.js @@ -1,5 +1,5 @@ jQuery(document).ready(function($) { $(".big-leader").css({'height':($(window).height())-([BackStretchVars.height])+'px'}); - $(".big-leader").backstretch([BackStretchVars.src],{'fade':750,'centeredY':false}); + $(".big-leader").backstretch([BackStretchVars.src],{'fade':750}); }); \ No newline at end of file diff --git a/readme.txt b/readme.txt new file mode 100644 index 0000000..9419d29 --- /dev/null +++ b/readme.txt @@ -0,0 +1,74 @@ +=== Display Featured Image for Genesis === + +Contributors: littler.chicken +Donate link: https://robincornett.com/donate/ +Tags: backstretch, featured image, genesis, studiopress +Requires at least: 3.8 +Tested up to: 4.0 +Stable tag: 1.1.0 +License: GPL-2.0+ +License URI: http://www.gnu.org/licenses/gpl-2.0.txt + +This plugin works within the Genesis Framework, to display your featured images in beautiful and dynamic ways. + +== Description == + +This plugin takes a different approach to how we use and display featured images for posts and pages. Instead of simply reusing an image which already exists in the post/page content, the plugin anticipates that you will want to use lovely large images for your featured images, but to do so intelligently. Depending on what you upload, the plugin will: + +* 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). + +_Note: This plugin works with the Genesis Framework and child themes only._ + +== Installation == + +1. Upload the entire `display-featured-image-genesis` folder to your `/wp-content/plugins` directory. +1. Activate the plugin through the 'Plugins' menu in WordPress. +1. Optionally, visit the Settings > Media page to change the default behavior of the plugin. + +== Frequently Asked Questions == + += How do I stop the featured image action from showing on my custom post types? = + +You'll want to add a filter to your theme (functions.php file). Here's an example: + + add_filter( 'display_featured_image_genesis_skipped_posttypes', 'rgc_skip_post_types' ); + function rgc_skip_post_types( $post_types ) { + $post_types[] = 'listing'; + $post_types[] = 'staff'; + + 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 'Reduction amount' 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. + +Additionally/alternatively, you could set a max-height for the backstretch image via css: + + + .backstretch { + max-height: 700px; + } + + +== Screenshots == +1. Screenshot of a page using the Backstretch Featured Image + +== Upgrade Notice == += 1.1.1 = +New setting to optionally reduce backstretch image height +== Changelog == + += 1.1.1 = +* added a setting in the admin to optionally reduce the height of the backstretch image (eg. due to header height issues) +* refactoring +* wp.org release + += 1.0.1 = +* added the filter for certain post types, and optional filter for other custom post types + += 1.0.0 = +* Initial release on Github \ No newline at end of file From 78483cf230646ba2bf55504838b6546b8c5b1c7f Mon Sep 17 00:00:00 2001 From: Robin Cornett Date: Tue, 23 Sep 2014 14:27:49 -0400 Subject: [PATCH 2/4] index --- index.php | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 index.php diff --git a/index.php b/index.php new file mode 100644 index 0000000..3191038 --- /dev/null +++ b/index.php @@ -0,0 +1,3 @@ + Date: Tue, 23 Sep 2014 15:43:24 -0400 Subject: [PATCH 3/4] corrected XHTML hooks, CSS. --- README.md | 3 +++ display-featured-image-genesis.php | 2 +- includes/class-displayfeaturedimagegenesis-output.php | 7 ++++--- includes/css/display-featured-image-genesis.css | 4 ++++ readme.txt | 7 +++++-- 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 135fce2..b9b4a1b 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,9 @@ Additionally/alternatively, you could set a max-height for the backstretch image ## Changelog ###1.1.1 +* corrected XHTML hooks + +###1.1.0 * added a setting in the admin to optionally reduce the height of the backstretch image * refactoring diff --git a/display-featured-image-genesis.php b/display-featured-image-genesis.php index aea101d..adbfe2e 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.1.0 + * Version: 1.1.1 * Author: Robin Cornett * Author URI: http://robincornett.com * License: GPL-2.0+ diff --git a/includes/class-displayfeaturedimagegenesis-output.php b/includes/class-displayfeaturedimagegenesis-output.php index 03f435c..f86612c 100644 --- a/includes/class-displayfeaturedimagegenesis-output.php +++ b/includes/class-displayfeaturedimagegenesis-output.php @@ -114,7 +114,7 @@ class Display_Featured_Image_Genesis_Output { } elseif ( ( $item->original[1] <= $item->large ) && ( $item->original[1] > $item->medium ) ) { add_action( 'genesis_before_entry', array( $this, 'do_large_image' ) ); // HTML5 - add_action( 'genesis_before_post_content', array( $this, 'do_large_image' ) ); // XHTML + add_action( 'genesis_before_post', array( $this, 'do_large_image' ) ); // XHTML } } @@ -131,7 +131,8 @@ class Display_Featured_Image_Genesis_Output { $item = $this->get_image_variables(); if ( ! is_home() ) { - remove_action( 'genesis_entry_header', 'genesis_do_post_title' ); + remove_action( 'genesis_entry_header', 'genesis_do_post_title' ); // HTML5 + remove_action( 'genesis_post_title', 'genesis_do_post_title' ); // XHTML } echo '
'; @@ -154,7 +155,7 @@ class Display_Featured_Image_Genesis_Output { */ public function do_large_image() { global $post; - echo get_the_post_thumbnail( $post->ID, 'large', array( 'class' => 'aligncenter', 'alt' => the_title_attribute( 'echo=0' ) ) ); + echo get_the_post_thumbnail( $post->ID, 'large', array( 'class' => 'aligncenter featured', 'alt' => the_title_attribute( 'echo=0' ) ) ); } } diff --git a/includes/css/display-featured-image-genesis.css b/includes/css/display-featured-image-genesis.css index 7c25fc7..3c8881c 100644 --- a/includes/css/display-featured-image-genesis.css +++ b/includes/css/display-featured-image-genesis.css @@ -15,3 +15,7 @@ left: 0; text-align: center; } + +img.featured { + max-width: 100%; +} diff --git a/readme.txt b/readme.txt index 9419d29..e67c2ab 100644 --- a/readme.txt +++ b/readme.txt @@ -5,7 +5,7 @@ Donate link: https://robincornett.com/donate/ Tags: backstretch, featured image, genesis, studiopress Requires at least: 3.8 Tested up to: 4.0 -Stable tag: 1.1.0 +Stable tag: 1.1.1 License: GPL-2.0+ License URI: http://www.gnu.org/licenses/gpl-2.0.txt @@ -59,10 +59,13 @@ Additionally/alternatively, you could set a max-height for the backstretch image == Upgrade Notice == = 1.1.1 = -New setting to optionally reduce backstretch image height +corrected XHTML hooks == Changelog == = 1.1.1 = +* corrected XHTML hooks + += 1.1.0 = * added a setting in the admin to optionally reduce the height of the backstretch image (eg. due to header height issues) * refactoring * wp.org release From d1f34866265154b65a959f373dee3e7824d55595 Mon Sep 17 00:00:00 2001 From: Robin Cornett Date: Fri, 26 Sep 2014 15:43:53 -0400 Subject: [PATCH 4/4] plugin properly deactivates --- README.md | 3 ++ display-featured-image-genesis.php | 2 +- .../class-displayfeaturedimagegenesis.php | 35 ++++++++++++++++--- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index b9b4a1b..92a282f 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,9 @@ Additionally/alternatively, you could set a max-height for the backstretch image ## Changelog +###1.1.2 +* plugin properly deactivates if Genesis isn't running + ###1.1.1 * corrected XHTML hooks diff --git a/display-featured-image-genesis.php b/display-featured-image-genesis.php index adbfe2e..feee32a 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.1.1 + * Version: 1.1.2 * Author: Robin Cornett * Author URI: http://robincornett.com * License: GPL-2.0+ diff --git a/includes/class-displayfeaturedimagegenesis.php b/includes/class-displayfeaturedimagegenesis.php index 5f550ff..d391d4f 100644 --- a/includes/class-displayfeaturedimagegenesis.php +++ b/includes/class-displayfeaturedimagegenesis.php @@ -22,6 +22,7 @@ class Display_Featured_Image_Genesis { public function run() { if ( basename( get_template_directory() ) !== 'genesis' ) { + add_action( 'admin_init', array( $this, 'deactivate' ) ); add_action( 'admin_notices', array( $this, 'error_message' ) ); return; } @@ -32,17 +33,41 @@ class Display_Featured_Image_Genesis { add_filter( 'body_class', array( $this->output, 'add_body_class' ) ); } + /** + * deactivates the plugin if Genesis isn't running + * + * @since 1.1.2 + * + */ + public function deactivate() { + if ( version_compare( PHP_VERSION, '5.3', '>=' ) ) { + deactivate_plugins( plugin_basename( dirname( __DIR__ ) ) . '/display-featured-image-genesis.php' ); // __DIR__ is a magic constant introduced in PHP 5.3 + } + else { + deactivate_plugins( plugin_basename( dirname( dirname( __FILE__ ) ) ) . '/display-featured-image-genesis.php' ); + } + } + /** * Error message if we're not using the Genesis Framework. * * @since 1.1.0 */ public function error_message() { - echo '

' . sprintf( - __( 'Sorry, Display Featured Image for Genesis works only with the Genesis Framework. You can deactivate the plugin, since it is not working anyway, or you can activate a Genesis child theme.', 'display-featured-image-genesis' ), - esc_url( admin_url( 'plugins.php' ) ), - esc_url( admin_url( 'themes.php' ) ) - ) . '

'; + if ( version_compare( PHP_VERSION, '5.3', '>=' ) ) { + echo '

' . sprintf( + __( 'Sorry, Display Featured Image for Genesis works only with the Genesis Framework. It has been deactivated.', 'display-featured-image-genesis' ) ) . '

'; + } + else { + echo '

' . sprintf( + __( 'Sorry, Display Featured Image for Genesis works only with the Genesis Framework. It has been deactivated. But since we're talking anyway, did you know that your server is running PHP version %1$s, which is outdated? You should ask your host to update that for you.', 'display-featured-image-genesis' ), + PHP_VERSION + ) . '

'; + } + + if ( isset( $_GET['activate'] ) ) { + unset( $_GET['activate'] ); + } } /**