diff --git src/wp-includes/link-template.php src/wp-includes/link-template.php
index 815c539..2d13754 100644
|
|
function get_the_privacy_policy_link( $before = '', $after = '' ) { |
4329 | 4329 | $privacy_policy_url = get_privacy_policy_url(); |
4330 | 4330 | |
4331 | 4331 | if ( $privacy_policy_url ) { |
4332 | | $link = sprintf( |
4333 | | '<a class="privacy-policy-link" href="%s">%s</a>', |
4334 | | esc_url( $privacy_policy_url ), |
4335 | | __( 'Privacy Policy' ) |
4336 | | ); |
| 4332 | $policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' ); |
| 4333 | $page_title = get_the_title( $policy_page_id ); |
| 4334 | |
| 4335 | if ( ! empty( $page_title ) ) { |
| 4336 | $link = sprintf( |
| 4337 | '<a class="privacy-policy-link" href="%s">%s</a>', |
| 4338 | esc_url( $privacy_policy_url ), |
| 4339 | esc_html( $page_title ) |
| 4340 | ); |
| 4341 | } |
4337 | 4342 | } |
4338 | 4343 | |
4339 | 4344 | /** |
diff --git tests/phpunit/tests/link/getThePrivacyPolicyLink.php tests/phpunit/tests/link/getThePrivacyPolicyLink.php
index 14dd1a9..f1c7f7e 100644
|
|
|
11 | 11 | * Test cases for the `get_the_privacy_policy_link()` function. |
12 | 12 | * |
13 | 13 | * @group link |
14 | | * @group privacy |
| 14 | * @group privacy1 |
15 | 15 | * @covers get_the_privacy_policy_link |
16 | 16 | * |
17 | 17 | * @since 4.9.6 |
… |
… |
class Tests_Link_GetThePrivacyPolicyLink extends WP_UnitTestCase { |
71 | 71 | |
72 | 72 | /** |
73 | 73 | * The function should return a valid link if a privacy policy page has been |
74 | | * created and set as the `wp_page_for_privacy_policy`. |
| 74 | * created and set as the `wp_page_for_privacy_policy`. The post title should |
| 75 | * be used as the link text. |
75 | 76 | */ |
76 | 77 | public function test_get_the_privacy_policy_link_should_return_valid_link_when_privacy_page_set() { |
77 | 78 | update_option( 'wp_page_for_privacy_policy', self::$privacy_policy_page_id ); |
… |
… |
class Tests_Link_GetThePrivacyPolicyLink extends WP_UnitTestCase { |
80 | 81 | |
81 | 82 | $this->assertStringStartsWith( '<a', $actual_link ); |
82 | 83 | $this->assertContains( self::$privacy_policy_url, $actual_link ); |
83 | | $this->assertStringEndsWith( '</a>', $actual_link ); |
| 84 | $this->assertStringEndsWith( '>' . WP_TESTS_DOMAIN . ' Privacy Policy</a>', $actual_link ); |
84 | 85 | } |
85 | 86 | |
86 | 87 | /** |
… |
… |
class Tests_Link_GetThePrivacyPolicyLink extends WP_UnitTestCase { |
108 | 109 | } |
109 | 110 | |
110 | 111 | /** |
| 112 | * The function should return an empty string when there is an empty page title |
| 113 | * for the privacy policy. |
| 114 | * |
| 115 | * @ticket 44192 |
| 116 | */ |
| 117 | public function test_function_should_return_empty_string_when_privacy_page_title_empty() { |
| 118 | $nameless_page_id = $this->factory->post->create( |
| 119 | array( |
| 120 | 'post_type' => 'page', |
| 121 | 'post_title' => '', |
| 122 | ) |
| 123 | ); |
| 124 | |
| 125 | update_option( 'wp_page_for_privacy_policy', $nameless_page_id ); |
| 126 | |
| 127 | $this->assertSame( '', get_the_privacy_policy_link( self::$before, self::$after ) ); |
| 128 | } |
| 129 | |
| 130 | /** |
111 | 131 | * The function should return an empty string when `wp_page_for_privacy_policy` is _not_ configured. |
112 | 132 | */ |
113 | 133 | public function test_get_the_privacy_policy_link_should_return_empty_string_when_privacy_page_not_set() { |