Files
display-featured-image-genesis/includes/class-displayfeaturedimagegenesis-description.php
T

253 lines
7.6 KiB
PHP
Raw Normal View History

2014-10-28 18:12:44 -04:00
<?php
2014-11-18 10:53:17 -05:00
/**
* @package DisplayFeaturedImageGenesis
* @author Robin Cornett <hello@robincornett.com>
* @license GPL-2.0+
2016-07-03 07:42:41 -04:00
* @link https://robincornett.com
2017-02-17 09:43:46 -05:00
* @copyright 2014-2017 Robin Cornett Creative, LLC
2014-11-18 10:53:17 -05:00
*/
2014-10-28 18:12:44 -04:00
class Display_Featured_Image_Genesis_Description {
/**
* 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.
*/
2015-06-03 14:36:16 -04:00
public function do_excerpt() {
2014-10-28 18:12:44 -04:00
2014-11-01 20:08:24 -04:00
if ( ! is_singular() || is_front_page() ) {
2014-10-28 18:12:44 -04:00
return;
}
2014-11-01 20:08:24 -04:00
2015-02-13 17:06:03 -05:00
$headline = $intro_text = $itemprop = '';
2014-11-01 20:08:24 -04:00
2015-02-13 17:06:03 -05:00
if ( genesis_html5() ) {
2016-04-30 14:20:46 -04:00
$itemprop = ' itemprop="headline"';
2014-11-01 20:08:24 -04:00
}
2016-04-04 15:50:04 -04:00
2018-12-05 15:29:32 -05:00
$setting = displayfeaturedimagegenesis_get_setting();
2016-04-04 15:50:04 -04:00
if ( ! $setting['keep_titles'] ) {
2016-04-30 14:20:46 -04:00
$headline = sprintf( '<h1 class="entry-title"%s>%s</h1>', $itemprop, get_the_title() );
2016-04-04 15:50:04 -04:00
}
2015-02-13 17:06:03 -05:00
2014-11-01 20:08:24 -04:00
if ( has_excerpt() ) {
2015-04-24 17:03:05 -04:00
$intro_text = apply_filters( 'display_featured_image_genesis_singular_description', get_the_excerpt() );
2014-11-01 20:08:24 -04:00
}
if ( $headline || $intro_text ) {
2016-01-28 11:00:09 -05:00
$print = $headline . wpautop( $intro_text );
$class = 'excerpt';
2016-02-20 15:45:23 -05:00
$this->print_description( $print, $class, $class );
2014-11-01 20:08:24 -04:00
}
}
/**
* Show optional excerpt on blog or front page.
*
* If it's not the front page and isn't home, 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 blog/front page.
*/
2015-06-03 14:36:16 -04:00
public function do_front_blog_excerpt() {
2014-11-01 20:08:24 -04:00
if ( ! is_front_page() && ! is_home() ) {
return;
}
// set front page and posts page variables
2015-09-06 16:45:43 -04:00
$title = $this->get_front_blog_title();
2016-04-30 14:20:46 -04:00
$itemprop = genesis_html5() ? ' itemprop="headline"' : '';
$headline = empty( $title ) ? '' : sprintf( '<h1 class="entry-title"%s>%s</h1>', $itemprop, $title );
2015-09-06 16:45:43 -04:00
$intro_text = $this->get_front_blog_intro_text();
2015-02-13 17:06:03 -05:00
2014-11-01 20:08:24 -04:00
if ( $headline || $intro_text ) {
2016-01-28 11:00:09 -05:00
$print = $headline . wpautop( $intro_text );
$class = 'excerpt';
2016-02-20 15:45:23 -05:00
$this->print_description( $print, $class, $class );
2014-11-01 20:08:24 -04:00
}
2014-10-28 18:12:44 -04:00
}
/**
* Add custom description to category / tag / taxonomy archive pages.
*
* If the page is not a category, tag or taxonomy term archive, or we're not on the first page, or there's no term, or
* no term meta set, then nothing extra is displayed.
*
* If there's a description to display, it runs through `wpautop()` before being added to a div.
*
* @since 1.3.0
*
* @global WP_Query $wp_query Query object.
*
* @return null Return early if not the correct archive page, not page one, or no term meta is set.
*/
2015-06-03 14:36:16 -04:00
public function do_tax_description() {
2014-10-28 18:12:44 -04:00
global $wp_query;
2015-02-15 15:55:07 -05:00
if ( ! is_category() && ! is_tag() && ! is_tax() ) {
2014-10-28 18:12:44 -04:00
return;
2015-02-15 15:55:07 -05:00
}
2014-10-28 18:12:44 -04:00
$term = is_tax() ? get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ) : $wp_query->get_queried_object();
2016-03-02 21:44:01 -05:00
if ( ! $term ) {
2014-10-28 18:12:44 -04:00
return;
2015-02-15 15:55:07 -05:00
}
2014-10-28 18:12:44 -04:00
2016-03-02 21:44:01 -05:00
$intro_text = displayfeaturedimagegenesis_get_term_meta( $term, 'intro_text' );
$intro_text = apply_filters( 'display_featured_image_genesis_term_description', $intro_text );
2014-10-28 18:12:44 -04:00
2015-02-13 17:06:03 -05:00
if ( $intro_text ) {
2016-01-28 11:00:09 -05:00
$class = 'archive-description taxonomy-description';
$this->print_description( $intro_text, $class );
2015-02-13 17:06:03 -05:00
}
2014-10-28 18:12:44 -04:00
}
/**
* Add custom headline and description to author archive pages.
*
* If we're not on an author archive page, or not on page 1, then nothing extra is displayed.
*
* If there's a custom headline to display, it is marked up as a level 1 heading.
*
* If there's a description (intro text) to display, it is run through `wpautop()` before being added to a div.
*
* @since 1.4.0
*
* @return null Return early if not author archive or not page one.
*/
2015-06-03 14:36:16 -04:00
public function do_author_description() {
2014-10-28 18:12:44 -04:00
2015-02-13 17:06:03 -05:00
if ( ! is_author() || get_query_var( 'paged' ) >= 2 ) {
2014-10-28 18:12:44 -04:00
return;
2015-02-13 17:06:03 -05:00
}
2014-10-28 18:12:44 -04:00
2015-02-13 17:06:03 -05:00
$intro_text = apply_filters( 'display_featured_image_genesis_author_description', get_the_author_meta( 'intro_text', (int) get_query_var( 'author' ) ) );
2014-10-28 18:12:44 -04:00
2015-02-13 17:06:03 -05:00
if ( $intro_text ) {
2016-01-28 11:00:09 -05:00
$class = 'archive-description author-description';
$this->print_description( $intro_text, $class );
2015-02-13 17:06:03 -05:00
}
2014-10-28 18:12:44 -04:00
}
/**
* Add custom headline and description to relevant custom post type archive pages.
*
* If we're not on a post type archive page, or not on page 1, then nothing extra is displayed.
*
* If there's a custom headline to display, it is marked up as a level 1 heading.
*
* If there's a description (intro text) to display, it is run through wpautop() before being added to a div.
*
* @since 2.0.0
*
* @uses genesis_has_post_type_archive_support() Check if a post type should potentially support an archive setting page.
* @uses genesis_get_cpt_option() Get list of custom post types which need an archive settings page.
*
* @return null Return early if not on relevant post type archive.
*/
2015-06-03 14:36:16 -04:00
public function do_cpt_archive_description() {
2014-10-28 18:12:44 -04:00
2015-02-13 17:06:03 -05:00
if ( ! is_post_type_archive() || ! genesis_has_post_type_archive_support() ) {
2014-10-28 18:12:44 -04:00
return;
2015-02-13 17:06:03 -05:00
}
2014-10-28 18:12:44 -04:00
2015-02-13 17:06:03 -05:00
$intro_text = apply_filters( 'display_featured_image_genesis_cpt_description', genesis_get_cpt_option( 'intro_text' ) );
2014-10-28 18:12:44 -04:00
2015-02-13 17:06:03 -05:00
if ( $intro_text ) {
2016-01-28 11:00:09 -05:00
$class = 'archive-description cpt-archive-description';
$this->print_description( $intro_text, $class );
2015-02-13 17:06:03 -05:00
}
2014-10-28 18:12:44 -04:00
}
2015-09-01 20:34:25 -04:00
/**
* Filter to show title on front page.
* @return boolean true/false
*
* @since 2.3.0
*/
public function show_front_page_title() {
$show_front_title = apply_filters( 'display_featured_image_genesis_excerpt_show_front_page_title', false );
return true === $show_front_title ? true : false;
}
2015-09-06 16:45:43 -04:00
/**
* Get the front or posts page title.
* @param string $title front page or posts page title
* @return string Site title, or page title
*
2015-09-08 13:40:07 -04:00
* @since 2.3.3
2015-09-06 16:45:43 -04:00
*/
protected function get_front_blog_title( $title = '' ) {
$frontpage = get_option( 'show_on_front' );
if ( $this->show_front_page_title() && is_front_page() ) {
$title = get_the_title();
if ( is_home() ) {
$title = get_bloginfo( 'title' );
}
} elseif ( is_home() && 'page' === $frontpage ) {
$postspage = get_post( get_option( 'page_for_posts' ) );
$title = $postspage->post_title;
}
return apply_filters( 'display_featured_image_genesis_front_blog_title', $title );
}
/**
* Get the front page excerpt, or site description, or posts page excerpt
* @param string $intro_text excerpt or archive-description
* @return string site description or excerpt
*
2015-09-08 13:40:07 -04:00
* @since 2.3.3
2015-09-06 16:45:43 -04:00
*/
protected function get_front_blog_intro_text( $intro_text = '' ) {
$frontpage = get_option( 'show_on_front' );
$intro_text = get_bloginfo( 'description' );
if ( is_front_page() && is_singular() && has_excerpt() ) {
$intro_text = get_the_excerpt();
} elseif ( is_home() && 'page' === $frontpage ) {
$postspage = get_post( get_option( 'page_for_posts' ) );
$intro_text = empty( $postspage->post_excerpt ) ? '' : $postspage->post_excerpt;
}
return apply_filters( 'display_featured_image_genesis_front_blog_description', $intro_text );
}
2016-01-28 11:00:09 -05:00
/**
* Actually print the description for the archive page. Adds hooks for moving output.
2017-12-27 15:17:30 -05:00
*
* @param $intro_text string the archive intro text.
2016-01-28 11:00:09 -05:00
* @param string $class optional class for the div.
*
2017-12-27 15:17:30 -05:00
* @param string $context
*
2016-04-04 15:50:04 -04:00
* @since 2.5.0
2016-01-28 11:00:09 -05:00
*/
2016-02-20 15:45:23 -05:00
protected function print_description( $intro_text, $class = '', $context = 'archive_intro' ) {
2016-04-04 15:50:04 -04:00
printf( '<div class="%s">', esc_html( $class ) );
2016-02-20 15:45:23 -05:00
do_action( "displayfeaturedimagegenesis_before_{$context}" );
2016-01-28 11:00:09 -05:00
echo wp_kses_post( wpautop( $intro_text ) );
2016-02-20 15:45:23 -05:00
do_action( "displayfeaturedimagegenesis_after_{$context}" );
2016-01-28 11:00:09 -05:00
echo '</div>';
}
2014-10-28 18:12:44 -04:00
}