Ticket #43620: 43620.policy_url.policy_link_4.diff
File 43620.policy_url.policy_link_4.diff, 4.6 KB (added by , 6 years ago) |
---|
-
src/wp-includes/link-template.php
diff --git src/wp-includes/link-template.php src/wp-includes/link-template.php index 9db1065c77..2e5dd7185a 100644
function get_parent_theme_file_path( $file = '' ) { 4282 4282 * @return string The URL to the privacy policy page. Empty string if it doesn't exist. 4283 4283 */ 4284 4284 function get_privacy_policy_url() { 4285 $url = ''; 4285 4286 $policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' ); 4286 4287 4287 4288 if ( ! empty( $policy_page_id ) && get_post_status( $policy_page_id ) === 'publish' ) { 4288 returnget_permalink( $policy_page_id );4289 $url = (string) get_permalink( $policy_page_id ); 4289 4290 } 4290 4291 4291 return ''; 4292 /** 4293 * Filters the URL of the privacy policy page. 4294 * 4295 * @since 4.9.6 4296 * 4297 * @param string $url The URL to the privacy policy page. Empty string if it 4298 * doesn't exist. 4299 * @param int $file The ID of privacy policy page. 4300 */ 4301 return apply_filters( 'privacy_policy_url', $url, $policy_page_id ); 4302 } 4303 4304 /** 4305 * Displays the privacy policy link with formatting, when applicable. 4306 * 4307 * @since 4.9.6 4308 * 4309 * @param string $before Optional. Display before privacy policy link. Default empty. 4310 * @param string $after Optional. Display after privacy policy link. Default empty. 4311 */ 4312 function the_privacy_policy_link( $before = '', $after = '' ) { 4313 echo get_the_privacy_policy_link( $before, $after ); 4314 } 4315 4316 /** 4317 * Returns the privacy policy link with formatting, when applicable. 4318 * 4319 * @since 4.9.6 4320 * 4321 * @param string $before Optional. Display before privacy policy link. Default empty. 4322 * @param string $after Optional. Display after privacy policy link. Default empty. 4323 * 4324 * @return string Markup for the link and surrounding elements. Empty string if it 4325 * doesn't exist. 4326 */ 4327 function get_the_privacy_policy_link( $before = '', $after = '' ) { 4328 $link = ''; 4329 $privacy_policy_url = get_privacy_policy_url(); 4330 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 ); 4337 } 4338 4339 /** 4340 * Filters the privacy policy link. 4341 * 4342 * @since 4.9.6 4343 * 4344 * @param string $link The privacy policy link. Empty string if it 4345 * doesn't exist. 4346 * @param string $privacy_policy_url The URL of the privacy policy. Empty string 4347 * if it doesn't exist. 4348 */ 4349 $link = apply_filters( 'the_privacy_policy_link', $link, $privacy_policy_url ); 4350 4351 if ( $link ) { 4352 return $before . $link . $after; 4353 } 4354 4355 return $link; 4292 4356 } -
tests/phpunit/tests/url.php
diff --git tests/phpunit/tests/url.php tests/phpunit/tests/url.php index 4d59c67bed..7edacb899d 100644
class Tests_URL extends WP_UnitTestCase { 527 527 ); 528 528 } 529 529 } 530 531 /** 532 * Test `get_privacy_policy_url()`. 533 * 534 * @ticket 43620. 535 */ 536 public function test_get_privacy_policy_url() { 537 $privacy_policy_page_id = self::factory()->post->create( 538 array( 539 'post_type' => 'page', 540 'post_title' => 'Privacy Policy' 541 ) 542 ); 543 $expected_url = get_permalink( $privacy_policy_page_id ); 544 545 $this->assertSame( '', get_privacy_policy_url() ); 546 547 update_option( 'wp_page_for_privacy_policy', $privacy_policy_page_id ); 548 $this->assertSame( $expected_url, get_privacy_policy_url() ); 549 } 550 551 /** 552 * Test `get_the_privacy_policy_link()`. 553 * 554 * @ticket 43620. 555 */ 556 public function test_get_the_privacy_policy_link() { 557 $privacy_policy_page_id = self::factory()->post->create( 558 array( 559 'post_type' => 'page', 560 'post_title' => WP_TESTS_DOMAIN . ' Privacy Policy' 561 ) 562 ); 563 564 $before = '<span class="privacy-policy-link-wrapper">'; 565 $after = '</span>'; 566 $expected_url = get_permalink( $privacy_policy_page_id ); 567 568 // Empty strings when a page is not set. 569 $this->assertSame( '', get_the_privacy_policy_link() ); 570 $this->assertSame( '', get_the_privacy_policy_link( $before, $after ) ); 571 572 // Valid link markup when a page is set. 573 update_option( 'wp_page_for_privacy_policy', $privacy_policy_page_id ); 574 $link = get_the_privacy_policy_link(); 575 576 $this->assertContains( $expected_url, $link ); 577 $this->assertStringStartsWith( '<a', $link ); 578 $this->assertStringEndsWith( '</a>', $link ); 579 580 $link = get_the_privacy_policy_link( $before, $after ); 581 582 $this->assertContains( $expected_url, $link ); 583 $this->assertStringStartsWith( $before . '<a', $link ); 584 $this->assertStringEndsWith( '</a>' . $after, $link ); 585 } 530 586 }