Slug.php
26 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace AC\Formatter\Term; |
| 6 | |
| 7 | use AC\Exception\ValueNotFoundException; |
| 8 | use AC\Formatter; |
| 9 | use AC\Type\Value; |
| 10 | use WP_Term; |
| 11 | |
| 12 | class Slug implements Formatter |
| 13 | { |
| 14 | |
| 15 | public function format(Value $value) |
| 16 | { |
| 17 | $term = get_term($value->get_id()); |
| 18 | |
| 19 | if ( ! $term instanceof WP_Term) { |
| 20 | throw ValueNotFoundException::from_id($value->get_id()); |
| 21 | } |
| 22 | |
| 23 | return $value->with_value((string)apply_filters('editable_slug', $term->slug, $term)); |
| 24 | } |
| 25 | |
| 26 | } |