Apiki /
wpsteak
| 1 | <?php declare(strict_types = 1); |
||
| 2 | |||
| 3 | namespace WPSteak\Repositories; |
||
| 4 | |||
| 5 | /** @codeCoverageIgnore */ |
||
| 6 | abstract class Term { |
||
| 7 | |||
| 8 | /** @param \WP_Term|int $term Id. */ |
||
| 9 | protected function get_term( $term ): ?\WP_Term { |
||
| 10 | if ( $term instanceof \WP_Term ) { |
||
| 11 | return $term; |
||
| 12 | } |
||
| 13 | |||
| 14 | $result = get_term( $term ); |
||
| 15 | |||
| 16 | if ( ! $result instanceof \WP_Term ) { |
||
| 17 | return null; |
||
| 18 | } |
||
| 19 | |||
| 20 | return $result; |
||
| 21 | } |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @param array<string> $args Args. |
||
| 25 | * @return array<\WP_Term> |
||
| 26 | * @throws \InvalidArgumentException When the passed taxonomy does not exists. |
||
| 27 | */ |
||
| 28 | protected function get_terms( array $args ): array { |
||
| 29 | $terms = get_terms( $args ); |
||
| 30 | |||
| 31 | if ( ! is_array( $terms ) ) { |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 32 | throw new \InvalidArgumentException( __( 'Taxonomia não existe.', 'wpsteak' ) ); |
||
| 33 | } |
||
| 34 | |||
| 35 | return $terms; |
||
| 36 | } |
||
| 37 | |||
| 38 | } |
||
| 39 |