mirror of
git://develop.git.wordpress.org/
synced 2025-04-14 09:02:06 +02:00
Privacy: Use the actual Privacy Policy page title in get_the_privacy_policy_link()
.
Props desrosj, birgire, ianbelanger, Ov3rfly. Merges [43506] to the 4.9 branch. Fixes #44192. git-svn-id: https://develop.svn.wordpress.org/branches/4.9@43507 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
8e0b78fadf
commit
9c35dcd477
@ -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(
|
||||
'<a class="privacy-policy-link" href="%s">%s</a>',
|
||||
esc_url( $privacy_policy_url ),
|
||||
__( 'Privacy Policy' )
|
||||
esc_html( $page_title )
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -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.
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user