Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add filters to category/tag badges #745

Merged
merged 13 commits into from
Apr 17, 2024
2 changes: 1 addition & 1 deletion footer.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
</footer>

<!-- To top button -->
<a href="#" class="<?= apply_filters('bootscore/class/footer/to_top_button', 'btn btn-primary shadow'); ?> position-fixed z-1 top-button"><i class="fa-solid fa-chevron-up"></i><span class="visually-hidden-focusable">To top</span></a>
<a href="#" class="<?= apply_filters('bootscore/class/footer/to_top_button', 'btn btn-primary shadow'); ?> position-fixed z-2 top-button"><i class="fa-solid fa-chevron-up"></i><span class="visually-hidden-focusable">To top</span></a>

</div><!-- #page -->

Expand Down
39 changes: 28 additions & 11 deletions inc/template-tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Eventually, some of the functionality here could be replaced by core features.
*
* @package Bootscore
* @version 5.3.3
* @version 6.0.0
*/


Expand All @@ -26,7 +26,9 @@ function bootscore_category_badge() {
$i = 0;
foreach (get_the_category() as $category) {
if (0 < $i) $thelist .= ' ';
$thelist .= '<a href="' . esc_url(get_category_link($category->term_id)) . '" class="badge bg-primary-subtle text-primary-emphasis text-decoration-none">' . $category->name . '</a>';
// Apply a filter to modify the class name
$class = apply_filters('bootscore/class/badge/category', 'badge bg-primary-subtle text-primary-emphasis text-decoration-none');
$thelist .= '<a href="' . esc_url(get_category_link($category->term_id)) . '" class="' . esc_attr($class) . '">' . $category->name . '</a>';
$i ++;
}
echo $thelist;
Expand Down Expand Up @@ -58,13 +60,23 @@ function bootscore_category() {
* Date
*/
if (!function_exists('bootscore_date')) :

/**
* Prints HTML with meta information for the current post-date/time.
*/
function bootscore_date() {
$time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';

// Check if modified time is different from the published time
if (get_the_time('U') !== get_the_modified_time('U')) {
$time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time> <span class="time-updated-separator">/</span> <time class="updated" datetime="%3$s">%4$s</time>';
$show_updated_time = apply_filters('bootscore/meta/time/updated', true);

// If filter returns false, don't display modified time
if (!$show_updated_time) {
$time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time>';
} else {
$time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time> <span class="time-updated-separator">/</span> <time class="updated" datetime="%3$s">%4$s</time>';
}
}

$time_string = sprintf(
Expand All @@ -76,7 +88,7 @@ function bootscore_date() {
);

$posted_on = sprintf(
/* translators: %s: post date. */
/* translators: %s: post date. */
'%s',
'<span rel="bookmark">' . $time_string . '</span>'
);
Expand All @@ -90,9 +102,16 @@ function bootscore_date() {
/**
* Author
*/
if (!function_exists('bootscore_author')) :
if (!function_exists('bootscore_author')) {

function bootscore_author() {
$display_author = apply_filters('bootscore/meta/author', true);

// Check if the filter returns false, if so, return early without displaying the author
if (!$display_author) {
return;
}

$byline = sprintf(
esc_html_x('by %s', 'post author', 'bootscore'),
'<span class="author vcard"><a class="url fn n" href="' . esc_url(get_author_posts_url(get_the_author_meta('ID'))) . '">' . esc_html(get_the_author()) . '</a></span>'
Expand All @@ -101,7 +120,7 @@ function bootscore_author() {
echo '<span class="byline"> ' . $byline . '</span>'; // WPCS: XSS OK.

}
endif;
}


/**
Expand Down Expand Up @@ -197,13 +216,10 @@ function bootscore_tags() {
// Hide category and tag text for pages.
if ('post' === get_post_type()) {


/* translators: used between list items, there is a space after the comma */
$tags_list = get_the_tag_list('', ' ');
if ($tags_list) {
/* translators: 1: list of tags. */
echo '<div class="tags-links">';
echo '<p class="tags-heading mb-2">' . esc_html__('Tagged', 'bootscore') . '</p>';
echo '<p class="tags-heading h6">' . esc_html__('Tagged', 'bootscore') . '</p>';
echo get_the_tag_list();
echo '</div>';
}
Expand All @@ -213,7 +229,8 @@ function bootscore_tags() {
add_filter("term_links-post_tag", 'add_tag_class');

function add_tag_class($links) {
return str_replace('<a href="', '<a class="badge bg-primary-subtle text-primary-emphasis text-decoration-none me-1" href="', $links);
$class = apply_filters('bootscore/class/badge/tag', 'badge bg-primary-subtle text-primary-emphasis text-decoration-none');
return str_replace('</a>', '</a> ', str_replace('<a href="', '<a class="' . $class . '" href="', $links));
}
endif;

Expand Down
4 changes: 2 additions & 2 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,9 @@
<?php endwhile; ?>
<?php endif; ?>

<footer class="entry-footer">
<div class="entry-footer">
<?php bootscore_pagination(); ?>
</footer>
</div>

</div>
<!-- col -->
Expand Down
4 changes: 2 additions & 2 deletions woocommerce/cart/mini-cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@
$stock_quantity = $_product->get_stock_quantity();
// Check if the product is sold individually
if ($_product->is_sold_individually()) {
echo '<div class="cart-badge my-1"><span class="badge bg-danger">' . esc_html__('Sold individually', 'woocommerce') . '</span></div>';
echo '<div class="cart-badge mb-2"><span class="badge bg-danger">' . esc_html__('Sold individually', 'woocommerce') . '</span></div>';
}

// Check if the product has only 5 or fewer left in stock
elseif ($stock_quantity <= 5 && $stock_quantity > 0) {
$stock_message = sprintf(esc_html__('Only %s left in stock', 'woocommerce'), $stock_quantity);
echo '<div class="cart-badge my-1"><span class="badge bg-danger">' . $stock_message . '</span></div>';
echo '<div class="cart-badge mb-2"><span class="badge bg-danger">' . $stock_message . '</span></div>';
}
?>

Expand Down
5 changes: 1 addition & 4 deletions woocommerce/content-product-cat.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@
exit;
}
?>
<div <?php wc_product_cat_class('col-md-6 col-lg-4 col-xxl-3', $category); ?>>

<div <?php wc_product_cat_class(apply_filters('bootscore/class/woocommerce/col', 'col-md-6 col-lg-4 col-xxl-3'), $category); ?>>
<div class="card h-100">

<?php
/**
* The woocommerce_before_subcategory hook.
Expand Down Expand Up @@ -64,5 +62,4 @@
?>
</div>
</div>

</div>
2 changes: 1 addition & 1 deletion woocommerce/content-product.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
}
?>

<div class="<?= apply_filters('bootscore/class/product_col', 'col-md-6 col-lg-4 col-xxl-3'); ?>">
<div class="<?= apply_filters('bootscore/class/woocommerce/col', 'col-md-6 col-lg-4 col-xxl-3'); ?>">
<div <?php wc_product_class('card h-100 d-flex text-center', $product); ?>>
<?php
/**
Expand Down