diff --git a/README.md b/README.md index e42724c..661821f 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,10 @@ _Set a Default Featured Image on the Appearance > Display Featured Image for Gen Display Featured Image for Genesis has its own settings page, under the main Appearance menu. +### Does this work with any Genesis child theme? + +Yes and no. Technically, it does, even older (XHTML) themes. However, depending on other factors such as the individual theme's styling and layout. Not recommended for themes such as Sixteen Nine Pro, or The 411 Pro due to layout, and not for Ambiance Pro or Minimum Pro without changing some theme functionality. + ### 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: diff --git a/includes/class-displayfeaturedimagegenesis-common.php b/includes/class-displayfeaturedimagegenesis-common.php index 0824eb6..050a801 100644 --- a/includes/class-displayfeaturedimagegenesis-common.php +++ b/includes/class-displayfeaturedimagegenesis-common.php @@ -21,18 +21,19 @@ class Display_Featured_Image_Genesis_Common { // variables internal to this function $frontpage = get_option( 'show_on_front' ); // either 'posts' or 'page' $postspage = get_option( 'page_for_posts' ); - $move_excerpts = get_option( 'displayfeaturedimage_excerpts' ); + $displaysetting = get_option( 'displayfeaturedimagegenesis' ); + $move_excerpts = $displaysetting['move_excerpts']; $postspage_image = get_post_thumbnail_id( $postspage ); if ( is_singular() ) { $post_thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'displayfeaturedimage_backstretch' ); } // variables used outside this function - $item->fallback = esc_attr( get_option( 'displayfeaturedimage_default' ) ); + $item->fallback = esc_attr( $displaysetting['default'] ); $item->fallback_id = self::get_image_id( $item->fallback ); $item->large = absint( get_option( 'large_size_w' ) ); $item->medium = absint( get_option( 'medium_size_w' ) ); - $item->reduce = absint( get_option( 'displayfeaturedimage_less_header', 0 ) ); + $item->reduce = absint( $displaysetting['less_header'] ); // Set Featured Image Source $item->original = wp_get_attachment_image_src( $item->fallback_id, 'displayfeaturedimage_backstretch' ); @@ -127,7 +128,8 @@ class Display_Featured_Image_Genesis_Common { */ public static function get_skipped_posttypes() { - $skip = get_option( 'displayfeaturedimage_exclude_front' ); + $displaysetting = get_option( 'displayfeaturedimagegenesis' ); + $skip = $displaysetting['exclude_front']; $post_types = array(); $post_types[] = 'attachment'; diff --git a/includes/class-displayfeaturedimagegenesis-output.php b/includes/class-displayfeaturedimagegenesis-output.php index 598fb5a..4bf4777 100644 --- a/includes/class-displayfeaturedimagegenesis-output.php +++ b/includes/class-displayfeaturedimagegenesis-output.php @@ -15,7 +15,8 @@ class Display_Featured_Image_Genesis_Output { * @since 1.1.3 */ public function manage_output() { - $fallback = get_option( 'displayfeaturedimage_default' ); + $displaysetting = get_option( 'displayfeaturedimagegenesis' ); + $fallback = $displaysetting['default']; if ( ( empty( $fallback ) && ! is_home() && ! is_singular() ) || ( in_array( get_post_type(), Display_Featured_Image_Genesis_Common::get_skipped_posttypes() ) ) ) { return; } @@ -102,7 +103,8 @@ class Display_Featured_Image_Genesis_Output { echo '
'; - $move_excerpts = get_option( 'displayfeaturedimage_excerpts' ); + $displaysetting = get_option( 'displayfeaturedimagegenesis' ); + $move_excerpts = $displaysetting['move_excerpts']; // if move excerpts is enabled if ( $move_excerpts && ! in_array( get_post_type(), Display_Featured_Image_Genesis_Common::omit_excerpt() ) ) { diff --git a/includes/class-displayfeaturedimagegenesis-settings.php b/includes/class-displayfeaturedimagegenesis-settings.php index ad8da1a..3fee603 100644 --- a/includes/class-displayfeaturedimagegenesis-settings.php +++ b/includes/class-displayfeaturedimagegenesis-settings.php @@ -9,10 +9,17 @@ class Display_Featured_Image_Genesis_Settings { + protected $displaysetting; + + /** + * add a submenu page under Appearance + * @return submenu Display Featured image settings page + * @since x.y.z + */ public function do_submenu_page() { add_theme_page( - __( 'Display Featured Image for Genesis: Settings', 'display-featured-image-genesis' ), + __( 'Display Featured Image for Genesis', 'display-featured-image-genesis' ), __( 'Display Featured Image Settings', 'display-featured-image-genesis' ), 'manage_options', 'displayfeaturedimagegenesis', @@ -24,8 +31,15 @@ class Display_Featured_Image_Genesis_Settings { } + /** + * create settings form + * @return form Display Featured Image for Genesis settings + * + * @since x.y.z + */ public function do_settings_form() { $page_title = get_admin_page_title(); + echo '
'; echo '

' . $page_title . '

'; echo '
'; @@ -38,52 +52,56 @@ class Display_Featured_Image_Genesis_Settings { } /** - * Settings for media screen + * Settings for options screen * @return settings for backstretch image options * * @since 1.1.0 */ public function register_settings() { - register_setting( 'displayfeaturedimagegenesis', 'displayfeaturedimage_less_header', 'absint' ); - register_setting( 'displayfeaturedimagegenesis', 'displayfeaturedimage_default', array( $this, 'validate_image' ) ); - register_setting( 'displayfeaturedimagegenesis', 'displayfeaturedimage_exclude_front', array( $this, 'one_zero' ) ); - register_setting( 'displayfeaturedimagegenesis', 'displayfeaturedimage_excerpts', array( $this, 'one_zero' ) ); + register_setting( 'displayfeaturedimagegenesis', 'displayfeaturedimagegenesis', array( $this, 'do_validation_things' ) ); + + $this->displaysetting = get_option( 'displayfeaturedimagegenesis', array( + 'less_header' => 0, + 'default' => '', + 'exclude_front' => 0, + 'move_excerpts' => 0 + ) ); add_settings_section( 'display_featured_image_section', - __( 'Display Featured Image for Genesis', 'display-featured-image-genesis' ), + __( 'Optional Sitewide Settings', 'display-featured-image-genesis' ), array( $this, 'section_description'), 'displayfeaturedimagegenesis' ); add_settings_field( - 'displayfeaturedimage_less_header', - '', + 'displayfeaturedimagegenesis[less_header]', + '', array( $this, 'header_size' ), 'displayfeaturedimagegenesis', 'display_featured_image_section' ); add_settings_field( - 'displayfeaturedimage_default', - '', + 'displayfeaturedimagegenesis[default]', + '', array( $this, 'set_default_image' ), 'displayfeaturedimagegenesis', 'display_featured_image_section' ); add_settings_field( - 'displayfeaturedimage_exclude_front', - '', + 'displayfeaturedimagegenesis[exclude_front]', + '', array( $this, 'exclude_front' ), 'displayfeaturedimagegenesis', 'display_featured_image_section' ); add_settings_field( - 'displayfeaturedimage_excerpts', - '', + 'displayfeaturedimagegenesis[move_excerpts]', + '', array( $this, 'move_excerpts' ), 'displayfeaturedimagegenesis', 'display_featured_image_section' @@ -110,10 +128,9 @@ class Display_Featured_Image_Genesis_Settings { * @since 1.1.0 */ public function header_size() { - $value = get_option( 'displayfeaturedimage_less_header', 0 ); - echo ''; - echo ''; + echo ''; + echo ''; echo '

' . __( 'Changing this number will reduce the backstretch image height by this number of pixels. Default is zero.', 'display-featured-image-genesis' ) . '

'; } @@ -126,15 +143,16 @@ class Display_Featured_Image_Genesis_Settings { * @since 1.2.1 */ public function set_default_image() { + $item = Display_Featured_Image_Genesis_Common::get_image_variables(); - if ( ! empty( $item->fallback ) ) { + if ( ! empty( $this->displaysetting['default'] ) ) { $preview = wp_get_attachment_image_src( $item->fallback_id, 'medium' ); echo '
'; echo ''; echo '
'; } - echo ''; + echo ''; 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' ), @@ -143,15 +161,13 @@ class Display_Featured_Image_Genesis_Settings { } /** - * option to exclude default featured image on front page + * option to exclude featured image on front page * @return 0 1 checkbox * * @since x.y.z */ public function exclude_front() { - $value = get_option( 'displayfeaturedimage_exclude_front' ); - - echo ' '; + echo 'displaysetting['exclude_front'], false ) . ' class="code" /> '; } /** @@ -161,9 +177,28 @@ class Display_Featured_Image_Genesis_Settings { * @since 1.3.0 */ public function move_excerpts() { - $value = get_option( 'displayfeaturedimage_excerpts' ); + echo 'displaysetting['move_excerpts'], false ) . ' class="code" /> '; + } + + /** + * validate all inputs + * @param string $new_value various settings + * @return string number or URL + * + * @since x.y.z + */ + public function do_validation_things( $new_value ) { + + $new_value['less_header'] = absint( $new_value['less_header'] ); + + $new_value['default'] = $this->validate_image( $new_value['default'] ); + + $new_value['exclude_front'] = $this->one_zero( $new_value['exclude_front'] ); + + $new_value['move_excerpts'] = $this->one_zero( $new_value['move_excerpts'] ); + + return $new_value; - echo ' '; } /** @@ -172,38 +207,42 @@ class Display_Featured_Image_Genesis_Settings { * @return string New or previous value, depending on allowed image size. * @since 1.2.2 */ - public function validate_image( $new_value ) { + protected function validate_image( $new_value ) { $new_value = esc_url( $new_value ); $valid = $this->is_valid_img_ext( $new_value ); $large = get_option( 'large_size_w' ); $id = Display_Featured_Image_Genesis_Common::get_image_id( $new_value ); $file = wp_get_attachment_image_src( $id, 'original' ); - $message = __( 'Settings saved.', 'display-featured-image-genesis' ); - $type = 'updated'; // ok for field to be empty if ( $new_value ) { if ( ! $valid ) { - $type = 'error'; - $message = __( 'Sorry, that is an invalid file type. The Default Featured Image has been reset to the last valid setting.', 'display-featured-image-genesis' ); - $new_value = get_option( 'displayfeaturedimage_default', '' ); + $message = __( 'Sorry, that is an invalid file type. The Default Featured Image has been reset to the last valid setting.', 'display-featured-image-genesis' ); + $new_value = $this->displaysetting['default']; + + add_settings_error( + $this->displaysetting['default'], + esc_attr( 'invalid' ), + $message, + 'error' + ); } // if file is an image, but is too small, throw it back elseif ( $file[1] <= $large ) { - $type = 'error'; - $message = __( 'Sorry, your image is too small. The Default Featured Image has been reset to the last valid setting.', 'display-featured-image-genesis' ); - $new_value = get_option( 'displayfeaturedimage_default', '' ); - } - } + $message = __( 'Sorry, your image is too small. The Default Featured Image has been reset to the last valid setting.', 'display-featured-image-genesis' ); + $new_value = $this->displaysetting['default']; - add_settings_error( - 'displayfeaturedimage_default', - esc_attr( 'settings-updated' ), - $message, - $type - ); + add_settings_error( + $this->displaysetting['default'], + esc_attr( 'weetiny' ), + $message, + 'error' + ); + } + + } return $new_value; } @@ -270,7 +309,7 @@ class Display_Featured_Image_Genesis_Settings { $skipfront_help = '

' . __( 'Show on Front Page', 'display-featured-image-genesis' ) . '

' . - '

' . __( 'If you set a Default Featured Image, it will show on every post/page of your site. This may not be desirable on child themes with a front page constructed with widgets, so you can select this option to prevent the Featured Image from showing on the front page.', 'display-featured-image-genesis' ) . '

' . + '

' . __( 'If you set a Default Featured Image, it will show on every post/page of your site. This may not be desirable on child themes with a front page constructed with widgets, so you can select this option to prevent the Featured Image from showing on the front page. Checking this will prevent the Featured Image from showing on the Front Page, even if you have set an image for that page individually.', 'display-featured-image-genesis' ) . '

' . '

' . sprintf( __( 'If you want to prevent entire groups of posts from not using the Featured Image, you will want to add a filter to your theme functions.php file.', 'display-featured-image-genesis' ), esc_url( 'https://github.com/robincornett/display-featured-image-genesis#how-do-i-stop-the-featured-image-action-from-showing-on-my-custom-post-types' ) diff --git a/includes/css/display-featured-image-genesis.css b/includes/css/display-featured-image-genesis.css index 1f668c0..65dc38e 100644 --- a/includes/css/display-featured-image-genesis.css +++ b/includes/css/display-featured-image-genesis.css @@ -32,7 +32,6 @@ .home .big-leader p { margin-top: 0; - margin-bottom: 18px; } .big-leader p, diff --git a/readme.txt b/readme.txt index e73197f..7686501 100644 --- a/readme.txt +++ b/readme.txt @@ -36,6 +36,10 @@ More words at [my site](http://robincornett.com/plugins/display-featured-image-g Display Featured Image for Genesis has its own settings page, under the main Appearance menu. += Does this work with any Genesis child theme? = + +Yes and no. Technically, it does, even older (XHTML) themes. However, depending on other factors such as the individual theme's styling and layout. Not recommended for themes such as Sixteen Nine Pro, or The 411 Pro due to layout, and not for Ambiance Pro or Minimum Pro without changing some theme functionality. + = 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: