From a1f6ba547791416459b9fbb3b7869d6a59dff32f Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Wed, 18 Jul 2018 11:49:46 +0000 Subject: [PATCH] Privacy: Use the actual Privacy Policy page title in `get_the_privacy_policy_link()`. Props desrosj, birgire, ianbelanger, Ov3rfly. Fixes #44192. git-svn-id: https://develop.svn.wordpress.org/trunk@43506 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/link-template.php | 6 +++-- .../tests/link/getThePrivacyPolicyLink.php | 24 +++++++++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/wp-includes/link-template.php b/src/wp-includes/link-template.php index 815c539a4a..47f4376d92 100644 --- a/src/wp-includes/link-template.php +++ b/src/wp-includes/link-template.php @@ -4327,12 +4327,14 @@ function the_privacy_policy_link( $before = '', $after = '' ) { function get_the_privacy_policy_link( $before = '', $after = '' ) { $link = ''; $privacy_policy_url = get_privacy_policy_url(); + $policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' ); + $page_title = ( $policy_page_id ) ? get_the_title( $policy_page_id ) : ''; - if ( $privacy_policy_url ) { + if ( $privacy_policy_url && $page_title ) { $link = sprintf( '%s', esc_url( $privacy_policy_url ), - __( 'Privacy Policy' ) + esc_html( $page_title ) ); } diff --git a/tests/phpunit/tests/link/getThePrivacyPolicyLink.php b/tests/phpunit/tests/link/getThePrivacyPolicyLink.php index 14dd1a9ea0..3543868831 100644 --- a/tests/phpunit/tests/link/getThePrivacyPolicyLink.php +++ b/tests/phpunit/tests/link/getThePrivacyPolicyLink.php @@ -71,7 +71,8 @@ class Tests_Link_GetThePrivacyPolicyLink extends WP_UnitTestCase { /** * The function should return a valid link if a privacy policy page has been - * created and set as the `wp_page_for_privacy_policy`. + * created and set as the `wp_page_for_privacy_policy`. The post title should + * be used as the link text. */ public function test_get_the_privacy_policy_link_should_return_valid_link_when_privacy_page_set() { update_option( 'wp_page_for_privacy_policy', self::$privacy_policy_page_id ); @@ -80,7 +81,7 @@ class Tests_Link_GetThePrivacyPolicyLink extends WP_UnitTestCase { $this->assertStringStartsWith( 'assertContains( self::$privacy_policy_url, $actual_link ); - $this->assertStringEndsWith( '', $actual_link ); + $this->assertStringEndsWith( '>' . WP_TESTS_DOMAIN . ' Privacy Policy', $actual_link ); } /** @@ -107,6 +108,25 @@ class Tests_Link_GetThePrivacyPolicyLink extends WP_UnitTestCase { $this->assertSame( '', $actual_link ); } + /** + * The function should return an empty string when there is an empty page title + * for the privacy policy. + * + * @ticket 44192 + */ + public function test_function_should_return_empty_string_when_privacy_page_title_empty() { + $nameless_page_id = $this->factory->post->create( + array( + 'post_type' => 'page', + 'post_title' => '', + ) + ); + + update_option( 'wp_page_for_privacy_policy', $nameless_page_id ); + + $this->assertSame( '', get_the_privacy_policy_link( self::$before, self::$after ) ); + } + /** * The function should return an empty string when `wp_page_for_privacy_policy` is _not_ configured. */