From 3e3b09c8eaa41d92981669256336854270ca8623 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Sun, 22 May 2016 16:18:22 +0000 Subject: [PATCH] In `get_page_by_path()`, values fetched from cache should obey `$output` param. Introduced in [37479]. Props spacedmonkey. Fixes #36711. git-svn-id: https://develop.svn.wordpress.org/trunk@37481 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/post.php | 2 +- tests/phpunit/tests/post/getPageByPath.php | 26 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index ceaa1d96a8..8a0e36b68b 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -4245,7 +4245,7 @@ function get_page_by_path( $page_path, $output = OBJECT, $post_type = 'page' ) { if ( '0' === $cached || 0 === $cached ) { return; } else { - return get_post( $cached ); + return get_post( $cached, $output ); } } diff --git a/tests/phpunit/tests/post/getPageByPath.php b/tests/phpunit/tests/post/getPageByPath.php index 01271bcaa2..2390903e2d 100644 --- a/tests/phpunit/tests/post/getPageByPath.php +++ b/tests/phpunit/tests/post/getPageByPath.php @@ -242,4 +242,30 @@ class Tests_Post_GetPageByPath extends WP_UnitTestCase { $num_queries++; $this->assertSame( $num_queries, $wpdb->num_queries ); } + + /** + * @ticket 37611 + */ + public function test_output_param_should_be_obeyed_for_cached_value() { + $page = self::factory()->post->create( array( + 'post_type' => 'page', + 'post_name' => 'foo', + ) ); + + // Prime cache. + $found = get_page_by_path( 'foo' ); + $this->assertSame( $page, $found->ID ); + + $object = get_page_by_path( 'foo', OBJECT ); + $this->assertInternalType( 'object', $object ); + $this->assertSame( $page, $object->ID ); + + $array_n = get_page_by_path( 'foo', ARRAY_N ); + $this->assertInternalType( 'array', $array_n ); + $this->assertSame( $page, $array_n[0] ); + + $array_a = get_page_by_path( 'foo', ARRAY_A ); + $this->assertInternalType( 'array', $array_a ); + $this->assertSame( $page, $array_a['ID'] ); + } }