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
This commit is contained in:
Sergey Biryukov 2018-07-18 11:49:46 +00:00
parent 7e4f59b28e
commit a1f6ba5477
2 changed files with 26 additions and 4 deletions

View File

@ -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(
'<a class="privacy-policy-link" href="%s">%s</a>',
esc_url( $privacy_policy_url ),
__( 'Privacy Policy' )
esc_html( $page_title )
);
}

View File

@ -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( '<a', $actual_link );
$this->assertContains( self::$privacy_policy_url, $actual_link );
$this->assertStringEndsWith( '</a>', $actual_link );
$this->assertStringEndsWith( '>' . WP_TESTS_DOMAIN . ' Privacy Policy</a>', $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.
*/