Make WordPress Core

Changeset 43506


Ignore:
Timestamp:
07/18/2018 11:49:46 AM (7 years ago)
Author:
SergeyBiryukov
Message:

Privacy: Use the actual Privacy Policy page title in get_the_privacy_policy_link().

Props desrosj, birgire, ianbelanger, Ov3rfly.
Fixes #44192.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/link-template.php

    r43002 r43506  
    43284328    $link               = '';
    43294329    $privacy_policy_url = get_privacy_policy_url();
    4330 
    4331     if ( $privacy_policy_url ) {
     4330    $policy_page_id     = (int) get_option( 'wp_page_for_privacy_policy' );
     4331    $page_title         = ( $policy_page_id ) ? get_the_title( $policy_page_id ) : '';
     4332
     4333    if ( $privacy_policy_url && $page_title ) {
    43324334        $link = sprintf(
    43334335            '<a class="privacy-policy-link" href="%s">%s</a>',
    43344336            esc_url( $privacy_policy_url ),
    4335             __( 'Privacy Policy' )
     4337            esc_html( $page_title )
    43364338        );
    43374339    }
  • trunk/tests/phpunit/tests/link/getThePrivacyPolicyLink.php

    r43002 r43506  
    7272    /**
    7373     * 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.
    7576     */
    7677    public function test_get_the_privacy_policy_link_should_return_valid_link_when_privacy_page_set() {
     
    8182        $this->assertStringStartsWith( '<a', $actual_link );
    8283        $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 );
    8485    }
    8586
     
    106107
    107108        $this->assertSame( '', $actual_link );
     109    }
     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 ) );
    108128    }
    109129
Note: See TracChangeset for help on using the changeset viewer.