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. Built from https://develop.svn.wordpress.org/trunk@36307 git-svn-id: http://core.svn.wordpress.org/trunk@36274 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
b9fd40a8cb
commit
b0b13aff2f
|
@ -1022,6 +1022,10 @@ class WP_Rewrite {
|
|||
$feedmatch2 = $match . $feedregex2;
|
||||
$feedquery2 = $feedindex . '?' . $query . '&feed=' . $this->preg_index($num_toks + 1);
|
||||
|
||||
// Create query and regex for embeds.
|
||||
$embedmatch = $match . $embedregex;
|
||||
$embedquery = $embedindex . '?' . $query . '&embed=true';
|
||||
|
||||
// If asked to, turn the feed queries into comment feed ones.
|
||||
if ( $forcomments ) {
|
||||
$feedquery .= '&withcomments=1';
|
||||
|
@ -1033,7 +1037,7 @@ class WP_Rewrite {
|
|||
|
||||
// ...adding on /feed/ regexes => queries
|
||||
if ( $feed ) {
|
||||
$rewrite = array( $feedmatch => $feedquery, $feedmatch2 => $feedquery2 );
|
||||
$rewrite = array( $feedmatch => $feedquery, $feedmatch2 => $feedquery2, $embedmatch => $embedquery );
|
||||
}
|
||||
|
||||
//...and /page/xx ones
|
||||
|
|
|
@ -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 ) );
|
||||
}
|
||||
|
||||
|
|
|
@ -3574,7 +3574,7 @@ function wp_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_p
|
|||
* @param bool $bad_slug Whether the slug would be bad as an attachment slug.
|
||||
* @param string $slug The post slug.
|
||||
*/
|
||||
if ( $post_name_check || in_array( $slug, $feeds ) || apply_filters( 'wp_unique_post_slug_is_bad_attachment_slug', false, $slug ) ) {
|
||||
if ( $post_name_check || in_array( $slug, $feeds ) || 'embed' === $slug || apply_filters( 'wp_unique_post_slug_is_bad_attachment_slug', false, $slug ) ) {
|
||||
$suffix = 2;
|
||||
do {
|
||||
$alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
|
||||
|
@ -3604,7 +3604,7 @@ function wp_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_p
|
|||
* @param string $post_type Post type.
|
||||
* @param int $post_parent Post parent ID.
|
||||
*/
|
||||
if ( $post_name_check || in_array( $slug, $feeds ) || preg_match( "@^($wp_rewrite->pagination_base)?\d+$@", $slug ) || apply_filters( 'wp_unique_post_slug_is_bad_hierarchical_slug', false, $slug, $post_type, $post_parent ) ) {
|
||||
if ( $post_name_check || in_array( $slug, $feeds ) || 'embed' === $slug || preg_match( "@^($wp_rewrite->pagination_base)?\d+$@", $slug ) || apply_filters( 'wp_unique_post_slug_is_bad_hierarchical_slug', false, $slug, $post_type, $post_parent ) ) {
|
||||
$suffix = 2;
|
||||
do {
|
||||
$alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
|
||||
|
@ -3649,7 +3649,7 @@ function wp_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_p
|
|||
* @param string $slug The post slug.
|
||||
* @param string $post_type Post type.
|
||||
*/
|
||||
if ( $post_name_check || in_array( $slug, $feeds ) || $conflicts_with_date_archive || apply_filters( 'wp_unique_post_slug_is_bad_flat_slug', false, $slug, $post_type ) ) {
|
||||
if ( $post_name_check || in_array( $slug, $feeds ) || 'embed' === $slug || $conflicts_with_date_archive || apply_filters( 'wp_unique_post_slug_is_bad_flat_slug', false, $slug, $post_type ) ) {
|
||||
$suffix = 2;
|
||||
do {
|
||||
$alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
|
||||
|
|
|
@ -1456,6 +1456,7 @@ class WP_Query {
|
|||
, 'title'
|
||||
, 'fields'
|
||||
, 'menu_order'
|
||||
, 'embed'
|
||||
);
|
||||
|
||||
foreach ( $keys as $key ) {
|
||||
|
@ -1756,6 +1757,10 @@ class WP_Query {
|
|||
if ( '' != $qv['feed'] )
|
||||
$this->is_feed = true;
|
||||
|
||||
if ( '' != $qv['embed'] ) {
|
||||
$this->is_embed = true;
|
||||
}
|
||||
|
||||
if ( '' != $qv['tb'] )
|
||||
$this->is_trackback = true;
|
||||
|
||||
|
@ -1788,6 +1793,9 @@ class WP_Query {
|
|||
// pagename can be set and empty depending on matched rewrite rules. Ignore an empty pagename.
|
||||
if ( isset($_query['pagename']) && '' == $_query['pagename'] )
|
||||
unset($_query['pagename']);
|
||||
|
||||
unset( $_query['embed'] );
|
||||
|
||||
if ( empty($_query) || !array_diff( array_keys($_query), array('preview', 'page', 'paged', 'cpage') ) ) {
|
||||
$this->is_page = true;
|
||||
$this->is_home = false;
|
||||
|
@ -1859,7 +1867,7 @@ class WP_Query {
|
|||
if ( '404' == $qv['error'] )
|
||||
$this->set_404();
|
||||
|
||||
$this->is_embed = isset( $qv['embed'] ) && ( $this->is_singular || $this->is_404 );
|
||||
$this->is_embed = $this->is_embed && ( $this->is_singular || $this->is_404 );
|
||||
|
||||
$this->query_vars_hash = md5( serialize( $this->query_vars ) );
|
||||
$this->query_vars_changed = false;
|
||||
|
|
|
@ -478,13 +478,6 @@ function url_to_postid( $url ) {
|
|||
return $id;
|
||||
}
|
||||
|
||||
// Check to see if we are using rewrite rules
|
||||
$rewrite = $wp_rewrite->wp_rewrite_rules();
|
||||
|
||||
// Not using rewrite rules, and 'p=N' and 'page_id=N' methods failed, so we're out of options
|
||||
if ( empty($rewrite) )
|
||||
return 0;
|
||||
|
||||
// Get rid of the #anchor
|
||||
$url_split = explode('#', $url);
|
||||
$url = $url_split[0];
|
||||
|
@ -504,6 +497,21 @@ function url_to_postid( $url ) {
|
|||
if ( false === strpos(home_url(), '://www.') )
|
||||
$url = str_replace('://www.', '://', $url);
|
||||
|
||||
if ( trim( $url, '/' ) === home_url() && 'page' == get_option( 'show_on_front' ) ) {
|
||||
$page_on_front = get_option( 'page_on_front' );
|
||||
|
||||
if ( $page_on_front && get_post( $page_on_front ) instanceof WP_Post ) {
|
||||
return (int) $page_on_front;
|
||||
}
|
||||
}
|
||||
|
||||
// Check to see if we are using rewrite rules
|
||||
$rewrite = $wp_rewrite->wp_rewrite_rules();
|
||||
|
||||
// Not using rewrite rules, and 'p=N' and 'page_id=N' methods failed, so we're out of options
|
||||
if ( empty($rewrite) )
|
||||
return 0;
|
||||
|
||||
// Strip 'index.php/' if we're not using path info permalinks
|
||||
if ( !$wp_rewrite->using_index_permalinks() )
|
||||
$url = str_replace( $wp_rewrite->index . '/', '', $url );
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '4.5-alpha-36306';
|
||||
$wp_version = '4.5-alpha-36307';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue