[wp-trac] [WordPress Trac] #50424: Privacy Page Shortcode

WordPress Trac noreply at wordpress.org
Thu Jun 18 17:46:33 UTC 2020


#50424: Privacy Page Shortcode
-------------------------+-----------------------------
 Reporter:  leehodson    |      Owner:  (none)
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  Privacy      |    Version:  5.4.2
 Severity:  normal       |   Keywords:
  Focuses:               |
-------------------------+-----------------------------
 The Privacy Page set in Dashboard > Settings > Privacy can be added to
 menus with ease but there is no easy way for non technical WordPress users
 to link to their site's correct Privacy Page within other areas of their
 site such as within widgets, pages and posts or within their site's
 footer.

 **Proposal**

 WordPress needs to include a Privacy Page shortcode that displays the
 correct link to a site's privacy page as set in Settings > Privacy. For
 example [privacy] and [privacy title=""].

 **Example code for this shortcode**

 {{{#!php
 <?php
 function privacy_page_sc_vr51( $atts ) {
   # Creates a Privacy Page link shortcode.
   # Use as [privacy title="Privacy Page Title"] or [privacy]
   # Default page title is Privacy Page.
   # Page link points to the Privacy Page set in Dashboard > Privacy.
   # The privacy page will only display if the page is public (status =
 publish).
   # Place this snippet into the site theme's functions.php file, a custom
 functions plugin or some other
   # suitable place.

         $atts = shortcode_atts(
                 array(
                         'title' => 'Privacy Page'
                 ), $atts
         );

         $name = sanitize_text_field( $atts['title'] );

         # See wp-admin/includes/class-wp-privacy-policy-content.php
         $privacy_page_id = (int) get_option( 'wp_page_for_privacy_policy'
 );

         if ( ! empty($privacy_page_id) && get_post_status(
 $privacy_page_id ) == 'public' ) {
                 return esc_url( get_page_link( $privacy_page_id );
         } else {
                 return;
         }
 }
 add_shortcode( 'privacy', 'privacy_page_sc_vr51' );

 }}}

 Gist Link: https://gist.github.com/VR51/84b9ab89681d0677bd60d8b8565a6cb9

 Use of this shortcode would ensure the link to the correct privacy page is
 displayed no matter how many times the page is switched in the site's
 settings and, in a WPML or similar setup, no matter which part of a site
 the link is displayed.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/50424>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list