WordPress.org

Make WordPress Core

Ticket #37825: 37825.2.diff

File 37825.2.diff, 3.7 KB (added by sladjanquantox, 16 months ago)
  • src/wp-includes/category.php

     
    333333}
    334334
    335335/**
     336 * Checks to see if more than one category has associated posts.
     337 *
     338 * @since 5.0.0
     339 *
     340 * @return bool Whether or not we have more than one categories.
     341 */
     342function wp_has_multiple_categories() {
     343        return wp_has_multiple_terms( 'category' );
     344}
     345
     346/**
     347 * Checks to see if more than one tag has associated posts.
     348 *
     349 * @since 5.0.0
     350 *
     351 * @return bool Whether or not we have more than one tags.
     352 */
     353function wp_has_multiple_tags() {
     354        return wp_has_multiple_terms( 'post_tag' );
     355}
     356
     357/**
    336358 * Update category structure to old pre 2.3 from new taxonomy structure.
    337359 *
    338360 * This function was added for the taxonomy support to update the new category
  • src/wp-includes/default-filters.php

     
    491491
    492492// Taxonomy
    493493add_action( 'init', 'create_initial_taxonomies', 0 ); // highest priority
     494add_action( 'edit_term', '_clear_multi_taxonomy_cache_for_term', 10, 3 );
     495add_action( 'save_post', '_clear_multi_taxonomy_cache_for_post', 10, 1 );
    494496add_action( 'change_locale', 'create_initial_taxonomies' );
    495497
    496498// Canonical
  • src/wp-includes/taxonomy.php

     
    45154515
    45164516        return $parent;
    45174517}
     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 */
     4527function 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 */
     4557function _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 */
     4575function _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 */
     4587function _clear_multi_taxonomy_cache_for_post( $post_id ) {
     4588        _clear_multi_taxonomy_cache( get_object_taxonomies( get_post( $post_id ) ) );
     4589}