2014-09-17 22:09:05 -04:00
< ? php
/**
* @package DisplayFeaturedImageGenesis
* @author Robin Cornett <hello@robincornett.com>
* @license GPL-2.0+
* @link http://robincornett.com
* @copyright 2014 Robin Cornett Creative, LLC
*/
class Display_Featured_Image_Genesis_Settings {
2014-11-05 14:30:13 -05:00
/**
* variable set for featured image option
* @var option
*/
2014-11-04 21:14:33 -05:00
protected $displaysetting ;
2015-01-03 17:43:18 -05:00
protected $post_types ;
2014-11-04 21:14:33 -05:00
/**
* add a submenu page under Appearance
* @return submenu Display Featured image settings page
2014-11-05 16:04:24 -05:00
* @since 1.4.0
2014-11-04 21:14:33 -05:00
*/
2014-11-02 19:20:00 -05:00
public function do_submenu_page () {
2014-11-02 19:51:39 -05:00
add_theme_page (
2014-11-04 21:14:33 -05:00
__ ( 'Display Featured Image for Genesis' , 'display-featured-image-genesis' ),
2014-11-02 19:20:00 -05:00
__ ( 'Display Featured Image Settings' , 'display-featured-image-genesis' ),
'manage_options' ,
'displayfeaturedimagegenesis' ,
array ( $this , 'do_settings_form' )
);
add_action ( 'admin_init' , array ( $this , 'register_settings' ) );
2014-11-02 19:51:39 -05:00
add_action ( 'load-appearance_page_displayfeaturedimagegenesis' , array ( $this , 'help' ) );
2014-11-02 19:20:00 -05:00
}
2014-11-04 21:14:33 -05:00
/**
* create settings form
* @return form Display Featured Image for Genesis settings
*
2014-11-05 16:04:24 -05:00
* @since 1.4.0
2014-11-04 21:14:33 -05:00
*/
2014-11-02 19:20:00 -05:00
public function do_settings_form () {
$page_title = get_admin_page_title ();
2014-11-04 21:14:33 -05:00
2014-11-02 19:20:00 -05:00
echo '<div class="wrap">' ;
echo '<h2>' . $page_title . '</h2>' ;
echo '<form action="options.php" method="post">' ;
settings_fields ( 'displayfeaturedimagegenesis' );
do_settings_sections ( 'displayfeaturedimagegenesis' );
2014-11-22 15:15:15 -05:00
wp_nonce_field ( 'displayfeaturedimagegenesis_save-settings' , 'displayfeaturedimagegenesis_nonce' , false );
2014-11-02 19:20:00 -05:00
submit_button ();
settings_errors ();
echo '</form>' ;
echo '</div>' ;
}
2014-09-17 22:09:05 -04:00
/**
2014-11-04 21:14:33 -05:00
* Settings for options screen
2014-09-17 22:09:05 -04:00
* @return settings for backstretch image options
*
* @since 1.1.0
*/
public function register_settings () {
2014-11-03 14:06:24 -05:00
2014-11-04 21:14:33 -05:00
register_setting ( 'displayfeaturedimagegenesis' , 'displayfeaturedimagegenesis' , array ( $this , 'do_validation_things' ) );
2014-11-21 22:03:07 -05:00
$defaults = array (
2014-11-04 21:14:33 -05:00
'less_header' => 0 ,
'default' => '' ,
'exclude_front' => 0 ,
2014-12-15 10:03:47 -05:00
'keep_titles' => 0 ,
2014-12-10 17:01:11 -05:00
'move_excerpts' => 0 ,
'feed_image' => 0
2014-11-21 22:03:07 -05:00
);
$this -> displaysetting = get_option ( 'displayfeaturedimagegenesis' , $defaults );
2014-10-21 18:16:00 -04:00
2014-09-17 22:09:05 -04:00
add_settings_section (
'display_featured_image_section' ,
2014-11-04 21:14:33 -05:00
__ ( 'Optional Sitewide Settings' , 'display-featured-image-genesis' ),
2014-09-17 22:09:05 -04:00
array ( $this , 'section_description' ),
2014-11-02 19:20:00 -05:00
'displayfeaturedimagegenesis'
2014-09-17 22:09:05 -04:00
);
add_settings_field (
2014-11-04 21:14:33 -05:00
'displayfeaturedimagegenesis[less_header]' ,
'<label for="displayfeaturedimagegenesis[less_header]">' . __ ( 'Height' , 'display-featured-image-genesis' ) . '</label>' ,
2014-09-17 22:09:05 -04:00
array ( $this , 'header_size' ),
2014-11-02 19:20:00 -05:00
'displayfeaturedimagegenesis' ,
2014-09-17 22:09:05 -04:00
'display_featured_image_section'
);
2014-10-16 08:53:41 -04:00
2014-10-21 18:16:00 -04:00
add_settings_field (
2014-11-04 21:14:33 -05:00
'displayfeaturedimagegenesis[default]' ,
'<label for="displayfeaturedimagegenesis[default]">' . __ ( 'Default Featured Image' , 'display-featured-image-genesis' ) . '</label>' ,
2014-10-21 18:16:00 -04:00
array ( $this , 'set_default_image' ),
2014-11-02 19:20:00 -05:00
'displayfeaturedimagegenesis' ,
2014-10-21 18:16:00 -04:00
'display_featured_image_section'
);
2014-11-03 14:06:24 -05:00
add_settings_field (
2014-11-04 21:14:33 -05:00
'displayfeaturedimagegenesis[exclude_front]' ,
'<label for="displayfeaturedimagegenesis[exclude_front]">' . __ ( 'Skip Front Page' , 'display-featured-image-genesis' ) . '</label>' ,
2014-11-03 14:06:24 -05:00
array ( $this , 'exclude_front' ),
'displayfeaturedimagegenesis' ,
'display_featured_image_section'
);
2014-12-15 10:03:47 -05:00
add_settings_field (
'displayfeaturedimagegenesis[keep_titles]' ,
'<label for="displayfeaturedimagegenesis[keep_titles]">' . __ ( 'Do Not Move Titles' , 'display-featured-image-genesis' ) . '</label>' ,
array ( $this , 'keep_titles' ),
'displayfeaturedimagegenesis' ,
'display_featured_image_section'
);
2014-10-28 18:12:44 -04:00
add_settings_field (
2014-11-04 21:14:33 -05:00
'displayfeaturedimagegenesis[move_excerpts]' ,
'<label for="displayfeaturedimagegenesis[move_excerpts]">' . __ ( 'Move Excerpts/Archive Descriptions' , 'display-featured-image-genesis' ) . '</label>' ,
2014-10-28 18:12:44 -04:00
array ( $this , 'move_excerpts' ),
2014-11-02 19:20:00 -05:00
'displayfeaturedimagegenesis' ,
2014-10-28 18:12:44 -04:00
'display_featured_image_section'
);
2014-12-10 17:01:11 -05:00
add_settings_field (
'displayfeaturedimagegenesis[feed_image]' ,
'<label for="displayfeaturedimagegenesis[feed_image]">' . __ ( 'Add Featured Image to Feed?' , 'display-featured-image-genesis' ) . '</label>' ,
array ( $this , 'add_image_to_feed' ),
'displayfeaturedimagegenesis' ,
'display_featured_image_section'
);
2015-01-03 17:43:18 -05:00
$args = array (
'public' => true ,
'_builtin' => false ,
'has_archive' => true ,
);
$output = 'objects' ;
$this -> post_types = get_post_types ( $args , $output );
if ( $this -> post_types ) {
add_settings_section (
'display_featured_image_custom_post_types' ,
__ ( 'CPT Featured Images' , 'display-featured-image-genesis' ),
array ( $this , 'cpt_section_description' ),
'displayfeaturedimagegenesis'
);
2015-01-03 18:08:27 -05:00
add_settings_field (
" displayfeaturedimagegenesis[post_types] " ,
__ ( 'Featured Images for Custom Post Types' , 'display-featured-image-genesis' ),
array ( $this , 'set_cpt_image' ),
'displayfeaturedimagegenesis' ,
'display_featured_image_custom_post_types'
);
2015-01-03 17:43:18 -05:00
}
2014-09-17 22:09:05 -04:00
}
/**
* Section description
* @return section description
*
* @since 1.1.0
*/
public function section_description () {
2014-11-03 14:06:24 -05:00
echo '<p>' . __ ( 'The Display Featured Image for Genesis plugin has just a few optional settings. Check the Help tab for more information. ' , 'display-featured-image-genesis' ) . '</p>' ;
2014-09-17 22:09:05 -04:00
}
2015-01-03 17:43:18 -05:00
/**
* Section description
* @return section description
*
* @since 1.1.0
*/
public function cpt_section_description () {
echo '<p>' . __ ( 'Since you have custom post types with archives, you might like to set a featured image for each of them.' , 'display-featured-image-genesis' ) . '</p>' ;
}
2014-09-17 22:09:05 -04:00
/**
* Setting for reduction amount
* @return number of pixels to remove in backstretch-set.js
*
* @since 1.1.0
*/
public function header_size () {
2014-11-04 21:14:33 -05:00
echo '<label for="displayfeaturedimagegenesis[less_header]">' . __ ( 'Pixels to remove ' , 'display-featured-image-genesis' ) . '</label>' ;
echo '<input type="number" step="1" min="0" max="400" id="displayfeaturedimagegenesis[less_header]" name="displayfeaturedimagegenesis[less_header]" value="' . esc_attr ( $this -> displaysetting [ 'less_header' ] ) . '" class="small-text" />' ;
2014-09-17 22:09:05 -04:00
echo '<p class="description">' . __ ( 'Changing this number will reduce the backstretch image height by this number of pixels. Default is zero.' , 'display-featured-image-genesis' ) . '</p>' ;
}
2014-10-21 18:16:00 -04:00
/**
* Default image uploader
*
* @return image
*
* @since 1.2.1
*/
public function set_default_image () {
2014-11-04 21:14:33 -05:00
2014-10-24 10:01:43 -04:00
$item = Display_Featured_Image_Genesis_Common :: get_image_variables ();
2014-10-21 18:16:00 -04:00
2014-11-04 21:14:33 -05:00
if ( ! empty ( $this -> displaysetting [ 'default' ] ) ) {
2014-10-31 10:57:11 -04:00
$preview = wp_get_attachment_image_src ( $item -> fallback_id , 'medium' );
2014-10-21 18:16:00 -04:00
echo '<div id="upload_logo_preview">' ;
2014-11-02 19:20:00 -05:00
echo '<img src="' . esc_url ( $preview [ 0 ] ) . '" />' ;
2014-10-21 18:16:00 -04:00
echo '</div>' ;
}
2015-01-03 17:43:18 -05:00
echo '<input type="url" class="upload_image_url" id="default_image_url" name="displayfeaturedimagegenesis[default]" value="' . esc_url ( $this -> displaysetting [ 'default' ] ) . '" />' ;
2015-01-04 18:15:32 -05:00
echo '<input id="upload_default_image" type="button" class="upload_default_image button-primary" value="' . __ ( 'Select Image' , 'display-featured-image-genesis' ) . '" />' ;
2014-10-27 17:17:13 -04:00
echo '<p class="description">' . 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' ),
2014-11-18 21:01:47 -05:00
absint ( $item -> large + 1 )
2014-10-27 17:17:13 -04:00
) . '</p>' ;
2014-10-21 18:16:00 -04:00
}
2014-11-03 14:06:24 -05:00
/**
2014-11-04 21:14:33 -05:00
* option to exclude featured image on front page
2014-11-03 14:06:24 -05:00
* @return 0 1 checkbox
*
2014-11-05 16:04:24 -05:00
* @since 1.4.0
2014-11-03 14:06:24 -05:00
*/
public function exclude_front () {
2014-11-22 15:14:57 -05:00
echo '<input type="hidden" name="displayfeaturedimagegenesis[exclude_front]" value="0" />' ;
2014-11-24 10:48:46 -05:00
echo '<label for="displayfeaturedimagegenesis[exclude_front]"><input type="checkbox" name="displayfeaturedimagegenesis[exclude_front]" id="displayfeaturedimagegenesis[exclude_front]" value="1"' . checked ( 1 , esc_attr ( $this -> displaysetting [ 'exclude_front' ] ), false ) . ' class="code" />' . __ ( 'Do not show the Featured Image on the Front Page of the site.' , 'display-featured-image-genesis' ) . '</label>' ;
2014-11-03 14:06:24 -05:00
}
2014-12-15 10:03:47 -05:00
/**
* option to not move titles
* @return 0 1 checkbox
*
* @since x.y.z
*/
public function keep_titles () {
echo '<input type="hidden" name="displayfeaturedimagegenesis[keep_titles]" value="0" />' ;
echo '<label for="displayfeaturedimagegenesis[keep_titles]"><input type="checkbox" name="displayfeaturedimagegenesis[keep_titles]" id="displayfeaturedimagegenesis[keep_titles]" value="1"' . checked ( 1 , esc_attr ( $this -> displaysetting [ 'keep_titles' ] ), false ) . ' class="code" />' . __ ( 'Do not move the titles to overlay the Featured Image.' , 'display-featured-image-genesis' ) . '</label>' ;
}
2014-10-28 18:12:44 -04:00
/**
2014-11-02 19:20:00 -05:00
* option to move excerpts to leader image area
2014-10-28 18:12:44 -04:00
* @return 0 1 checkbox
*
* @since 1.3.0
*/
public function move_excerpts () {
2014-11-22 15:14:57 -05:00
echo '<input type="hidden" name="displayfeaturedimagegenesis[move_excerpts]" value="0" />' ;
2014-11-24 10:48:46 -05:00
echo '<label for="displayfeaturedimagegenesis[move_excerpts]"><input type="checkbox" name="displayfeaturedimagegenesis[move_excerpts]" id="displayfeaturedimagegenesis[move_excerpts]" value="1"' . checked ( 1 , esc_attr ( $this -> displaysetting [ 'move_excerpts' ] ), false ) . ' class="code" />' . __ ( 'Move excerpts (if used) on single pages and move archive/taxonomy descriptions to overlay the Featured Image.' , 'display-featured-image-genesis' ) . '</label>' ;
2014-11-04 21:14:33 -05:00
}
2014-12-10 17:01:11 -05:00
/**
2014-12-11 17:30:39 -05:00
* option to add images to feed
2014-12-10 17:01:11 -05:00
* @return 0 1 checkbox
*
2014-12-13 10:03:55 -05:00
* @since 1.5.0
2014-12-10 17:01:11 -05:00
*/
public function add_image_to_feed () {
echo '<input type="hidden" name="displayfeaturedimagegenesis[feed_image]" value="0" />' ;
echo '<label for="displayfeaturedimagegenesis[feed_image]"><input type="checkbox" name="displayfeaturedimagegenesis[feed_image]" id="displayfeaturedimagegenesis[feed_image]" value="1"' . checked ( 1 , esc_attr ( $this -> displaysetting [ 'feed_image' ] ), false ) . ' class="code" />' . __ ( 'Optionally, add the featured image to your RSS feed.' , 'display-featured-image-genesis' ) . '</label>' ;
}
2015-01-04 16:05:25 -05:00
/**
* Custom Post Type image uploader
*
* @return image
*
* @since x.y.z
*/
public function set_cpt_image () {
$item = Display_Featured_Image_Genesis_Common :: get_image_variables ();
foreach ( $this -> post_types as $post ) {
$post_type = $post -> name ;
if ( empty ( $this -> displaysetting [ 'post_type' ][ $post_type ] ) ) {
$this -> displaysetting [ 'post_type' ][ $post_type ] = '' ;
}
echo '<h4>' . $post -> label . '</h4>' ;
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' );
echo '<div id="upload_logo_preview">' ;
echo '<img src="' . esc_url ( $preview [ 0 ] ) . '" />' ;
echo '</div>' ;
}
echo '<input type="url" class="upload_image_url" id="displayfeaturedimagegenesis[post_type][' . $post_type . ']" name="displayfeaturedimagegenesis[post_type][' . $post_type . ']" value="' . esc_url ( $this -> displaysetting [ 'post_type' ][ $post_type ] ) . '" />' ;
echo '<input id="displayfeaturedimagegenesis[post_type][' . $post_type . ']" type="button" class="upload_default_image button" value="' . __ ( 'Select Image' , 'display-featured-image-genesis' ) . '" />' ;
}
}
/**
* Save extra taxonomy fields callback function.
* @param term id $term_id the id of the term
* @return updated option updated option for term featured image
*
* @since x.y.z
*/
public function save_taxonomy_custom_meta ( $term_id ) {
if ( isset ( $_POST [ 'term_meta' ] ) ) {
$t_id = $term_id ;
$term_meta = get_option ( " taxonomy_ $t_id " );
$cat_keys = array_keys ( $_POST [ 'term_meta' ] );
$is_updated = false ;
foreach ( $cat_keys as $key ) {
if ( isset ( $_POST [ 'term_meta' ][ $key ] ) ) {
$term_meta [ $key ] = $_POST [ 'term_meta' ][ $key ];
if ( $_POST [ 'term_meta' ][ 'dfig_image' ] === $term_meta [ $key ] ) {
$term_meta [ $key ] = $this -> validate_taxonomy_image ( $_POST [ 'term_meta' ][ $key ] );
if ( false !== $term_meta [ $key ] ) {
$is_updated = true ;
}
}
}
}
//* Save the option array.
if ( $is_updated ) {
update_option ( " taxonomy_ $t_id " , $term_meta );
}
}
}
2014-11-04 21:14:33 -05:00
/**
* validate all inputs
* @param string $new_value various settings
* @return string number or URL
*
2014-11-05 16:04:24 -05:00
* @since 1.4.0
2014-11-04 21:14:33 -05:00
*/
public function do_validation_things ( $new_value ) {
2014-11-22 15:15:15 -05:00
if ( empty ( $_POST [ 'displayfeaturedimagegenesis_nonce' ] ) ) {
wp_die ( __ ( 'Something unexpected happened. Please try again.' , 'display-featured-image-genesis' ) );
}
check_admin_referer ( 'displayfeaturedimagegenesis_save-settings' , 'displayfeaturedimagegenesis_nonce' );
2014-11-04 21:14:33 -05:00
$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' ] );
2014-12-15 10:03:47 -05:00
$new_value [ 'keep_titles' ] = $this -> one_zero ( $new_value [ 'keep_titles' ] );
2014-11-04 21:14:33 -05:00
$new_value [ 'move_excerpts' ] = $this -> one_zero ( $new_value [ 'move_excerpts' ] );
2014-12-10 19:31:39 -05:00
$new_value [ 'feed_image' ] = $this -> one_zero ( $new_value [ 'feed_image' ] );
2015-01-03 17:43:18 -05:00
foreach ( $this -> post_types as $post_type ) {
2015-01-03 18:08:27 -05:00
$new_value [ 'post_type' ][ $post_type -> name ] = $this -> validate_post_type_image ( $new_value [ 'post_type' ][ $post_type -> name ] );
2015-01-04 17:45:32 -05:00
if ( false === $new_value [ 'post_type' ][ $post_type -> name ] ) {
$new_value [ 'post_type' ][ $post_type -> name ] = $this -> displaysetting [ 'post_type' ][ $post_type -> name ];
}
2015-01-03 17:43:18 -05:00
}
2014-11-04 21:14:33 -05:00
return $new_value ;
2014-10-28 18:12:44 -04:00
}
2014-10-25 17:41:32 -04:00
/**
* Returns previous value for image if not correct file type/size
* @param string $new_value New value
* @return string New or previous value, depending on allowed image size.
* @since 1.2.2
*/
2014-11-04 21:14:33 -05:00
protected function validate_image ( $new_value ) {
2014-10-25 17:41:32 -04:00
$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 );
2014-11-18 21:01:47 -05:00
$metadata = wp_get_attachment_metadata ( $id );
$width = $metadata [ 'width' ];
2014-10-25 17:41:32 -04:00
2015-01-04 17:45:32 -05:00
//* ok for field to be empty
2014-11-02 19:20:00 -05:00
if ( $new_value ) {
if ( ! $valid ) {
2015-01-03 11:57:06 -05:00
$message = __ ( 'Sorry, that is an invalid file type.' , 'display-featured-image-genesis' );
$message .= __ ( ' The Default Featured Image has been reset to the last valid setting.' , 'display-featured-image-genesis' );
2014-11-04 21:14:33 -05:00
$new_value = $this -> displaysetting [ 'default' ];
add_settings_error (
$this -> displaysetting [ 'default' ],
esc_attr ( 'invalid' ),
$message ,
'error'
);
2014-11-02 19:20:00 -05:00
}
2015-01-04 17:45:32 -05:00
//* if file is an image, but is too small, throw it back
2014-11-18 21:01:47 -05:00
elseif ( $width <= $large ) {
2015-01-03 11:57:06 -05:00
$message = __ ( 'Sorry, your image is too small.' , 'display-featured-image-genesis' );
$message .= __ ( ' The Default Featured Image has been reset to the last valid setting.' , 'display-featured-image-genesis' );
2014-11-04 21:14:33 -05:00
$new_value = $this -> displaysetting [ 'default' ];
add_settings_error (
$this -> displaysetting [ 'default' ],
esc_attr ( 'weetiny' ),
$message ,
'error'
);
2014-11-02 19:20:00 -05:00
}
2014-10-25 17:41:32 -04:00
2014-11-04 21:14:33 -05:00
}
2014-11-02 19:20:00 -05:00
return $new_value ;
2014-10-25 17:41:32 -04:00
}
2015-01-03 18:08:27 -05:00
/**
* Returns empty value for image if not correct file type/size
* @param string $new_value New value
* @return string New or previous value, depending on allowed image size.
* @since x.y.z
*/
protected function validate_post_type_image ( $new_value ) {
$new_value = esc_url ( $new_value );
$valid = $this -> is_valid_img_ext ( $new_value );
2015-01-04 18:15:32 -05:00
$large = get_option ( 'large_size_w' );
2015-01-03 18:08:27 -05:00
$id = Display_Featured_Image_Genesis_Common :: get_image_id ( $new_value );
$metadata = wp_get_attachment_metadata ( $id );
$width = $metadata [ 'width' ];
2015-01-04 17:45:32 -05:00
//* ok for field to be empty
2015-01-03 18:08:27 -05:00
if ( $new_value ) {
if ( ! $valid ) {
$message = __ ( 'Sorry, that is an invalid file type.' , 'display-featured-image-genesis' );
2015-01-04 18:15:32 -05:00
$new_value = false ;
2015-01-03 18:08:27 -05:00
add_settings_error (
$this -> displaysetting [ 'post_type' ],
esc_attr ( 'invalid' ),
$message ,
'error'
);
}
2015-01-04 17:45:32 -05:00
//* if file is an image, but is too small, throw it back
2015-01-04 18:15:32 -05:00
elseif ( $width <= $large ) {
2015-01-03 18:08:27 -05:00
$message = __ ( 'Sorry, your image is too small.' , 'display-featured-image-genesis' );
2015-01-04 17:45:32 -05:00
$new_value = false ;
2015-01-03 18:08:27 -05:00
add_settings_error (
$this -> displaysetting [ 'post_type' ],
esc_attr ( 'weetiny' ),
$message ,
'error'
);
}
}
return $new_value ;
}
2015-01-04 16:05:25 -05:00
/**
* Returns false value for image if not correct file type/size
* @param string $new_value New value
* @return string New value or false, depending on allowed image size.
* @since x.y.z
*/
protected function validate_taxonomy_image ( $new_value ) {
$new_value = esc_url ( $new_value );
$valid = $this -> is_valid_img_ext ( $new_value );
2015-01-04 18:15:32 -05:00
$large = get_option ( 'large_size_w' );
2015-01-04 16:05:25 -05:00
$id = Display_Featured_Image_Genesis_Common :: get_image_id ( $new_value );
$metadata = wp_get_attachment_metadata ( $id );
$width = $metadata [ 'width' ];
// ok for field to be empty
2015-01-04 18:15:32 -05:00
if ( $new_value && ( ! $valid || $width <= $large ) ) {
2015-01-04 16:05:25 -05:00
$new_value = false ;
}
return $new_value ;
}
2014-10-25 17:41:32 -04:00
/**
* returns file extension
* @since 1.2.2
*/
2014-10-28 18:12:44 -04:00
protected function get_file_ext ( $file ) {
2014-10-25 17:41:32 -04:00
$parsed = @ parse_url ( $file , PHP_URL_PATH );
return $parsed ? strtolower ( pathinfo ( $parsed , PATHINFO_EXTENSION ) ) : false ;
}
/**
* check if file type is image
* @return file check file extension against list
* @since 1.2.2
*/
2014-10-28 18:12:44 -04:00
protected function is_valid_img_ext ( $file ) {
2014-10-25 17:41:32 -04:00
$file_ext = $this -> get_file_ext ( $file );
$this -> valid = empty ( $this -> valid )
? ( array ) apply_filters ( 'displayfeaturedimage_valid_img_types' , array ( 'jpg' , 'jpeg' , 'png' , 'gif' ) )
: $this -> valid ;
return ( $file_ext && in_array ( $file_ext , $this -> valid ) );
}
2014-10-28 18:12:44 -04:00
/**
* Returns a 1 or 0, for all truthy / falsy values.
*
* Uses double casting. First, we cast to bool, then to integer.
*
* @since 1.3.0
*
* @param mixed $new_value Should ideally be a 1 or 0 integer passed in
* @return integer 1 or 0.
*/
2014-11-21 15:50:19 -05:00
protected function one_zero ( $new_value ) {
2014-10-28 18:12:44 -04:00
return ( int ) ( bool ) $new_value ;
}
2014-09-17 22:09:05 -04:00
/**
* Help tab for media screen
* @return help tab with verbose information for plugin
*
* @since 1.1.0
*/
public function help () {
$screen = get_current_screen ();
2014-10-25 17:41:32 -04:00
$large = get_option ( 'large_size_w' );
2014-09-17 22:09:05 -04:00
2014-11-02 19:20:00 -05:00
$height_help =
2014-10-28 18:12:44 -04:00
'<h3>' . __ ( 'Height' , 'display-featured-image-genesis' ) . '</h3>' .
2014-11-02 19:20:00 -05:00
'<p>' . __ ( '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 to change this number. It will raise the bottom line of the backstretch image, making it shorter.' , 'display-featured-image-genesis' ) . '</p>' ;
2014-10-24 10:01:43 -04:00
2014-11-02 19:20:00 -05:00
$default_help =
2014-10-24 10:01:43 -04:00
'<h3>' . __ ( 'Set a Default Featured Image' , 'display-featured-image-genesis' ) . '</h3>' .
2014-10-25 17:41:32 -04:00
'<p>' . __ ( '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.' , 'display-featured-image-genesis' ) . '</p>' .
'<p>' . sprintf (
__ ( 'Supported file types are: jpg, jpeg, png, and gif. The image must be at least %1$s pixels wide.' , 'display-featured-image-genesis' ),
2014-11-18 21:01:47 -05:00
absint ( $large + 1 )
2014-11-02 19:20:00 -05:00
) . '</p>' ;
2014-11-03 14:06:24 -05:00
$skipfront_help =
'<h3>' . __ ( 'Show on Front Page' , 'display-featured-image-genesis' ) . '</h3>' .
2014-11-04 21:14:33 -05:00
'<p>' . __ ( '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' ) . '</p>' .
2014-11-03 14:06:24 -05:00
'<p>' . sprintf (
__ ( 'If you want to prevent entire groups of posts from not using the Featured Image, you will want to <a href="%s" target="_blank">add a filter</a> 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' )
) . '</p>' ;
2014-11-02 19:20:00 -05:00
$excerpts_help =
2014-10-28 18:12:44 -04:00
'<h3>' . __ ( 'Move Excerpts/Archive Descriptions' , 'display-featured-image-genesis' ) . '</h3>' .
2014-11-02 19:20:00 -05:00
'<p>' . __ ( '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' ) . '</p>' ;
2014-12-10 19:31:53 -05:00
$feed_help =
'<h3>' . __ ( 'Add Featured Image to Feed?' , 'display-featured-image-genesis' ) . '</h3>' .
'<p>' . __ ( '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' ) . '</p>' .
'<p>' . __ ( 'If your RSS feed is set to Full Text, the Featured Image will be added to the entry content. If it is set to Summary, the Featured Image will be added to the excerpt instead.' , 'display-featured-image-genesis' ) . '</p>' ;
2014-11-02 19:20:00 -05:00
$screen -> add_help_tab ( array (
'id' => 'displayfeaturedimage_less_header-help' ,
'title' => __ ( 'Height' , 'display-featured-image-genesis' ),
'content' => $height_help ,
) );
$screen -> add_help_tab ( array (
'id' => 'displayfeaturedimage_default-help' ,
'title' => __ ( 'Default Featured Image' , 'display-featured-image-genesis' ),
'content' => $default_help ,
) );
2014-09-17 22:09:05 -04:00
2014-11-03 14:06:24 -05:00
$screen -> add_help_tab ( array (
'id' => 'displayfeaturedimage_exclude_front-help' ,
'title' => __ ( 'Show on Front Page' , 'display-featured-image-genesis' ),
'content' => $skipfront_help ,
) );
2014-09-17 22:09:05 -04:00
$screen -> add_help_tab ( array (
2014-11-02 19:20:00 -05:00
'id' => 'displayfeaturedimage_excerpts-help' ,
'title' => __ ( 'Move Excerpts' , 'display-featured-image-genesis' ),
'content' => $excerpts_help ,
2014-09-17 22:09:05 -04:00
) );
2014-12-10 19:31:53 -05:00
$screen -> add_help_tab ( array (
'id' => 'displayfeaturedimage_feed-help' ,
'title' => __ ( 'RSS Feed' , 'display-featured-image-genesis' ),
'content' => $feed_help ,
) );
2014-09-17 22:09:05 -04:00
}
}