get_the_ID(), 'show_count' => true, 'class' => '', ], $atts, $tag); $post_id = (int) $a['post_id']; if (!$post_id) { return ''; } $on = Store::has(get_current_user_id(), $post_id, $type); $count = Store::count($post_id, $type); $label = $type === 'like' ? ($on ? __('Unlike', 'aumframe') : __('Like', 'aumframe')) : ($on ? __('Remove from favorites', 'aumframe') : __('Add to favorites', 'aumframe')); $icon = self::icon($type === 'like' ? 'heart' : 'star', $on); $html = '
'; return $html; } /** * @param string $name `heart` * @param bool $on */ private static function icon(string $name, bool $on): string { $key = $on ? $name . '-fill' : $name; /** * @param string $svg * @param string $key */ $themed = (string) apply_filters('aumframe/icon', '', $key); if (trim($themed) !== '') { return $themed; } $paths = [ 'heart' => 'M12 21s-7.5-4.6-9.5-9A5.2 5.2 0 0 1 12 6.7 5.2 5.2 0 0 1 21.5 12c-2 4.4-9.5 9-9.5 9Z', 'star' => 'm12 3.6 2.6 5.3 5.9.9-4.3 4.1 1 5.8-5.2-2.7-5.2 2.7 1-5.8L3.5 9.8l5.9-.9L12 3.6Z', ]; $d = $paths[$name] ?? $paths['heart']; return ''; } /** 1200 -> 1.2K. */ private static function format(int $n): string { if ($n >= 1000000) { return rtrim(rtrim(number_format($n / 1000000, 1), '0'), '.') . 'M'; } if ($n >= 1000) { return rtrim(rtrim(number_format($n / 1000, 1), '0'), '.') . 'K'; } return (string) $n; } }