Embeds: Add titles to alternate resource links for oEmbed and REST API.

This changeset makes the following changes:
- Adds the title attribute to `<link rel="alternate">` tags for oEmbed and REST API endpoints
- Updates the oEmbed phpunit tests to reflect the above change
- Adds the title link-param to REST API Link: headers (verified as supported in RFC 8288 here: https://httpwg.org/specs/rfc8288.html#serialisation-defined-attributes)

Props edent, kadamwhite, TimothyBlynJacobs, joedolson, swissspidy, sabernhardt.
Fixes #59006.



Built from https://develop.svn.wordpress.org/trunk@58286


git-svn-id: http://core.svn.wordpress.org/trunk@57746 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
audrasjb 2024-06-02 22:02:16 +00:00
parent 0d72c5dd46
commit d82ab90019
3 changed files with 16 additions and 5 deletions

View File

@ -336,10 +336,10 @@ function wp_oembed_add_discovery_links() {
$output = '';
if ( is_singular() ) {
$output .= '<link rel="alternate" type="application/json+oembed" href="' . esc_url( get_oembed_endpoint_url( get_permalink() ) ) . '" />' . "\n";
$output .= '<link rel="alternate" title="' . _x( 'oEmbed (JSON)', 'oEmbed resource link name' ) . '" type="application/json+oembed" href="' . esc_url( get_oembed_endpoint_url( get_permalink() ) ) . '" />' . "\n";
if ( class_exists( 'SimpleXMLElement' ) ) {
$output .= '<link rel="alternate" type="text/xml+oembed" href="' . esc_url( get_oembed_endpoint_url( get_permalink(), 'xml' ) ) . '" />' . "\n";
$output .= '<link rel="alternate" title="' . _x( 'oEmbed (XML)', 'oEmbed resource link name' ) . '" type="text/xml+oembed" href="' . esc_url( get_oembed_endpoint_url( get_permalink(), 'xml' ) ) . '" />' . "\n";
}
}

View File

@ -1007,7 +1007,11 @@ function rest_output_link_wp_head() {
$resource = rest_get_queried_resource_route();
if ( $resource ) {
printf( '<link rel="alternate" type="application/json" href="%s" />', esc_url( rest_url( $resource ) ) );
printf(
'<link rel="alternate" title="%1$s" type="application/json" href="%2$s" />',
_x( 'JSON', 'REST API resource link name' ),
esc_url( rest_url( $resource ) )
);
}
}
@ -1032,7 +1036,14 @@ function rest_output_link_header() {
$resource = rest_get_queried_resource_route();
if ( $resource ) {
header( sprintf( 'Link: <%s>; rel="alternate"; type="application/json"', sanitize_url( rest_url( $resource ) ) ), false );
header(
sprintf(
'Link: <%1$s>; rel="alternate"; title="%2$s"; type="application/json"',
sanitize_url( rest_url( $resource ) ),
_x( 'JSON', 'REST API resource link name' )
),
false
);
}
}

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.6-alpha-58285';
$wp_version = '6.6-alpha-58286';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.