| @@ -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 |
| @@ -38,18 +49,14 @@ | ||
| 38 | 49 | number_format_i18n( $sub_terms_count ) |
| 39 | 50 | ) |
| 40 | 51 | ); |
| 41 | 52 | } else { |
| 42 | - /* 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. | |
| 43 | 56 | echo esc_html( |
| 44 | 57 | sprintf( |
| 45 | - // phpcs:ignore WordPress.WP.I18n.MissingTranslatorsComment, WordPress.WP.I18n.MismatchedPlaceholders | |
| 46 | - _n( | |
| 47 | - '%1$s %2$s', | |
| 48 | - '%1$s %2$s', | |
| 49 | - $sub_terms_count, | |
| 50 | - 'betterdocs' | |
| 51 | - ), | |
| 58 | + '%1$s %2$s', | |
| 52 | 59 | esc_html( $sub_terms_count ), |
| 53 | 60 | esc_html( $sub_terms_count === 1 ? $subcategory_singular_text : $subcategory_plural_text ) |
| 54 | 61 | ) |
| 55 | 62 | ); |
| @@ -58,18 +65,14 @@ | ||
| 58 | 65 | } |
| 59 | 66 | ?> |
| 60 | 67 | <span> |
| 61 | 68 | <?php |
| 62 | - /* 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. | |
| 63 | 72 | echo esc_html( |
| 64 | 73 | sprintf( |
| 65 | - // phpcs:ignore WordPress.WP.I18n.MissingTranslatorsComment, WordPress.WP.I18n.MismatchedPlaceholders | |
| 66 | - _n( | |
| 67 | - '%2$s %1$s %3$s', | |
| 68 | - '%2$s %1$s %3$s', | |
| 69 | - $counts, | |
| 70 | - 'betterdocs' | |
| 71 | - ), | |
| 74 | + '%2$s %1$s %3$s', | |
| 72 | 75 | esc_html( $counts ), |
| 73 | 76 | esc_html( $prefix ), |
| 74 | 77 | esc_html( $counts === 1 ? $suffix_singular : $suffix ) |
| 75 | 78 | ) |