| 1 |
<?php |
| 2 |
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- view template receives variables via extract(); prefixing is impractical. |
| 3 |
|
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
exit; |
| 6 |
} |
| 7 |
if ( ! $show_count ) { |
| 8 |
return; |
| 9 |
} |
| 10 |
|
| 11 |
$prefix = $suffix = $suffix_singular = ''; |
| 12 |
|
| 13 |
if ( is_array( $counts ) ) { |
| 14 |
$prefix = $counts['prefix']; |
| 15 |
$_count = $counts['counts']; |
| 16 |
$suffix = $counts['suffix']; |
| 17 |
$suffix_singular = $counts['suffix_singular']; |
| 18 |
$counts = $_count; |
| 19 |
} |
| 20 |
|
| 21 |
$prefix = apply_filters( 'betterdocs_category_items_counts_prefix', $prefix, get_defined_vars() ); |
| 22 |
$suffix = apply_filters( 'betterdocs_category_items_counts_suffix', $suffix, get_defined_vars() ); |
| 23 |
$suffix_singular = apply_filters( 'betterdocs_category_items_counts_suffix_singular', $suffix_singular, get_defined_vars() ); |
| 24 |
$subcategory_singular_text = isset( $subcategory_text ) ? $subcategory_text : __( 'Sub Category', 'betterdocs' ); // Default singular subcategory text. |
| 25 |
$subcategory_plural_text = isset( $subcategories_text ) ? $subcategories_text : __( 'Sub Categories', 'betterdocs' ); // Default plural subcategory text. |
| 26 |
|
| 27 |
// These are not always supplied by the caller (e.g. TemplateTags::sub_category_counts() |
| 28 |
// only passes show_count + counts). Default them so PHP 8.x does not emit |
| 29 |
// "Undefined variable" warnings; the defaults preserve the existing branch outcomes. |
| 30 |
$taxonomy = isset( $taxonomy ) ? $taxonomy : ''; |
| 31 |
$sub_terms_count = isset( $sub_terms_count ) ? $sub_terms_count : 0; |
| 32 |
?> |
| 33 |
|
| 34 |
<div data-count="<?php echo esc_attr( $counts ); ?>" class="betterdocs-sub-category-items-counts"> |
| 35 |
<?php |
| 36 |
if ( $sub_terms_count > 0 ) { |
| 37 |
echo '<span>'; |
| 38 |
if ( $taxonomy === 'knowledge_base' ) { |
| 39 |
/* translators: %s: Number of categories. */ |
| 40 |
echo esc_html( |
| 41 |
sprintf( |
| 42 |
// phpcs:ignore WordPress.WP.I18n.MissingTranslatorsComment, WordPress.WP.I18n.MismatchedPlaceholders |
| 43 |
_n( |
| 44 |
'%1$s Category', |
| 45 |
'%1$s Categories', |
| 46 |
$sub_terms_count, |
| 47 |
'betterdocs' |
| 48 |
), |
| 49 |
number_format_i18n( $sub_terms_count ) |
| 50 |
) |
| 51 |
); |
| 52 |
} else { |
| 53 |
// Layout-only format string — not wrapped in _n() because it contains |
| 54 |
// nothing but positional placeholders, and translator typos in the |
| 55 |
// placeholder numbers crash sprintf() on PHP 8.x with ArgumentCountError. |
| 56 |
echo esc_html( |
| 57 |
sprintf( |
| 58 |
'%1$s %2$s', |
| 59 |
esc_html( $sub_terms_count ), |
| 60 |
esc_html( $sub_terms_count === 1 ? $subcategory_singular_text : $subcategory_plural_text ) |
| 61 |
) |
| 62 |
); |
| 63 |
} |
| 64 |
echo '</span> <span>|</span>'; |
| 65 |
} |
| 66 |
?> |
| 67 |
<span> |
| 68 |
<?php |
| 69 |
// Layout-only format string — not wrapped in _n() because it contains |
| 70 |
// nothing but positional placeholders, and translator typos in the |
| 71 |
// placeholder numbers crash sprintf() on PHP 8.x with ArgumentCountError. |
| 72 |
echo esc_html( |
| 73 |
sprintf( |
| 74 |
'%2$s %1$s %3$s', |
| 75 |
esc_html( $counts ), |
| 76 |
esc_html( $prefix ), |
| 77 |
esc_html( $counts === 1 ? $suffix_singular : $suffix ) |
| 78 |
) |
| 79 |
); |
| 80 |
?> |
| 81 |
</span> |
| 82 |
</div> |
| 83 |
|