| | 4446 | |
| | 4447 | /** |
| | 4448 | * Checks to see if more than one term of a given taxonomy has associated posts. |
| | 4449 | * |
| | 4450 | * @since 4.7.0 |
| | 4451 | * |
| | 4452 | * @param string $taxonomy Taxonomy name. |
| | 4453 | * @return bool Whether or not we have more than one term of the given taxonomy. |
| | 4454 | */ |
| | 4455 | function is_multi_taxonomy( $taxonomy ) { |
| | 4456 | if ( false === ( $is_multi_taxonomy = get_transient( 'is_multi_taxonomy_' . $taxonomy ) ) ) { |
| | 4457 | $is_multi_taxonomy = get_terms( array( |
| | 4458 | 'taxonomy' => $taxonomy, |
| | 4459 | 'fields' => 'count', |
| | 4460 | 'number' => 2, |
| | 4461 | ) ); |
| | 4462 | $is_multi_taxonomy = $is_multi_taxonomy > 1 ? 1 : 0; |
| | 4463 | set_transient( 'is_multi_taxonomy_' . $taxonomy, $is_multi_taxonomy ); |
| | 4464 | } |
| | 4465 | |
| | 4466 | /** |
| | 4467 | * Filters whether the site has more than one term of the given taxonomy with associated posts. |
| | 4468 | * |
| | 4469 | * @since 4.7.0 |
| | 4470 | * |
| | 4471 | * @param bool $is_multi_taxonomy Whether $is_multi_taxonomy should evaluate as true. |
| | 4472 | * @param string $taxonomy Taxonomy name. |
| | 4473 | */ |
| | 4474 | return apply_filters( 'is_multi_taxonomy', (bool) $is_multi_taxonomy, $taxonomy ); |
| | 4475 | } |
| | 4476 | |
| | 4477 | /** |
| | 4478 | * Helper function to clear the cache for a number of taxonomy terms. |
| | 4479 | * |
| | 4480 | * @since 4.7.0 |
| | 4481 | * @access private |
| | 4482 | * |
| | 4483 | * @param string|array $taxonomies One or more taxonomy names. |
| | 4484 | */ |
| | 4485 | function _clear_multi_taxonomy_cache( $taxonomies ) { |
| | 4486 | $taxonomies = (array) $taxonomies; |
| | 4487 | |
| | 4488 | foreach ( $taxonomies as $taxonomy ) { |
| | 4489 | delete_transient( 'is_multi_taxonomy_' . $taxonomy ); |
| | 4490 | } |
| | 4491 | } |
| | 4492 | |
| | 4493 | /** |
| | 4494 | * Helper function to clear the $is_multi_taxonomy cache for a term. |
| | 4495 | * |
| | 4496 | * @since 4.7.0 |
| | 4497 | * @access private |
| | 4498 | * |
| | 4499 | * @param int $term_id Term ID. |
| | 4500 | * @param int $tt_id Term taxonomy ID. |
| | 4501 | * @param string $taxonomy Taxonomy name. |
| | 4502 | */ |
| | 4503 | function _clear_multi_taxonomy_cache_for_term( $term_id, $tt_id, $taxonomy ) { |
| | 4504 | _clear_multi_taxonomy_cache( $taxonomy ); |
| | 4505 | } |
| | 4506 | |
| | 4507 | /** |
| | 4508 | * Helper function to clear the $is_multi_taxonomy cache for a post. |
| | 4509 | * |
| | 4510 | * @since 4.7.0 |
| | 4511 | * @access private |
| | 4512 | * |
| | 4513 | * @param int $post_id Post ID. |
| | 4514 | */ |
| | 4515 | function _clear_multi_taxonomy_cache_for_post( $post_id ) { |
| | 4516 | _clear_multi_taxonomy_cache( get_object_taxonomies( get_post( $post_id ) ) ); |
| | 4517 | } |