From 8a6d07f5964649baa260c0ae682e695602ffe343 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Thu, 15 Oct 2015 06:49:25 +0000 Subject: [PATCH] In `WP::parse_request()` and `url_to_postid()`, if a post slug clashes with a trashed page, return the post instead of the page. Props kovshenin, SergeyBiryukov, igmoweb. Fixes #21970. Built from https://develop.svn.wordpress.org/trunk@35195 git-svn-id: http://core.svn.wordpress.org/trunk@35161 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp.php | 9 ++++++++- wp-includes/rewrite-functions.php | 9 ++++++++- wp-includes/version.php | 2 +- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/wp-includes/class-wp.php b/wp-includes/class-wp.php index bba47ffb71..4acadadca1 100644 --- a/wp-includes/class-wp.php +++ b/wp-includes/class-wp.php @@ -209,8 +209,15 @@ class WP { if ( $wp_rewrite->use_verbose_page_rules && preg_match( '/pagename=\$matches\[([0-9]+)\]/', $query, $varmatch ) ) { // This is a verbose page match, let's check to be sure about it. - if ( ! get_page_by_path( $matches[ $varmatch[1] ] ) ) + $page = get_page_by_path( $matches[ $varmatch[1] ] ); + if ( ! $page ) { continue; + } + + $post_status_obj = get_post_status_object( $page->post_status ); + if ( ! $post_status_obj->public && ! $post_status_obj->protected && ! $post_status_obj->private ) { + continue; + } } // Got a match. diff --git a/wp-includes/rewrite-functions.php b/wp-includes/rewrite-functions.php index a42535b4a4..2f9be5ad99 100644 --- a/wp-includes/rewrite-functions.php +++ b/wp-includes/rewrite-functions.php @@ -397,8 +397,15 @@ function url_to_postid( $url ) { if ( $wp_rewrite->use_verbose_page_rules && preg_match( '/pagename=\$matches\[([0-9]+)\]/', $query, $varmatch ) ) { // This is a verbose page match, let's check to be sure about it. - if ( ! get_page_by_path( $matches[ $varmatch[1] ] ) ) + $page = get_page_by_path( $matches[ $varmatch[1] ] ); + if ( ! $page ) { continue; + } + + $post_status_obj = get_post_status_object( $page->post_status ); + if ( ! $post_status_obj->public && ! $post_status_obj->protected && ! $post_status_obj->private ) { + continue; + } } // Got a match. diff --git a/wp-includes/version.php b/wp-includes/version.php index 646da3d79c..5d8163ba98 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.4-alpha-35194'; +$wp_version = '4.4-alpha-35195'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.