From eeac928d3bfe453870eb508aa800b34914a9dc49 Mon Sep 17 00:00:00 2001 From: Gary Pendergast Date: Wed, 9 Jan 2019 06:00:51 +0000 Subject: [PATCH] Comments: Add a new `is_avatar_comment_type()` function. This function splits the `get_avatar_comment_types` filter out of `get_avatar_data()`. Props dshanske, birgire. Fixes #44033. Built from https://develop.svn.wordpress.org/trunk@44499 git-svn-id: http://core.svn.wordpress.org/trunk@44330 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/link-template.php | 33 ++++++++++++++++++++++++--------- wp-includes/version.php | 2 +- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/wp-includes/link-template.php b/wp-includes/link-template.php index cda3444af8..0e746becb0 100644 --- a/wp-includes/link-template.php +++ b/wp-includes/link-template.php @@ -3937,6 +3937,29 @@ function get_avatar_url( $id_or_email, $args = null ) { return $args['url']; } + +/** + * Check if this comment type allows avatars to be retrieved. + * + * @since 5.1.0 + * + * @param string $comment_type Comment type to check. + * @return bool Whether the comment type is allowed for retrieving avatars. + */ +function is_avatar_comment_type( $comment_type ) { + /** + * Filters the list of allowed comment types for retrieving avatars. + * + * @since 3.0.0 + * + * @param array $types An array of content types. Default only contains 'comment'. + */ + $allowed_comment_types = apply_filters( 'get_avatar_comment_types', array( 'comment' ) ); + + return in_array( $comment_type, (array) $allowed_comment_types, true ); +} + + /** * Retrieves default data about the avatar. * @@ -4082,15 +4105,7 @@ function get_avatar_data( $id_or_email, $args = null ) { // Post Object $user = get_user_by( 'id', (int) $id_or_email->post_author ); } elseif ( $id_or_email instanceof WP_Comment ) { - /** - * Filters the list of allowed comment types for retrieving avatars. - * - * @since 3.0.0 - * - * @param array $types An array of content types. Default only contains 'comment'. - */ - $allowed_comment_types = apply_filters( 'get_avatar_comment_types', array( 'comment' ) ); - if ( ! empty( $id_or_email->comment_type ) && ! in_array( $id_or_email->comment_type, (array) $allowed_comment_types ) ) { + if ( ! is_avatar_comment_type( get_comment_type( $id_or_email ) ) ) { $args['url'] = false; /** This filter is documented in wp-includes/link-template.php */ return apply_filters( 'get_avatar_data', $args, $id_or_email ); diff --git a/wp-includes/version.php b/wp-includes/version.php index f3e6997dd5..27a587c9eb 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.1-alpha-44498'; +$wp_version = '5.1-alpha-44499'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.