diff --git a/wp-includes/class-wp-rewrite.php b/wp-includes/class-wp-rewrite.php index 7c639990d1..808ae2a690 100644 --- a/wp-includes/class-wp-rewrite.php +++ b/wp-includes/class-wp-rewrite.php @@ -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 diff --git a/wp-includes/embed.php b/wp-includes/embed.php index 9fa1aa3df7..0284e4c5ce 100644 --- a/wp-includes/embed.php +++ b/wp-includes/embed.php @@ -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 .= '' . "\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 ) ); } diff --git a/wp-includes/post.php b/wp-includes/post.php index 72ef1641aa..690e597c1a 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -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"; diff --git a/wp-includes/query.php b/wp-includes/query.php index 44e9a5c242..69aa2a7ba4 100644 --- a/wp-includes/query.php +++ b/wp-includes/query.php @@ -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; diff --git a/wp-includes/rewrite.php b/wp-includes/rewrite.php index c43abe8de9..0c92446d0c 100644 --- a/wp-includes/rewrite.php +++ b/wp-includes/rewrite.php @@ -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 ); diff --git a/wp-includes/version.php b/wp-includes/version.php index e14a44d2b8..248514c02f 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -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.