Embeds: Allow embedding static front pages and pages having a child page with an embed slug.

This makes `embed` a special slug that can't be used for new pages/posts. When `https://example.com/foo/embed/` is an existing page, embeds fall back to `https://example.com/foo/?embed=true`.
Adds unit tests.

Fixes #34971.

git-svn-id: https://develop.svn.wordpress.org/trunk@36307 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Pascal Birchler
2016-01-15 07:55:19 +00:00
parent ee60e36a2c
commit d80a3c7ccd
10 changed files with 241 additions and 27 deletions

View File

@@ -345,7 +345,7 @@ function wp_oembed_register_route() {
function wp_oembed_add_discovery_links() {
$output = '';
if ( is_singular() && ! is_front_page() ) {
if ( is_singular() ) {
$output .= '<link rel="alternate" type="application/json+oembed" href="' . esc_url( get_oembed_endpoint_url( get_permalink() ) ) . '" />' . "\n";
if ( class_exists( 'SimpleXMLElement' ) ) {
@@ -387,9 +387,10 @@ function get_post_embed_url( $post = null ) {
return false;
}
if ( get_option( 'permalink_structure' ) ) {
$embed_url = trailingslashit( get_permalink( $post ) ) . user_trailingslashit( 'embed' );
} else {
$embed_url = trailingslashit( get_permalink( $post ) ) . user_trailingslashit( 'embed' );
$path_conflict = get_page_by_path( str_replace( home_url(), '', $embed_url ), OBJECT, get_post_types( array( 'public' => true ) ) );
if ( ! get_option( 'permalink_structure' ) || $path_conflict ) {
$embed_url = add_query_arg( array( 'embed' => 'true' ), get_permalink( $post ) );
}