Make WordPress Core

Changeset 54066


Ignore:
Timestamp:
09/05/2022 05:43:57 AM (3 months ago)
Author:
peterwilsoncc
Message:

Posts, Post Types: Allow bypassing of term classes in get_post_class().

Introduces the filter wp_post_class_taxonomies to allow developers to bypass the generation of term based classes with the get_post_class() function.

Developers can use this filter to reduce the number of taxonomies for which classes term classes are generated. This can improve performance on sites with a large number of custom taxonomies.

Props boonebgorges, bordoni, davidbaumwald, desrosj, invelity, mukesh27, sebastianpisula, steveo2000, swissspidy, system909, tlovett1, xparham.
Fixes #37114.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/post-template.php

    r53958 r54066  
    548548    // All public taxonomies.
    549549    $taxonomies = get_taxonomies( array( 'public' => true ) );
     550
     551    /**
     552     * Filters the taxonomies to generate classes for each individual term.
     553     *
     554     * Default is all public taxonomies registered to the post type.
     555     *
     556     * @since 6.1.0
     557     *
     558     * @param array    $taxonomies List of all public taxonomies to generate classes for.
     559     * @param int      $post_id    The post ID.
     560     * @param string[] $classes    An array of post class names.
     561     * @param string[] $class      An array of additional class names added to the post.
     562    */
     563    $taxonomies = apply_filters( 'wp_post_class_taxonomies', $taxonomies, $post->ID, $classes, $class );
     564
    550565    foreach ( (array) $taxonomies as $taxonomy ) {
    551566        if ( is_object_in_taxonomy( $post->post_type, $taxonomy ) ) {
Note: See TracChangeset for help on using the changeset viewer.