Privacy: Add template tags for building link to privacy policy page.

This introduces the `get_the_privacy_policy_link()` and `the_privacy_policy_link()` functions, as well as the `privacy_policy_url` filter.

A new `tests/url/` folder was added to better organize tests related to `get_*_url()` functions. Previously, those tests were placed in `tests/url.php` and `tests/link/`, but neither of those locations are optimal. Placing tests in `tests/url.php` violates the guideline of creating separate files/classes for each function under test, and using `tests/link/` conflates two distinct -- albeit related -- groups of functions. Over time, URL-related tests can be migrated to the new folder.

Props birgire, xkon, azaozz, iandunn.
See #43850.

Built from https://develop.svn.wordpress.org/trunk@43002


git-svn-id: http://core.svn.wordpress.org/trunk@42831 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
iandunn 2018-04-25 15:55:21 +00:00
parent 41968f7ea9
commit c9c3c61a53
2 changed files with 66 additions and 2 deletions

View File

@ -4282,10 +4282,74 @@ function get_parent_theme_file_path( $file = '' ) {
* @return string The URL to the privacy policy page. Empty string if it doesn't exist.
*/
function get_privacy_policy_url() {
$url = '';
$policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' );
if ( ! empty( $policy_page_id ) && get_post_status( $policy_page_id ) === 'publish' ) {
return get_permalink( $policy_page_id );
$url = (string) get_permalink( $policy_page_id );
}
/**
* Filters the URL of the privacy policy page.
*
* @since 4.9.6
*
* @param string $url The URL to the privacy policy page. Empty string
* if it doesn't exist.
* @param int $policy_page_id The ID of privacy policy page.
*/
return apply_filters( 'privacy_policy_url', $url, $policy_page_id );
}
/**
* Displays the privacy policy link with formatting, when applicable.
*
* @since 4.9.6
*
* @param string $before Optional. Display before privacy policy link. Default empty.
* @param string $after Optional. Display after privacy policy link. Default empty.
*/
function the_privacy_policy_link( $before = '', $after = '' ) {
echo get_the_privacy_policy_link( $before, $after );
}
/**
* Returns the privacy policy link with formatting, when applicable.
*
* @since 4.9.6
*
* @param string $before Optional. Display before privacy policy link. Default empty.
* @param string $after Optional. Display after privacy policy link. Default empty.
*
* @return string Markup for the link and surrounding elements. Empty string if it
* doesn't exist.
*/
function get_the_privacy_policy_link( $before = '', $after = '' ) {
$link = '';
$privacy_policy_url = get_privacy_policy_url();
if ( $privacy_policy_url ) {
$link = sprintf(
'<a class="privacy-policy-link" href="%s">%s</a>',
esc_url( $privacy_policy_url ),
__( 'Privacy Policy' )
);
}
/**
* Filters the privacy policy link.
*
* @since 4.9.6
*
* @param string $link The privacy policy link. Empty string if it
* doesn't exist.
* @param string $privacy_policy_url The URL of the privacy policy. Empty string
* if it doesn't exist.
*/
$link = apply_filters( 'the_privacy_policy_link', $link, $privacy_policy_url );
if ( $link ) {
return $before . $link . $after;
}
return '';

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.0-alpha-43001';
$wp_version = '5.0-alpha-43002';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.