Move description/intro related functions to description class

This commit is contained in:
Robin Cornett
2019-05-17 18:01:50 -04:00
parent 64a5885853
commit 8ed9cdb9a1
2 changed files with 61 additions and 96 deletions
@@ -9,26 +9,69 @@
class Display_Featured_Image_Genesis_Description {
/**
* Remove Genesis titles/descriptions
* @since 2.3.1
*/
public function remove_title_descriptions() {
if ( is_singular() && ! is_page_template( 'page_blog.php' ) ) {
remove_action( 'genesis_entry_header', 'genesis_do_post_title' ); // HTML5
remove_action( 'genesis_post_title', 'genesis_do_post_title' ); // XHTML
if ( ! post_type_supports( get_post_type( get_the_ID() ), 'genesis-entry-meta-before-content' ) && apply_filters( 'displayfeaturedimagegenesis_remove_entry_header', true ) ) {
remove_action( 'genesis_entry_header', 'genesis_entry_header_markup_open', 5 );
remove_action( 'genesis_entry_header', 'genesis_entry_header_markup_close', 15 );
}
}
remove_action( 'genesis_before_loop', 'genesis_do_taxonomy_title_description', 15 );
remove_action( 'genesis_before_loop', 'genesis_do_author_title_description', 15 );
remove_action( 'genesis_before_loop', 'genesis_do_cpt_archive_title_description' );
remove_action( 'genesis_before_loop', 'genesis_do_blog_template_heading' );
remove_action( 'genesis_before_loop', 'genesis_do_posts_page_heading' );
}
/**
* Do title and description together (for excerpt output)
*
* @since 2.3.1
*/
public function do_title_descriptions() {
$this->do_front_blog_excerpt();
$this->do_excerpt();
genesis_do_taxonomy_title_description();
genesis_do_author_title_description();
genesis_do_cpt_archive_title_description();
}
/**
* Separate archive titles from descriptions. Titles show in leader image
* area; descriptions show before loop.
*
* @since 1.3.0
*
*/
public function add_descriptions() {
$this->do_tax_description();
$this->do_author_description();
$this->do_cpt_archive_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.
* 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 = '';
$headline = '';
$intro_text = '';
$itemprop = '';
if ( genesis_html5() ) {
$itemprop = ' itemprop="headline"';
}
@@ -42,7 +85,7 @@ class Display_Featured_Image_Genesis_Description {
$intro_text = apply_filters( 'display_featured_image_genesis_singular_description', get_the_excerpt() );
}
if ( $headline || $intro_text ) {
$print = $headline . wpautop( $intro_text );
$print = $headline . $intro_text;
$class = 'excerpt';
$this->print_description( $print, $class, $class );
}
@@ -50,17 +93,12 @@ class Display_Featured_Image_Genesis_Description {
/**
* 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.
*/
public function do_front_blog_excerpt() {
if ( ! is_front_page() && ! is_home() ) {
return;
}
@@ -70,9 +108,8 @@ class Display_Featured_Image_Genesis_Description {
$itemprop = genesis_html5() ? ' itemprop="headline"' : '';
$headline = empty( $title ) ? '' : sprintf( '<h1 class="entry-title"%s>%s</h1>', $itemprop, $title );
$intro_text = $this->get_front_blog_intro_text();
if ( $headline || $intro_text ) {
$print = $headline . wpautop( $intro_text );
$print = $headline . $intro_text;
$class = 'excerpt';
$this->print_description( $print, $class, $class );
}
@@ -80,27 +117,21 @@ class Display_Featured_Image_Genesis_Description {
/**
* 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.
*/
public function do_tax_description() {
global $wp_query;
if ( ! is_category() && ! is_tag() && ! is_tax() ) {
return;
}
global $wp_query;
$term = is_tax() ? get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ) : $wp_query->get_queried_object();
if ( ! $term ) {
@@ -109,74 +140,55 @@ class Display_Featured_Image_Genesis_Description {
$intro_text = displayfeaturedimagegenesis_get_term_meta( $term, 'intro_text' );
$intro_text = apply_filters( 'display_featured_image_genesis_term_description', $intro_text );
if ( $intro_text ) {
$class = 'archive-description taxonomy-description';
$this->print_description( $intro_text, $class );
}
}
/**
* 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.
*/
public function do_author_description() {
if ( ! is_author() || get_query_var( 'paged' ) >= 2 ) {
return;
}
$intro_text = apply_filters( 'display_featured_image_genesis_author_description', get_the_author_meta( 'intro_text', (int) get_query_var( 'author' ) ) );
if ( $intro_text ) {
$class = 'archive-description author-description';
$this->print_description( $intro_text, $class );
}
}
/**
* 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.
*/
public function do_cpt_archive_description() {
if ( ! is_post_type_archive() || ! genesis_has_post_type_archive_support() ) {
return;
}
$intro_text = apply_filters( 'display_featured_image_genesis_cpt_description', genesis_get_cpt_option( 'intro_text' ) );
if ( $intro_text ) {
$class = 'archive-description cpt-archive-description';
$this->print_description( $intro_text, $class );
}
}
/**
@@ -186,10 +198,9 @@ class Display_Featured_Image_Genesis_Description {
* @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;
return true === $show_front_title ? true : false;
}
/**
@@ -210,6 +221,7 @@ class Display_Featured_Image_Genesis_Description {
$postspage = get_post( get_option( 'page_for_posts' ) );
$title = $postspage->post_title;
}
return apply_filters( 'display_featured_image_genesis_front_blog_title', $title );
}
@@ -229,6 +241,7 @@ class Display_Featured_Image_Genesis_Description {
$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 );
}
@@ -115,8 +115,9 @@ class Display_Featured_Image_Genesis_Output {
* @since 1.0.0
*/
public function do_backstretch_image_title() {
$description = $this->get_description_class();
if ( $this->move_title() ) {
$this->remove_title_descriptions();
$description->remove_title_descriptions();
}
$class = 'big-leader';
@@ -136,13 +137,13 @@ class Display_Featured_Image_Genesis_Output {
if ( $this->move_title() ) {
if ( $this->move_excerpts() ) {
$this->do_title_descriptions();
$description->do_title_descriptions();
} else {
$item = $this->get_item();
if ( ! empty( $item->title ) && $this->do_the_title() ) {
echo $this->do_the_title();
}
add_action( 'genesis_before_loop', array( $this, 'add_descriptions' ) );
add_action( 'genesis_before_loop', array( $description, 'add_descriptions' ) );
}
}
@@ -248,55 +249,6 @@ class Display_Featured_Image_Genesis_Output {
return apply_filters( 'display_featured_image_genesis_modify_title_overlay', $title_output, esc_attr( $class ), esc_attr( $itemprop ), $title );
}
/**
* Separate archive titles from descriptions. Titles show in leader image
* area; descriptions show before loop.
*
* @since 1.3.0
*
*/
public function add_descriptions() {
$description = $this->get_description_class();
$description->do_tax_description();
$description->do_author_description();
$description->do_cpt_archive_description();
}
/**
* Do title and description together (for excerpt output)
*
* @since 2.3.1
*/
protected function do_title_descriptions() {
$description = $this->get_description_class();
$description->do_front_blog_excerpt();
$description->do_excerpt();
genesis_do_taxonomy_title_description();
genesis_do_author_title_description();
genesis_do_cpt_archive_title_description();
}
/**
* Remove Genesis titles/descriptions
* @since 2.3.1
*/
protected function remove_title_descriptions() {
if ( is_singular() && ! is_page_template( 'page_blog.php' ) ) {
remove_action( 'genesis_entry_header', 'genesis_do_post_title' ); // HTML5
remove_action( 'genesis_post_title', 'genesis_do_post_title' ); // XHTML
if ( ! post_type_supports( get_post_type( get_the_ID() ), 'genesis-entry-meta-before-content' ) && apply_filters( 'displayfeaturedimagegenesis_remove_entry_header', true ) ) {
remove_action( 'genesis_entry_header', 'genesis_entry_header_markup_open', 5 );
remove_action( 'genesis_entry_header', 'genesis_entry_header_markup_close', 15 );
}
}
remove_action( 'genesis_before_loop', 'genesis_do_taxonomy_title_description', 15 );
remove_action( 'genesis_before_loop', 'genesis_do_author_title_description', 15 );
remove_action( 'genesis_before_loop', 'genesis_do_cpt_archive_title_description' );
remove_action( 'genesis_before_loop', 'genesis_do_blog_template_heading' );
remove_action( 'genesis_before_loop', 'genesis_do_posts_page_heading' );
}
/**
* Check plugin settings/filters to see if the featured image should output on this post/etc. at all.
* Returns true to quit now; false to carry on.