mirror of
git://develop.git.wordpress.org/
synced 2025-04-04 20:23:27 +02:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@58286 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
bcbb31d98a
commit
0e963984d9
@ -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";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -127,7 +127,7 @@ class Test_oEmbed_Controller extends WP_UnitTestCase {
|
||||
'response' => array(
|
||||
'code' => 200,
|
||||
),
|
||||
'body' => '<html><head><link rel="alternate" type="application/json+oembed" href="' . self::UNTRUSTED_PROVIDER_URL . '" /></head><body></body></html>',
|
||||
'body' => '<html><head><link rel="alternate" title="oEmbed (JSON)" type="application/json+oembed" href="' . self::UNTRUSTED_PROVIDER_URL . '" /></head><body></body></html>',
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -32,8 +32,8 @@ class Tests_oEmbed_Discovery extends WP_UnitTestCase {
|
||||
$this->go_to( home_url() );
|
||||
$this->assertQueryTrue( 'is_front_page', 'is_singular', 'is_page' );
|
||||
|
||||
$expected = '<link rel="alternate" type="application/json+oembed" href="' . esc_url( get_oembed_endpoint_url( get_permalink() ) ) . '" />' . "\n";
|
||||
$expected .= '<link rel="alternate" type="text/xml+oembed" href="' . esc_url( get_oembed_endpoint_url( get_permalink(), 'xml' ) ) . '" />' . "\n";
|
||||
$expected = '<link rel="alternate" title="oEmbed (JSON)" type="application/json+oembed" href="' . esc_url( get_oembed_endpoint_url( get_permalink() ) ) . '" />' . "\n";
|
||||
$expected .= '<link rel="alternate" title="oEmbed (XML)" type="text/xml+oembed" href="' . esc_url( get_oembed_endpoint_url( get_permalink(), 'xml' ) ) . '" />' . "\n";
|
||||
|
||||
$this->assertSame( $expected, get_echo( 'wp_oembed_add_discovery_links' ) );
|
||||
|
||||
@ -45,8 +45,8 @@ class Tests_oEmbed_Discovery extends WP_UnitTestCase {
|
||||
$this->go_to( get_permalink( $post_id ) );
|
||||
$this->assertQueryTrue( 'is_single', 'is_singular' );
|
||||
|
||||
$expected = '<link rel="alternate" type="application/json+oembed" href="' . esc_url( get_oembed_endpoint_url( get_permalink() ) ) . '" />' . "\n";
|
||||
$expected .= '<link rel="alternate" type="text/xml+oembed" href="' . esc_url( get_oembed_endpoint_url( get_permalink(), 'xml' ) ) . '" />' . "\n";
|
||||
$expected = '<link rel="alternate" title="oEmbed (JSON)" type="application/json+oembed" href="' . esc_url( get_oembed_endpoint_url( get_permalink() ) ) . '" />' . "\n";
|
||||
$expected .= '<link rel="alternate" title="oEmbed (XML)" type="text/xml+oembed" href="' . esc_url( get_oembed_endpoint_url( get_permalink(), 'xml' ) ) . '" />' . "\n";
|
||||
|
||||
$this->assertSame( $expected, get_echo( 'wp_oembed_add_discovery_links' ) );
|
||||
}
|
||||
@ -60,8 +60,8 @@ class Tests_oEmbed_Discovery extends WP_UnitTestCase {
|
||||
$this->go_to( get_permalink( $post_id ) );
|
||||
$this->assertQueryTrue( 'is_page', 'is_singular' );
|
||||
|
||||
$expected = '<link rel="alternate" type="application/json+oembed" href="' . esc_url( get_oembed_endpoint_url( get_permalink() ) ) . '" />' . "\n";
|
||||
$expected .= '<link rel="alternate" type="text/xml+oembed" href="' . esc_url( get_oembed_endpoint_url( get_permalink(), 'xml' ) ) . '" />' . "\n";
|
||||
$expected = '<link rel="alternate" title="oEmbed (JSON)" type="application/json+oembed" href="' . esc_url( get_oembed_endpoint_url( get_permalink() ) ) . '" />' . "\n";
|
||||
$expected .= '<link rel="alternate" title="oEmbed (XML)" type="text/xml+oembed" href="' . esc_url( get_oembed_endpoint_url( get_permalink(), 'xml' ) ) . '" />' . "\n";
|
||||
|
||||
$this->assertSame( $expected, get_echo( 'wp_oembed_add_discovery_links' ) );
|
||||
}
|
||||
@ -80,8 +80,8 @@ class Tests_oEmbed_Discovery extends WP_UnitTestCase {
|
||||
$this->go_to( get_permalink( $attachment_id ) );
|
||||
$this->assertQueryTrue( 'is_attachment', 'is_singular', 'is_single' );
|
||||
|
||||
$expected = '<link rel="alternate" type="application/json+oembed" href="' . esc_url( get_oembed_endpoint_url( get_permalink() ) ) . '" />' . "\n";
|
||||
$expected .= '<link rel="alternate" type="text/xml+oembed" href="' . esc_url( get_oembed_endpoint_url( get_permalink(), 'xml' ) ) . '" />' . "\n";
|
||||
$expected = '<link rel="alternate" title="oEmbed (JSON)" type="application/json+oembed" href="' . esc_url( get_oembed_endpoint_url( get_permalink() ) ) . '" />' . "\n";
|
||||
$expected .= '<link rel="alternate" title="oEmbed (XML)" type="text/xml+oembed" href="' . esc_url( get_oembed_endpoint_url( get_permalink(), 'xml' ) ) . '" />' . "\n";
|
||||
|
||||
$this->assertSame( $expected, get_echo( 'wp_oembed_add_discovery_links' ) );
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user