/** * Define array of checkboxes to add to post editor featured image. * @return array * @since 2.5.2 */ protected function get_checkboxes() { $checkboxes = array(array('setting' => $this->disable, 'label' => __('Don\'t show the featured image on this post', 'display-featured-image-genesis'))); $setting = displayfeaturedimagegenesis_get_setting(); if (!$setting['keep_titles']) { $checkboxes[] = array('setting' => $this->move, 'label' => __('Don\'t move the title to overlay the backstretch featured image on this post', 'display-featured-image-genesis')); } return $checkboxes; }
/** * set parameters for scripts, etc. to run. * * @since 1.1.3 */ public function manage_output() { $this->setting = displayfeaturedimagegenesis_get_setting(); if ($this->quit_now()) { return; } $this->common = new Display_Featured_Image_Genesis_Common(); $this->item = Display_Featured_Image_Genesis_Common::get_image_variables(); add_filter('jetpack_photon_override_image_downsize', '__return_true'); add_action('wp_enqueue_scripts', array($this, 'load_scripts')); }
/** * Decide whether or not to add the featured image to the feed or the feed excerpt * * @return filter the_excerpt_rss (if summaries) or the_content_feed (full text) * @since 1.5.0 */ public function maybe_do_feed() { $displaysetting = displayfeaturedimagegenesis_get_setting(); $feed_image = $displaysetting['feed_image']; // if the user isn't sending images to the feed, we're done if (!$feed_image || Display_Featured_Image_Genesis_Common::is_in_array('skipped_posttypes')) { return; } // if the feed is summary, filter the excerpt $which_filter = 'the_excerpt_rss'; $priority = 1000; $rss_option = get_option('rss_use_excerpt'); // if the feed is full text, filter the content if ('0' === $rss_option) { $which_filter = 'the_content_feed'; $priority = 15; } add_filter($which_filter, array($this, 'add_image_to_feed'), $priority); }
/** * Show optional excerpt on single posts. * * If it's not a single post, nothing happens. * * If there's an excerpt and the move excerpts option is selected, it runs through `wpautop()` before being added to a div. * * @since 1.3.0 * * @return null Return early if not a single post with an excerpt. */ public function do_excerpt() { if (!is_singular() || is_front_page()) { return; } $headline = $intro_text = $itemprop = ''; if (genesis_html5()) { $itemprop = ' itemprop="headline"'; } $setting = displayfeaturedimagegenesis_get_setting(); if (!$setting['keep_titles']) { $headline = sprintf('<h1 class="entry-title"%s>%s</h1>', $itemprop, get_the_title()); } if (has_excerpt()) { $intro_text = apply_filters('display_featured_image_genesis_singular_description', get_the_excerpt()); } if ($headline || $intro_text) { $print = $headline . wpautop($intro_text); $class = 'excerpt'; $this->print_description($print, $class, $class); } }
/** * check existing settings array to see if a setting is in the array * @return updated setting updates to default (0) * @since 1.5.0 */ public function check_settings() { $displaysetting = displayfeaturedimagegenesis_get_setting(); // return early if the option doesn't exist yet if (empty($displaysetting)) { return; } if (empty($displaysetting['feed_image'])) { $this->update_settings(array('feed_image' => 0)); } // new setting for titles added in 2.0.0 if (empty($displaysetting['keep_titles'])) { $this->update_settings(array('keep_titles' => 0)); } // new setting for subsequent pages added in 2.2.0 if (empty($displaysetting['is_paged'])) { $this->update_settings(array('is_paged' => 0)); } }
/** * retrieve image ID for output * * @param string $image_id variable, ID of featured image * * @since 2.2.1 * @return int|string $image_id */ public static function set_image_id($image_id = '') { $setting = displayfeaturedimagegenesis_get_setting(); $fallback = $setting['default']; $fallback_id = displayfeaturedimagegenesis_check_image_id($fallback); // set here with fallback preemptively, if it exists if (!empty($fallback)) { /** * Creates display_featured_image_genesis_use_default filter to check * whether get_post_type array should use default image. * @uses is_in_array() */ $image_id = $fallback_id; if (self::is_in_array('use_default') || $setting['always_default']) { return (int) $image_id; } } // outlier: if it's a home page with a static front page, and there is a featured image set on the home page // also provisionally sets featured image for posts, similar to CPT archives $frontpage = get_option('show_on_front'); // either 'posts' or 'page' if ('page' === $frontpage) { $postspage = get_option('page_for_posts'); $postspage_image = get_post_thumbnail_id($postspage); $setting['post_type']['post'] = (int) $postspage_image; } // if a post type image exists, it takes priority over the fallback. check that next. $post_type = get_post_type(); if (!empty($setting['post_type'][$post_type])) { /** * Creates display_featured_image_genesis_use_post_type_image filter to check * whether get_post_type array should use the post type image. * @uses is_in_array() */ $image_id = displayfeaturedimagegenesis_check_image_id($setting['post_type'][$post_type]); if (self::is_in_array('use_post_type_image')) { return (int) $image_id; } } if (is_author()) { $image_id = get_the_author_meta('displayfeaturedimagegenesis', (int) get_query_var('author')); } // taxonomy if (is_category() || is_tag() || is_tax()) { $object = get_queried_object(); $image = displayfeaturedimagegenesis_get_term_image($object->term_id); if ($image) { $image_id = $image; } } // search page if (is_search() && !empty($setting['post_type']['search'])) { $image_id = $setting['post_type']['search']; } // 404 if (is_404() && !empty($setting['post_type']['fourohfour'])) { $image_id = $setting['post_type']['fourohfour']; } // any singular post/page/CPT if (is_singular()) { $image_id = self::get_singular_post_image($image_id, $setting, $post_type); } /** * filter to use a different image id * @var $image_id * * @since 2.2.0 */ $image_id = apply_filters('display_featured_image_genesis_image_id', $image_id); // make sure the image id is an integer $image_id = is_numeric($image_id) ? (int) $image_id : ''; return $image_id; }
/** * Get custom post type featured image ID. * @return ID Gets the ID of the image assigned as the custom post type featured image. * * @since 2.1.0 */ function display_featured_image_genesis_get_cpt_image_id($image_id = '') { $post_type = ''; $displaysetting = displayfeaturedimagegenesis_get_setting(); $object = get_queried_object(); if (!$object || is_admin()) { return; } if ($object->name) { // results in post type on cpt archive $post_type = $object->name; } elseif ($object->taxonomy) { // on a tax/term/category $tax_object = get_taxonomy($object->taxonomy); $post_type = $tax_object->object_type[0]; } elseif ($object->post_type) { // on singular $post_type = $object->post_type; } if (!empty($displaysetting['post_type'][$post_type])) { $image_id = displayfeaturedimagegenesis_check_image_id($displaysetting['post_type'][$post_type]); } return (int) $image_id; }
/** * Echo the widget content. * * @since 2.0.0 * * * @param array $args Display arguments including before_title, after_title, before_widget, and after_widget. * @param array $instance The settings for the particular instance of the widget */ function widget($args, $instance) { // Merge with defaults $instance = wp_parse_args((array) $instance, $this->defaults); $post_type = get_post_type_object($instance['post_type']); if (!$post_type) { return; } $option = displayfeaturedimagegenesis_get_setting(); $image_id = ''; if ('post' === $instance['post_type']) { $frontpage = get_option('show_on_front'); // either 'posts' or 'page' $postspage = get_option('page_for_posts'); $postspage_image = get_post_thumbnail_id($postspage); $title = get_post($postspage)->post_title; $permalink = esc_url(get_the_permalink($postspage)); if ('posts' === $frontpage || 'page' === $frontpage && !$postspage) { $postspage_image = display_featured_image_genesis_get_default_image_id(); $title = get_bloginfo('name'); $permalink = home_url(); } $image_id = $postspage_image; } else { $title = $post_type->label; $permalink = esc_url(get_post_type_archive_link($instance['post_type'])); if (post_type_supports($instance['post_type'], 'genesis-cpt-archives-settings')) { $headline = genesis_get_cpt_option('headline', $instance['post_type']); if (!empty($headline)) { $title = $headline; } } } echo $args['before_widget']; if (!empty($instance['title'])) { echo $args['before_title'] . apply_filters('widget_title', $instance['title'], $instance, $this->id_base) . $args['after_title']; } $image = ''; if (isset($option['post_type'][$post_type->name])) { $image_id = displayfeaturedimagegenesis_check_image_id($option['post_type'][$post_type->name]); } $image_src = wp_get_attachment_image_src($image_id, $instance['image_size']); if ($image_src) { $image = '<img src="' . $image_src[0] . '" alt="' . $title . '" />'; } if ($instance['show_image'] && $image) { $role = empty($instance['show_title']) ? '' : 'aria-hidden="true"'; printf('<a href="%s" title="%s" class="%s" %s>%s</a>', esc_url($permalink), esc_html($title), esc_attr($instance['image_alignment']), $role, $image); } if ($instance['show_title']) { if (!empty($instance['show_title'])) { $title_output = sprintf('<h2><a href="%s">%s</a></h2>', $permalink, esc_html($title)); if (genesis_html5()) { $title_output = sprintf('<h2 class="archive-title"><a href="%s">%s</a></h2>', $permalink, esc_html($title)); } echo wp_kses_post($title_output); } } $intro_text = ''; if (post_type_supports($instance['post_type'], 'genesis-cpt-archives-settings')) { $intro_text = genesis_get_cpt_option('intro_text', $instance['post_type']); } elseif ('post' === $instance['post_type']) { $intro_text = get_post($postspage)->post_excerpt; if ('posts' === $frontpage || 'page' === $frontpage && !$postspage) { $intro_text = get_bloginfo('description'); } } if ($instance['show_content'] && $intro_text) { echo genesis_html5() ? '<div class="archive-description">' : ''; $intro_text = apply_filters('display_featured_image_genesis_cpt_description', $intro_text); echo wp_kses_post(wpautop($intro_text)); echo genesis_html5() ? '</div>' : ''; } echo $args['after_widget']; }