diff --git a/src/wp-includes/link-template.php b/src/wp-includes/link-template.php
index b55ebcb189..00b572c5c5 100644
--- a/src/wp-includes/link-template.php
+++ b/src/wp-includes/link-template.php
@@ -4158,12 +4158,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.
*/