Make WordPress Core

Ticket #37825: 37825.diff

File 37825.diff, 3.7 KB (added by flixos90, 9 years ago)
  • src/wp-includes/category.php

     
    319319}
    320320
    321321/**
     322 * Checks to see if more than one category has associated posts.
     323 *
     324 * @since 4.7.0
     325 *
     326 * @return bool Whether or not we have more than one categories.
     327 */
     328function is_multi_category() {
     329        return is_multi_taxonomy( 'category' );
     330}
     331
     332/**
     333 * Checks to see if more than one tag has associated posts.
     334 *
     335 * @since 4.7.0
     336 *
     337 * @return bool Whether or not we have more than one tags.
     338 */
     339function is_multi_tag() {
     340        return is_multi_taxonomy( 'post_tag' );
     341}
     342
     343/**
    322344 * Update category structure to old pre 2.3 from new taxonomy structure.
    323345 *
    324346 * This function was added for the taxonomy support to update the new category
  • src/wp-includes/default-filters.php

     
    424424
    425425// Taxonomy
    426426add_action( 'init', 'create_initial_taxonomies', 0 ); // highest priority
     427add_action( 'edit_term', '_clear_multi_taxonomy_cache_for_term', 10, 3 );
     428add_action( 'save_post', '_clear_multi_taxonomy_cache_for_post', 10, 1 );
    427429
    428430// Canonical
    429431add_action( 'template_redirect', 'redirect_canonical' );
  • src/wp-includes/taxonomy.php

     
    44434443
    44444444        return $parent;
    44454445}
     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 */
     4455function 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 */
     4485function _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 */
     4503function _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 */
     4515function _clear_multi_taxonomy_cache_for_post( $post_id ) {
     4516        _clear_multi_taxonomy_cache( get_object_taxonomies( get_post( $post_id ) ) );
     4517}