| | 4518 | |
| | 4519 | /** |
| | 4520 | * Checks to see if more than one term of a given taxonomy has associated posts. |
| | 4521 | * |
| | 4522 | * @since 5.0.0 |
| | 4523 | * |
| | 4524 | * @param string $taxonomy Taxonomy name. |
| | 4525 | * @return bool Whether or not we have more than one term of the given taxonomy. |
| | 4526 | */ |
| | 4527 | function wp_has_multiple_terms( $taxonomy ) { |
| | 4528 | if ( false === ( $is_multi_taxonomy = get_transient( 'is_multi_taxonomy_' . $taxonomy ) ) ) { |
| | 4529 | $is_multi_taxonomy = get_terms( array( |
| | 4530 | 'taxonomy' => $taxonomy, |
| | 4531 | 'fields' => 'count', |
| | 4532 | 'number' => 2, |
| | 4533 | ) ); |
| | 4534 | $is_multi_taxonomy = $is_multi_taxonomy > 1 ? 1 : 0; |
| | 4535 | set_transient( 'is_multi_taxonomy_' . $taxonomy, $is_multi_taxonomy ); |
| | 4536 | } |
| | 4537 | |
| | 4538 | /** |
| | 4539 | * Filters whether the site has more than one term of the given taxonomy with associated posts. |
| | 4540 | * |
| | 4541 | * @since 4.7.0 |
| | 4542 | * |
| | 4543 | * @param bool $is_multi_taxonomy Whether $is_multi_taxonomy should evaluate as true. |
| | 4544 | * @param string $taxonomy Taxonomy name. |
| | 4545 | */ |
| | 4546 | return apply_filters( 'is_multi_taxonomy', (bool) $is_multi_taxonomy, $taxonomy ); |
| | 4547 | } |
| | 4548 | |
| | 4549 | /** |
| | 4550 | * Helper function to clear the cache for a number of taxonomy terms. |
| | 4551 | * |
| | 4552 | * @since 5.0.0 |
| | 4553 | * @access private |
| | 4554 | * |
| | 4555 | * @param string|array $taxonomies One or more taxonomy names. |
| | 4556 | */ |
| | 4557 | function _clear_multi_taxonomy_cache( $taxonomies ) { |
| | 4558 | $taxonomies = (array) $taxonomies; |
| | 4559 | |
| | 4560 | foreach ( $taxonomies as $taxonomy ) { |
| | 4561 | delete_transient( 'is_multi_taxonomy_' . $taxonomy ); |
| | 4562 | } |
| | 4563 | } |
| | 4564 | |
| | 4565 | /** |
| | 4566 | * Helper function to clear the $is_multi_taxonomy cache for a term. |
| | 4567 | * |
| | 4568 | * @since 4.7.0 |
| | 4569 | * @access private |
| | 4570 | * |
| | 4571 | * @param int $term_id Term ID. |
| | 4572 | * @param int $tt_id Term taxonomy ID. |
| | 4573 | * @param string $taxonomy Taxonomy name. |
| | 4574 | */ |
| | 4575 | function _clear_multi_taxonomy_cache_for_term( $term_id, $tt_id, $taxonomy ) { |
| | 4576 | _clear_multi_taxonomy_cache( $taxonomy ); |
| | 4577 | } |
| | 4578 | |
| | 4579 | /** |
| | 4580 | * Helper function to clear the $is_multi_taxonomy cache for a post. |
| | 4581 | * |
| | 4582 | * @since 4.7.0 |
| | 4583 | * @access private |
| | 4584 | * |
| | 4585 | * @param int $post_id Post ID. |
| | 4586 | */ |
| | 4587 | function _clear_multi_taxonomy_cache_for_post( $post_id ) { |
| | 4588 | _clear_multi_taxonomy_cache( get_object_taxonomies( get_post( $post_id ) ) ); |
| | 4589 | } |