| @@ -1,5 +1,10 @@ | ||
| 1 | 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 | +} | |
| 2 | 7 | if ( ! $show_count ) { |
| 3 | 8 | return; |
| 4 | 9 | } |
| 5 | 10 | |
| @@ -17,8 +22,14 @@ | ||
| 17 | 22 | $suffix = apply_filters( 'betterdocs_category_items_counts_suffix', $suffix, get_defined_vars() ); |
| 18 | 23 | $suffix_singular = apply_filters( 'betterdocs_category_items_counts_suffix_singular', $suffix_singular, get_defined_vars() ); |
| 19 | 24 | $subcategory_singular_text = isset( $subcategory_text ) ? $subcategory_text : __( 'Sub Category', 'betterdocs' ); // Default singular subcategory text. |
| 20 | 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; | |
| 21 | 32 | ?> |
| 22 | 33 | |
| 23 | 34 | <div data-count="<?php echo esc_attr( $counts ); ?>" class="betterdocs-sub-category-items-counts"> |
| 24 | 35 | <?php |
| @@ -27,22 +38,27 @@ | ||
| 27 | 38 | if ( $taxonomy === 'knowledge_base' ) { |
| 28 | 39 | /* translators: %s: Number of categories. */ |
| 29 | 40 | echo esc_html( |
| 30 | 41 | sprintf( |
| 31 | - // phpcs:ignore WordPress.WP.I18n.MissingTranslatorsComment, WordPress.WP.I18n.MismatchedPlaceholders | |
| 32 | - _n( '%s Category', '%s Categories', $sub_terms_count, 'betterdocs' ), | |
| 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 | + ), | |
| 33 | 49 | number_format_i18n( $sub_terms_count ) |
| 34 | 50 | ) |
| 35 | - ); | |
| 51 | + ); | |
| 36 | 52 | } else { |
| 37 | - /* translators: %1$s: Number of items, %2$s: Singular text, %3$s: Plural text. */ | |
| 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. | |
| 38 | 56 | echo esc_html( |
| 39 | 57 | sprintf( |
| 40 | - // phpcs:ignore WordPress.WP.I18n.MissingTranslatorsComment, WordPress.WP.I18n.MismatchedPlaceholders | |
| 41 | - _n( '%1$s %2$s', '%1$s %3$s', $sub_terms_count, 'betterdocs' ), | |
| 58 | + '%1$s %2$s', | |
| 42 | 59 | esc_html( $sub_terms_count ), |
| 43 | - esc_html( $subcategory_singular_text ), | |
| 44 | - esc_html( $subcategory_plural_text ) | |
| 60 | + esc_html( $sub_terms_count === 1 ? $subcategory_singular_text : $subcategory_plural_text ) | |
| 45 | 61 | ) |
| 46 | 62 | ); |
| 47 | 63 | } |
| 48 | 64 | echo '</span> <span>|</span>'; |
| @@ -49,17 +65,17 @@ | ||
| 49 | 65 | } |
| 50 | 66 | ?> |
| 51 | 67 | <span> |
| 52 | 68 | <?php |
| 53 | - /* translators: %1$s: Number of items, %2$s: Prefix text, %3$s: Singular suffix, %4$s: Plural suffix. */ | |
| 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. | |
| 54 | 72 | echo esc_html( |
| 55 | 73 | sprintf( |
| 56 | - // phpcs:ignore WordPress.WP.I18n.MissingTranslatorsComment, WordPress.WP.I18n.MismatchedPlaceholders | |
| 57 | - _n( '%2$s %1$s %3$s', '%2$s %1$s %4$s', $counts, 'betterdocs' ), | |
| 74 | + '%2$s %1$s %3$s', | |
| 58 | 75 | esc_html( $counts ), |
| 59 | 76 | esc_html( $prefix ), |
| 60 | - esc_html( $suffix_singular ), | |
| 61 | - esc_html( $suffix ) | |
| 77 | + esc_html( $counts === 1 ? $suffix_singular : $suffix ) | |
| 62 | 78 | ) |
| 63 | 79 | ); |
| 64 | 80 | ?> |
| 65 | 81 | </span> |