Add support for a full path parameter to is_page() and is_single(). Props Jesper800, engelen, johnbillion. Fixes #16802.

Built from https://develop.svn.wordpress.org/trunk@29039


git-svn-id: http://core.svn.wordpress.org/trunk@28827 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
John Blackbourn 2014-07-09 16:04:16 +00:00
parent 2f4b08860b
commit 5a43586db1
2 changed files with 32 additions and 9 deletions

View File

@ -4311,7 +4311,7 @@ class WP_Query {
*
* @since 3.1.0
*
* @param mixed $page Page ID, title, slug, or array of such.
* @param mixed $page Page ID, title, slug, path, or array of such.
* @return bool
*/
public function is_page( $page = '' ) {
@ -4325,12 +4325,24 @@ class WP_Query {
$page = (array) $page;
if ( in_array( $page_obj->ID, $page ) )
if ( in_array( $page_obj->ID, $page ) ) {
return true;
elseif ( in_array( $page_obj->post_title, $page ) )
} elseif ( in_array( $page_obj->post_title, $page ) ) {
return true;
else if ( in_array( $page_obj->post_name, $page ) )
} else if ( in_array( $page_obj->post_name, $page ) ) {
return true;
} else {
foreach ( $page as $pagepath ) {
if ( ! strpos( $pagepath, '/' ) ) {
continue;
}
$pagepath_obj = get_page_by_path( $pagepath );
if ( $pagepath_obj && ( $pagepath_obj->ID == $page_obj->ID ) ) {
return true;
}
}
}
return false;
}
@ -4392,7 +4404,7 @@ class WP_Query {
*
* @since 3.1.0
*
* @param mixed $post Post ID, title, slug, or array of such.
* @param mixed $post Post ID, title, slug, path, or array of such.
* @return bool
*/
public function is_single( $post = '' ) {
@ -4406,13 +4418,24 @@ class WP_Query {
$post = (array) $post;
if ( in_array( $post_obj->ID, $post ) )
if ( in_array( $post_obj->ID, $post ) ) {
return true;
elseif ( in_array( $post_obj->post_title, $post ) )
} elseif ( in_array( $post_obj->post_title, $post ) ) {
return true;
elseif ( in_array( $post_obj->post_name, $post ) )
} elseif ( in_array( $post_obj->post_name, $post ) ) {
return true;
} else {
foreach ( $post as $postpath ) {
if ( ! strpos( $postpath, '/' ) ) {
continue;
}
$postpath_obj = get_page_by_path( $postpath, OBJECT, $post_obj->post_type );
if ( $postpath_obj && ( $postpath_obj->ID == $post_obj->ID ) ) {
return true;
}
}
}
return false;
}

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.0-alpha-20140708';
$wp_version = '4.0-alpha-20140709';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.