[wp-trac] [WordPress Trac] #43620: Privacy Policy page design
WordPress Trac
noreply at wordpress.org
Sat Apr 21 10:44:51 UTC 2018
#43620: Privacy Policy page design
------------------------------------------+--------------------------------
Reporter: melchoyce | Owner: xkon
Type: enhancement | Status: assigned
Priority: normal | Milestone: 4.9.6
Component: General | Version:
Severity: normal | Resolution:
Keywords: gdpr has-patch needs-testing | Focuses: ui,
| administration
------------------------------------------+--------------------------------
Comment (by birgire):
The {{{get_privacy_policy_url()}}} uses {{{get_permalink()}}} that returns
a string or {{{false}}}:
{{{
* @return string|false The permalink URL or false if post does not exist.
}}}
so that means {{{get_privacy_policy_url()}}} can return a string or false
Examples:
{{{
delete_option( 'wp_page_for_privacy_policy' );
var_dump( get_privacy_policy_url() );
string(0) ""
update_option( 'wp_page_for_privacy_policy', 0 );
var_dump( get_privacy_policy_url() );
string(0) ""
update_option( 'wp_page_for_privacy_policy', PHP_INT_MAX );
var_dump( get_privacy_policy_url() );
bool(false)
}}}
In general there's inconsistancy between core {{{get_*_url()}}} functions
return, either empty string or false on failure.
I think we should choose either {{{false}}} or empty string here.
There's exists a function since 4.7, with a familiar structure, that we
could look into:
{{{
/**
* Retrieve header video URL for custom header.
*
* Uses a local video if present, or falls back to an external video.
*
* @since 4.7.0
*
* @return string|false Header video URL or false if there is no video.
*/
function get_header_video_url() {
$id = absint( get_theme_mod( 'header_video' ) );
$url = esc_url( get_theme_mod( 'external_header_video' ) );
if ( $id ) {
// Get the file URL from the attachment ID.
$url = wp_get_attachment_url( $id );
}
/**
* Filters the header video URL.
*
* @since 4.7.3
*
* @param string $url Header video URL, if available.
*/
$url = apply_filters( 'get_header_video_url', $url );
if ( ! $id && ! $url ) {
return false;
}
return esc_url_raw( set_url_scheme( $url ) );
}
}}}
and template tags to use in themes:
{{{
/**
* Display header video URL.
*
* @since 4.7.0
*/
function the_header_video_url() {
$video = get_header_video_url();
if ( $video ) {
echo esc_url( $video );
}
}
/**
* Check whether a header video is set or not.
*
* @since 4.7.0
*
* @see get_header_video_url()
*
* @return bool Whether a header video is set or not.
*/
function has_header_video() {
return (bool) get_header_video_url();
}
}}}
We could also consider:
{{{
function the_privacy_policy_url() {
$privacty_policy_url = get_privacy_policy_url();
if ( $privacty_policy_url ) {
echo esc_url( $privacty_policy_url );
}
}
function has_privacy_policy() {
return (bool) get_privacy_policy_url();
}
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/43620#comment:32>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list