| 1 | <?php |
|---|
| 2 | /** |
|---|
| 3 | * Custom template tags for this theme |
|---|
| 4 | * |
|---|
| 5 | * Eventually, some of the functionality here could be replaced by core features. |
|---|
| 6 | * |
|---|
| 7 | * @package Beauty Cosmetic Store |
|---|
| 8 | */ |
|---|
| 9 | |
|---|
| 10 | if (!function_exists('beauty_cosmetic_store_posted_on')) : |
|---|
| 11 | /** |
|---|
| 12 | * Prints HTML with meta information for the current post-date/time and author. |
|---|
| 13 | */ |
|---|
| 14 | function beauty_cosmetic_store_posted_on(){ |
|---|
| 15 | $beauty_cosmetic_store_time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>'; |
|---|
| 16 | if (get_the_time('U') !== get_the_modified_time('U')) { |
|---|
| 17 | $beauty_cosmetic_store_time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time>'; |
|---|
| 18 | } |
|---|
| 19 | |
|---|
| 20 | $beauty_cosmetic_store_time_string = sprintf($beauty_cosmetic_store_time_string, |
|---|
| 21 | esc_attr(get_the_date('c')), |
|---|
| 22 | esc_html(get_the_date()) |
|---|
| 23 | ); |
|---|
| 24 | |
|---|
| 25 | $posted_on = sprintf( |
|---|
| 26 | /* translators: %s: post date */ |
|---|
| 27 | __( '<span class="screen-reader-text">Posted on</span> %s', 'beauty-cosmetic-store' ), |
|---|
| 28 | '<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . $beauty_cosmetic_store_time_string . '</a>' |
|---|
| 29 | ); |
|---|
| 30 | |
|---|
| 31 | $byline = sprintf( |
|---|
| 32 | /* translators: %s: post author */ |
|---|
| 33 | __( '<span class="screen-reader-text">Posted on</span> %s', 'beauty-cosmetic-store' ), |
|---|
| 34 | '<span class="author vcard"><i class="far fa-user" aria-hidden="true"></i> <a class="url fn n" href="' . esc_url(get_author_posts_url(get_the_author_meta('ID'))) . '">' . esc_html(get_the_author()) . '</a></span>' |
|---|
| 35 | ); |
|---|
| 36 | |
|---|
| 37 | echo '<span class="posted-on">' . $posted_on . '</span> | <span class="byline"> ' . $byline . '</span>'; // WPCS: XSS OK. |
|---|
| 38 | |
|---|
| 39 | if (!is_single() && !post_password_required() && (comments_open() || get_comments_number())) { |
|---|
| 40 | echo ' | <span class="comments-link"><i class="far fa-comments" aria-hidden="true"></i> '; |
|---|
| 41 | /* translators: %s: post title */ |
|---|
| 42 | comments_popup_link(sprintf(wp_kses(__('Leave a Comment<span class="screen-reader-text"> on %s</span>', 'beauty-cosmetic-store'), array('span' => array('class' => array()))), esc_html( get_the_title()))); |
|---|
| 43 | echo '</span>'; |
|---|
| 44 | } |
|---|
| 45 | } |
|---|
| 46 | endif; |
|---|
| 47 | |
|---|
| 48 | /** |
|---|
| 49 | * Returns true if a blog has more than 1 category. |
|---|
| 50 | * |
|---|
| 51 | * @return bool |
|---|
| 52 | */ |
|---|
| 53 | function beauty_cosmetic_store_categorized_blog(){ |
|---|
| 54 | if (false === ($beauty_cosmetic_store_all_the_cool_cats = get_transient('beauty_cosmetic_store_categories'))) { |
|---|
| 55 | // Create an array of all the categories that are attached to posts. |
|---|
| 56 | $beauty_cosmetic_store_all_the_cool_cats = get_categories(array( |
|---|
| 57 | 'fields' => 'ids', |
|---|
| 58 | 'hide_empty' => 1, |
|---|
| 59 | // We only need to know if there is more than one category. |
|---|
| 60 | 'number' => 2, |
|---|
| 61 | )); |
|---|
| 62 | |
|---|
| 63 | // Count the number of categories that are attached to the posts. |
|---|
| 64 | $beauty_cosmetic_store_all_the_cool_cats = count($beauty_cosmetic_store_all_the_cool_cats); |
|---|
| 65 | |
|---|
| 66 | set_transient('beauty_cosmetic_store_categories', $beauty_cosmetic_store_all_the_cool_cats); |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | if ($beauty_cosmetic_store_all_the_cool_cats > 1) { |
|---|
| 70 | // This blog has more than 1 category so beauty_cosmetic_store_categorized_blog should return true. |
|---|
| 71 | return true; |
|---|
| 72 | } else { |
|---|
| 73 | // This blog has only 1 category so beauty_cosmetic_store_categorized_blog should return false. |
|---|
| 74 | return false; |
|---|
| 75 | } |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | /** |
|---|
| 79 | * Flush out the transients used in beauty_cosmetic_store_categorized_blog. |
|---|
| 80 | */ |
|---|
| 81 | function beauty_cosmetic_store_category_transient_flusher(){ |
|---|
| 82 | if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { |
|---|
| 83 | return; |
|---|
| 84 | } |
|---|
| 85 | // Like, beat it. Dig? |
|---|
| 86 | delete_transient('beauty_cosmetic_store_categories'); |
|---|
| 87 | } |
|---|
| 88 | add_action('edit_category', 'beauty_cosmetic_store_category_transient_flusher'); |
|---|
| 89 | add_action('save_post', 'beauty_cosmetic_store_category_transient_flusher'); |
|---|
| 90 | |
|---|
| 91 | if (!function_exists('beauty_cosmetic_store_post_thumbnail')) : |
|---|
| 92 | /** |
|---|
| 93 | * Displays an optional post thumbnail. |
|---|
| 94 | * |
|---|
| 95 | * Wraps the post thumbnail in an anchor element on index views, or a div |
|---|
| 96 | * element when on single views. |
|---|
| 97 | */ |
|---|
| 98 | function beauty_cosmetic_store_post_thumbnail(){ |
|---|
| 99 | if (post_password_required() || is_attachment() || !has_post_thumbnail()) { |
|---|
| 100 | return; |
|---|
| 101 | } |
|---|
| 102 | |
|---|
| 103 | if (is_singular()) : |
|---|
| 104 | ?> |
|---|
| 105 | |
|---|
| 106 | <div class="post-thumbnail"> |
|---|
| 107 | <?php the_post_thumbnail(); ?> |
|---|
| 108 | </div> |
|---|
| 109 | |
|---|
| 110 | <?php else : ?> |
|---|
| 111 | |
|---|
| 112 | <div class="post-thumbnail"> |
|---|
| 113 | <a class="post-thumbnail" href="<?php the_permalink(); ?>" aria-hidden="true" tabindex="-1"> |
|---|
| 114 | <?php |
|---|
| 115 | the_post_thumbnail('post-thumbnail', array( |
|---|
| 116 | 'alt' => the_title_attribute(array( |
|---|
| 117 | 'echo' => false, |
|---|
| 118 | )), |
|---|
| 119 | )); |
|---|
| 120 | ?> |
|---|
| 121 | </a> |
|---|
| 122 | </div> |
|---|
| 123 | |
|---|
| 124 | <?php |
|---|
| 125 | endif; // End is_singular(). |
|---|
| 126 | } |
|---|
| 127 | endif; |
|---|
| 128 | |
|---|
| 129 | if (!function_exists('beauty_cosmetic_store_comment')) : |
|---|
| 130 | /** |
|---|
| 131 | * Template for comments and pingbacks. |
|---|
| 132 | * |
|---|
| 133 | * Used as a callback by wp_list_comments() for displaying the comments. |
|---|
| 134 | */ |
|---|
| 135 | function beauty_cosmetic_store_comment($comment, $args, $depth){ |
|---|
| 136 | |
|---|
| 137 | if ('pingback' == $comment->comment_type || 'trackback' == $comment->comment_type) : ?> |
|---|
| 138 | |
|---|
| 139 | <li id="comment-<?php comment_ID(); ?>" <?php comment_class('media'); ?>> |
|---|
| 140 | <div class="comment-body"> |
|---|
| 141 | <?php esc_html_e('Pingback:', 'beauty-cosmetic-store'); |
|---|
| 142 | comment_author_link(); ?><?php edit_comment_link(__('Edit', 'beauty-cosmetic-store'), '<span class="edit-link">', '</span>'); ?> |
|---|
| 143 | </div> |
|---|
| 144 | |
|---|
| 145 | <?php else : ?> |
|---|
| 146 | |
|---|
| 147 | <li id="comment-<?php comment_ID(); ?>" <?php comment_class(empty($args['has_children']) ? '' : 'parent'); ?>> |
|---|
| 148 | <article id="div-comment-<?php comment_ID(); ?>" class="comment-body media mb-4"> |
|---|
| 149 | <a class="pull-left" href="#"> |
|---|
| 150 | <?php if (0 != $args['avatar_size']) echo get_avatar($comment, $args['avatar_size']); ?> |
|---|
| 151 | </a> |
|---|
| 152 | <div class="media-body"> |
|---|
| 153 | <div class="media-body-wrap card"> |
|---|
| 154 | <div class="card-header"> |
|---|
| 155 | <h5 class="mt-0"><?php /* translators: %s: author */ printf('<cite class="fn">%s</cite>', esc_url( get_comment_author_link() ) ); ?></h5> |
|---|
| 156 | <div class="comment-meta"> |
|---|
| 157 | <a href="<?php echo esc_url(get_comment_link($comment->comment_ID)); ?>"> |
|---|
| 158 | <time datetime="<?php comment_time('c'); ?>"> |
|---|
| 159 | <?php /* translators: %s: Date */ printf( esc_attr('%1$s at %2$s', '1: date, 2: time', 'beauty-cosmetic-store'), esc_attr( get_comment_date() ), esc_attr( get_comment_time() ) ); ?> |
|---|
| 160 | </time> |
|---|
| 161 | </a> |
|---|
| 162 | <?php edit_comment_link( __( 'Edit', 'beauty-cosmetic-store' ), '<span class="edit-link">', '</span>' ); ?> |
|---|
| 163 | </div> |
|---|
| 164 | </div> |
|---|
| 165 | |
|---|
| 166 | <?php if ('0' == $comment->comment_approved) : ?> |
|---|
| 167 | <p class="comment-awaiting-moderation"><?php esc_html_e('Your comment is awaiting moderation.', 'beauty-cosmetic-store'); ?></p> |
|---|
| 168 | <?php endif; ?> |
|---|
| 169 | |
|---|
| 170 | <div class="comment-content card-block"> |
|---|
| 171 | <?php comment_text(); ?> |
|---|
| 172 | </div> |
|---|
| 173 | |
|---|
| 174 | <?php comment_reply_link( |
|---|
| 175 | array_merge( |
|---|
| 176 | $args, array( |
|---|
| 177 | 'add_below' => 'div-comment', |
|---|
| 178 | 'depth' => $depth, |
|---|
| 179 | 'max_depth' => $args['max_depth'], |
|---|
| 180 | 'before' => '<footer class="reply comment-reply card-footer">', |
|---|
| 181 | 'after' => '</footer><!-- .reply -->' |
|---|
| 182 | ) |
|---|
| 183 | ) |
|---|
| 184 | ); ?> |
|---|
| 185 | </div> |
|---|
| 186 | </div> |
|---|
| 187 | </article> |
|---|
| 188 | |
|---|
| 189 | <?php |
|---|
| 190 | endif; |
|---|
| 191 | } |
|---|
| 192 | endif; // ends check for beauty_cosmetic_store_comment() |
|---|