* @license GPL-2.0+ * @link http://robincornett.com * @copyright 2014-2015 Robin Cornett Creative, LLC */ class Display_Featured_Image_Genesis_Settings extends Display_Featured_Image_Genesis_Helper { /** * variable set for featured image option * @var option */ protected $common; protected $page; protected $displaysetting; protected $post_types; protected $fields; /** * add a submenu page under Appearance * @return submenu Display Featured image settings page * @since 1.4.0 */ public function do_submenu_page() { $this->page = 'displayfeaturedimagegenesis'; $this->common = new Display_Featured_Image_Genesis_Common(); add_theme_page( __( 'Display Featured Image for Genesis', 'display-featured-image-genesis' ), __( 'Display Featured Image for Genesis', 'display-featured-image-genesis' ), 'manage_options', $this->page, array( $this, 'do_settings_form' ) ); add_action( 'admin_init', array( $this, 'register_settings' ) ); add_action( 'load-appearance_page_displayfeaturedimagegenesis', array( $this, 'help' ) ); $this->displaysetting = $this->get_display_setting(); } /** * create settings form * @return form Display Featured Image for Genesis settings * * @since 1.4.0 */ public function do_settings_form() { if ( $this->terms_need_updating() ) { $this->update_delete_term_meta(); } $page_title = get_admin_page_title(); $heading = $GLOBALS['wp_version'] >= '4.3' ? 'h1' : 'h2'; echo '
%s
', wp_kses_post( $description ) ); } /** * validate all inputs * @param string $new_value various settings * @return string number or URL * * @since 1.4.0 */ public function do_validation_things( $new_value ) { $action = 'displayfeaturedimagegenesis_save-settings'; $nonce = 'displayfeaturedimagegenesis_nonce'; // If the user doesn't have permission to save, then display an error message if ( ! $this->user_can_save( $action, $nonce ) ) { wp_die( esc_attr__( 'Something unexpected happened. Please try again.', 'display-featured-image-genesis' ) ); } check_admin_referer( 'displayfeaturedimagegenesis_save-settings', 'displayfeaturedimagegenesis_nonce' ); $new_value['less_header'] = absint( $new_value['less_header'] ); // validate all checkbox fields foreach ( $this->fields as $field ) { if ( 'do_checkbox' === $field['callback'] ) { $new_value[ $field['id'] ] = $this->one_zero( $new_value[ $field['id'] ] ); } } // extra variables to pass through to image validation $old_value = $this->displaysetting['default']; $label = 'Default'; $size_to_check = $this->common->minimum_backstretch_width(); // validate default image $new_value['default'] = $this->validate_image( $new_value['default'], $old_value, $label, $size_to_check ); foreach ( $this->post_types as $post_type ) { // extra variables to pass through to image validation $old_value = isset( $this->displaysetting['post_type'][ $post_type->name ] ) ? $this->displaysetting['post_type'][ $post_type->name ] : ''; $label = $post_type->label; $size_to_check = get_option( 'medium_size_w' ); // sanitize $new_value['post_type'][ $post_type->name ] = $this->validate_image( $new_value['post_type'][ $post_type->name ], $old_value, $label, $size_to_check ); } return $new_value; } /** * 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 */ protected function validate_image( $new_value, $old_value, $label, $size_to_check ) { $new_value = displayfeaturedimagegenesis_check_image_id( $new_value ); $old_value = displayfeaturedimagegenesis_check_image_id( $old_value ); $source = wp_get_attachment_image_src( $new_value, 'full' ); $valid = $this->is_valid_img_ext( $source[0] ); $width = $source[1]; $reset = sprintf( __( ' The %s Featured Image has been reset to the last valid setting.', 'display-featured-image-genesis' ), $label ); // ok for field to be empty if ( ! $new_value ) { return ''; } if ( $valid && $width > $size_to_check ) { return (int) $new_value; } $new_value = $old_value; if ( ! $valid ) { $message = __( 'Sorry, that is an invalid file type.', 'display-featured-image-genesis' ); $class = 'invalid'; } elseif ( $width <= $size_to_check ) { $message = __( 'Sorry, your image is too small.', 'display-featured-image-genesis' ); $class = 'weetiny'; } add_settings_error( $old_value, esc_attr( $class ), esc_attr( $message . $reset ), 'error' ); return (int) $new_value; } /** * Help tab for media screen * @return help tab with verbose information for plugin * * @since 1.1.0 */ public function help() { $screen = get_current_screen(); $large = $this->common->minimum_backstretch_width(); $height_help = '' . __( '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' ) . '
'; $height_help .= '' . __( 'The plugin determines the size of your backstretch image based on the size of the user\'s browser window. Changing the "Height" setting tells the plugin to subtract that number of pixels from the measured height of the user\'s window, regardless of the size of that window.', 'display-featured-image-genesis' ) . '
'; $height_help .= '' . __( 'If you need to control the size of the backstretch Featured Image output with more attention to the user\'s screen size, you will want to consider a CSS approach instead. Check the readme for an example.', 'display-featured-image-genesis' ) . '
'; $default_help = '' . __( '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' ) . '
'; $default_help .= '' . sprintf( __( 'Supported file types are: jpg, jpeg, png, and gif. The image must be at least %1$s pixels wide.', 'display-featured-image-genesis' ), absint( $large + 1 ) ) . '
'; $skipfront_help = '' . __( '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' ) . '
'; $skipfront_help .= '' . 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' ) ) . '
'; $keeptitles_help = '' . __( 'This setting applies to the backstretch Featured Image only. It allows you to keep the post/page titles in their original location, instead of overlaying the new image.', 'display-featured-image-genesis' ) . '
'; $excerpts_help = '' . __( '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 = '' . __( '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 = '' . __( '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' ) . '
'; $feed_help .= '' . __( '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' ) . '
'; $cpt_help = '' . __( 'Some plugins and/or developers extend the power of WordPress by using Custom Post Types to create special kinds of content.', 'display-featured-image-genesis' ) . '
'; $cpt_help .= '' . __( 'Since you have custom post types with archives, you might like to set a featured image for each of them.', 'display-featured-image-genesis' ) . '
'; $cpt_help .= '' . __( 'Featured Images for archives can be smaller than the Default Featured Image, but still need to be larger than your site\'s "medium" image size.', 'display-featured-image-genesis' ) . '
'; $help_tabs = array( array( 'id' => 'displayfeaturedimage_less_header-help', 'title' => __( 'Height', 'display-featured-image-genesis' ), 'content' => $height_help, ), array( 'id' => 'displayfeaturedimage_default-help', 'title' => __( 'Default Featured Image', 'display-featured-image-genesis' ), 'content' => $default_help, ), array( 'id' => 'displayfeaturedimage_exclude_front-help', 'title' => __( 'Skip Front Page', 'display-featured-image-genesis' ), 'content' => $skipfront_help, ), array( 'id' => 'displayfeaturedimage_keep_titles-help', 'title' => __( 'Do Not Move Titles', 'display-featured-image-genesis' ), 'content' => $keeptitles_help, ), array( 'id' => 'displayfeaturedimage_excerpts-help', 'title' => __( 'Move Excerpts', 'display-featured-image-genesis' ), 'content' => $excerpts_help, ), array( 'id' => 'displayfeaturedimage_paged-help', 'title' => __( 'Subsequent Pages', 'display-featured-image-genesis' ), 'content' => $paged_help, ), array( 'id' => 'displayfeaturedimage_feed-help', 'title' => __( 'RSS Feed', 'display-featured-image-genesis' ), 'content' => $feed_help, ), ); if ( $this->post_types ) { $help_tabs[] = array( 'id' => 'displayfeaturedimage_cpt-help', 'title' => __( 'Custom Post Types', 'display-featured-image-genesis' ), 'content' => $cpt_help, ); } foreach ( $help_tabs as $tab ) { $screen->add_help_tab( $tab ); } } /** * For 4.4, output a notice explaining that old term options can be updated to term_meta. * Options are to update all terms or to ignore, and do by hand. * @since 2.4.0 */ protected function term_meta_notice() { $screen = get_current_screen(); if ( 'appearance_page_displayfeaturedimagegenesis' !== $screen->id ) { return; } $terms = $this->get_affected_terms(); if ( empty( $terms ) ) { return; } $message = sprintf( '%s
', __( 'WordPress 4.4 introduces term metadata for categories, tags, and other taxonomies. This is your opportunity to optionally update all impacted terms on your site to use the new metadata.', 'display-featured-image-genesis' ) ); $message .= sprintf( '%s
', __( 'This will modify your database (potentially many entries at once), so if you\'d rather do it yourself, you can. Here\'s a list of the affected terms:', 'display-featured-image-genesis' ) ); $message .= '%s
', __( 'To get rid of this notice, you can 1) update your terms by hand; 2) click the update button (please check your terms afterward); or 3) click the dismiss button.', 'display-featured-image-genesis' ) ); $faq = sprintf( __( 'For more information, please visit the plugin\'s Frequently Asked Questions on WordPress.org.', 'display-featured-image-genesis' ), esc_url( 'https://wordpress.org/plugins/display-featured-image-genesis/faq/' ) ); $message .= sprintf( '%s
', $faq ); echo '