Add pluggable function wrappers to inc/template-tags.php

This commit is contained in:
Alex Wright 2018-03-30 10:14:25 -05:00
parent eda69c0385
commit c75682937e
1 changed files with 82 additions and 74 deletions

View File

@ -7,10 +7,11 @@
* @package understrap
*/
if ( ! function_exists( 'understrap_posted_on' ) ) :
/**
* Prints HTML with meta information for the current post-date/time and author.
*/
if ( ! function_exists ( 'understrap_posted_on' ) ) {
function understrap_posted_on() {
$time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
@ -32,12 +33,13 @@ function understrap_posted_on() {
);
echo '<span class="posted-on">' . $posted_on . '</span><span class="byline"> ' . $byline . '</span>'; // WPCS: XSS OK.
}
endif;
}
if ( ! function_exists( 'understrap_entry_footer' ) ) :
/**
* Prints HTML with meta information for the categories, tags and comments.
*/
if ( ! function_exists ( 'understrap_entry_footer' ) ) {
function understrap_entry_footer() {
// Hide category and tag text for pages.
if ( 'post' === get_post_type() ) {
@ -67,13 +69,15 @@ function understrap_entry_footer() {
'</span>'
);
}
endif;
}
/**
* Returns true if a blog has more than 1 category.
*
* @return bool
*/
if ( ! function_exists ( 'understrap_categorized_blog' ) ) {
function understrap_categorized_blog() {
if ( false === ( $all_the_cool_cats = get_transient( 'understrap_categories' ) ) ) {
// Create an array of all the categories that are attached to posts.
@ -95,10 +99,16 @@ function understrap_categorized_blog() {
return false;
}
}
}
/**
* Flush out the transients used in understrap_categorized_blog.
*/
add_action( 'edit_category', 'understrap_category_transient_flusher' );
add_action( 'save_post', 'understrap_category_transient_flusher' );
if ( ! function_exists ( 'understrap_category_transient_flusher' ) ) {
function understrap_category_transient_flusher() {
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return;
@ -106,6 +116,4 @@ function understrap_category_transient_flusher() {
// Like, beat it. Dig?
delete_transient( 'understrap_categories' );
}
add_action( 'edit_category', 'understrap_category_transient_flusher' );
add_action( 'save_post', 'understrap_category_transient_flusher' );
}