From 0301c933d4513b40e1f0c2d95c63e67f212cb48a Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Mon, 5 Sep 2022 05:45:14 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/trunk@54066 git-svn-id: http://core.svn.wordpress.org/trunk@53625 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/post-template.php | 15 +++++++++++++++ wp-includes/version.php | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/wp-includes/post-template.php b/wp-includes/post-template.php index 9f12a2aefb..99ec81deb4 100644 --- a/wp-includes/post-template.php +++ b/wp-includes/post-template.php @@ -547,6 +547,21 @@ function get_post_class( $class = '', $post = null ) { // All public taxonomies. $taxonomies = get_taxonomies( array( 'public' => true ) ); + + /** + * Filters the taxonomies to generate classes for each individual term. + * + * Default is all public taxonomies registered to the post type. + * + * @since 6.1.0 + * + * @param array $taxonomies List of all public taxonomies to generate classes for. + * @param int $post_id The post ID. + * @param string[] $classes An array of post class names. + * @param string[] $class An array of additional class names added to the post. + */ + $taxonomies = apply_filters( 'wp_post_class_taxonomies', $taxonomies, $post->ID, $classes, $class ); + foreach ( (array) $taxonomies as $taxonomy ) { if ( is_object_in_taxonomy( $post->post_type, $taxonomy ) ) { foreach ( (array) get_the_terms( $post->ID, $taxonomy ) as $term ) { diff --git a/wp-includes/version.php b/wp-includes/version.php index 601649e9d8..41c0f30964 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.1-alpha-54065'; +$wp_version = '6.1-alpha-54066'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.