From 2b1840d393576344de43ff37590e1deefd197e73 Mon Sep 17 00:00:00 2001 From: audrasjb Date: Tue, 7 Feb 2023 14:35:23 +0000 Subject: [PATCH] Media: Introduce `wp_get_attachment_link_attributes` filter. This changeset introduces the `wp_get_attachment_link_attributes` hook to allow developers to filter the link attributes when getting the attachment link. Props NathanAtmoz, aaroncampbell, antpb, costdev. Fixes #41574. Built from https://develop.svn.wordpress.org/trunk@55262 git-svn-id: http://core.svn.wordpress.org/trunk@54795 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/post-template.php | 19 ++++++++++++++++++- wp-includes/version.php | 2 +- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/wp-includes/post-template.php b/wp-includes/post-template.php index b5c3772828..27f55fc7df 100644 --- a/wp-includes/post-template.php +++ b/wp-includes/post-template.php @@ -1666,7 +1666,24 @@ function wp_get_attachment_link( $post = 0, $size = 'thumbnail', $permalink = fa $link_text = esc_html( pathinfo( get_attached_file( $_post->ID ), PATHINFO_FILENAME ) ); } - $link_html = "$link_text"; + /** + * Filters the list of attachment link attributes. + * + * @since 6.2.0 + * + * @param array $attributes An array of attributes for the link markup, + * keyed on the attribute name. + * @param int $id Post ID. + */ + $attributes = apply_filters( 'wp_get_attachment_link_attributes', array( 'href' => $url ), $_post->ID ); + + $link_attributes = ''; + foreach ( $attributes as $name => $value ) { + $value = 'href' === $name ? esc_url( $value ) : esc_attr( $value ); + $link_attributes .= ' ' . esc_attr( $name ) . "='" . $value . "'"; + } + + $link_html = "$link_text"; /** * Filters a retrieved attachment page link. diff --git a/wp-includes/version.php b/wp-includes/version.php index 0a5ce9c40d..9709ace729 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.2-alpha-55261'; +$wp_version = '6.2-alpha-55262'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.