| @@ -27,9 +27,9 @@ | ||
| 27 | 27 | 'span', |
| 28 | 28 | ]; |
| 29 | 29 | |
| 30 | 30 | public static function get_site_domain() { |
| 31 | - return str_ireplace( 'www.', '', parse_url( home_url(), PHP_URL_HOST ) ); | |
| 31 | + return str_ireplace( 'www.', '', wp_parse_url( home_url(), PHP_URL_HOST ) ); | |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | public static function readable_num( $size ) { |
| 35 | 35 | $l = substr( $size, -1 ); |
| @@ -55,14 +55,18 @@ | ||
| 55 | 55 | * Validate an HTML tag against a safe allowed list. |
| 56 | 56 | * @param string $tag |
| 57 | 57 | * @return string |
| 58 | 58 | */ |
| 59 | - public static function get_valid_html_tag( $tag ) { | |
| 60 | - return in_array( strtolower( $tag ), self::ALLOWED_HTML_WRAPPER_TAGS ) ? $tag : 'div'; | |
| 59 | + public static function get_valid_html_tag( $tag ) { | |
| 60 | + if ( ! is_scalar( $tag ) ) { | |
| 61 | + return 'div'; | |
| 62 | + } | |
| 63 | + | |
| 64 | + return in_array( strtolower( (string) $tag ), self::ALLOWED_HTML_WRAPPER_TAGS ) ? $tag : 'div'; | |
| 61 | 65 | } |
| 62 | 66 | |
| 63 | - public static function print_valid_html_tag( $tag ) { | |
| 64 | - echo in_array( strtolower( $tag ), self::ALLOWED_HTML_WRAPPER_TAGS ) ? $tag : 'div'; | |
| 67 | + public static function print_valid_html_tag( $tag ) { | |
| 68 | + echo esc_attr( self::get_valid_html_tag( $tag ) ); | |
| 65 | 69 | } |
| 66 | 70 | |
| 67 | 71 | /** |
| 68 | 72 | * Get placeholder image source. |
| @@ -151,7 +155,36 @@ | ||
| 151 | 155 | } |
| 152 | 156 | } |
| 153 | 157 | |
| 154 | 158 | return $timezone_string; |
| 159 | + } | |
| 160 | + | |
| 161 | + /** | |
| 162 | + * Build a localized comment count string for front-end display. | |
| 163 | + * | |
| 164 | + * Single translatable pattern so locales can reorder words (e.g. "Comments: %s"). | |
| 165 | + * Always escape with esc_html() (or esc_attr() for attributes) when outputting. | |
| 166 | + * | |
| 167 | + * @param int $post_id Post ID. Use 0 for the current post in The Loop. | |
| 168 | + * @return string Unescaped translated string. | |
| 169 | + */ | |
| 170 | + public static function get_formatted_comments_count( $post_id = 0 ) { | |
| 171 | + $comment_count = (int) get_comments_number( $post_id ); | |
| 172 | + | |
| 173 | + return sprintf( | |
| 174 | + /* translators: %s: number of comments */ | |
| 175 | + _n( '%s comment', '%s comments', $comment_count, 'ultimate-post-kit' ), | |
| 176 | + number_format_i18n( $comment_count ) | |
| 177 | + ); | |
| 178 | + } | |
| 179 | + | |
| 180 | + /** | |
| 181 | + * Localized numeric comment count only (no word label). For icon-only meta. | |
| 182 | + * | |
| 183 | + * @param int $post_id Post ID. Use 0 for the current post in The Loop. | |
| 184 | + * @return string | |
| 185 | + */ | |
| 186 | + public static function get_localized_comment_count( $post_id = 0 ) { | |
| 187 | + return number_format_i18n( (int) get_comments_number( $post_id ) ); | |
| 155 | 188 | } |
| 156 | 189 | |
| 157 | 190 | } |