[wp-trac] [WordPress Trac] #52194: Add filter to disable or amend the "Need help putting together your new Privacy Policy page? Check out our guide for recommendations on what content to include, along with policies suggested by your plugins and theme." notice

WordPress Trac noreply at wordpress.org
Wed Dec 30 18:27:05 UTC 2020


#52194: Add filter to disable or amend the "Need help putting together your new
Privacy Policy page? Check out our guide for recommendations on what
content to include, along with policies suggested by your plugins and
theme." notice
-------------------------+------------------------------
 Reporter:  ninetyninew  |       Owner:  (none)
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  Awaiting Review
Component:  Privacy      |     Version:  5.6
 Severity:  normal       |  Resolution:
 Keywords:  close        |     Focuses:  administration
-------------------------+------------------------------
Changes (by garrett-eclipse):

 * keywords:   => close


Comment:

 Hi @ninetyninew I hope this finds you well. The privacy notice you
 mentioned is hooked into admin_notices as the
 WP_Privacy_Policy_Content::notice() function, you can already unhook it to
 remove by adding the following to your functions.php;
 `remove_action( 'admin_notices', array( 'WP_Privacy_Policy_Content',
 'notice' ) );`

 If you'd rather replace it than along with the above removal, add in your
 own notice as follows;
 {{{#!php
 function notice( $post = null ) {
     if ( is_null( $post ) ) {
         global $post;
     } else {
         $post = get_post( $post );
     }

     if ( ! ( $post instanceof WP_Post ) ) {
         return;
     }

     if ( ! current_user_can( 'manage_privacy_options' ) ) {
         return;
     }

     $current_screen = get_current_screen();
     $policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' );

     if ( 'post' !== $current_screen->base || $policy_page_id !== $post->ID
 ) {
         return;
     }

     $message = __( 'This is my customized notice message.' );
     $url     = esc_url( admin_url( 'privacy-policy-guide.php' ) );
     $label   = __( 'View Privacy Policy Guide.' );

     if ( get_current_screen()->is_block_editor() ) {
         wp_enqueue_script( 'wp-notices' );
         $action = array(
             'url'   => $url,
             'label' => $label,
         );
         wp_add_inline_script(
             'wp-notices',
             sprintf(
                 'wp.data.dispatch( "core/notices" ).createWarningNotice(
 "%s", { actions: [ %s ], isDismissible: false } )',
                 $message,
                 wp_json_encode( $action )
             ),
             'after'
         );
     } else {
         ?>
         <div class="notice notice-warning inline wp-pp-notice">
             <p>
             <?php
             echo $message;
             printf(
                 ' <a href="%s" target="_blank">%s <span class="screen-
 reader-text">%s</span></a>',
                 $url,
                 $label,
                 /* translators: Accessibility text. */
                 __( '(opens in a new tab)' )
             );
             ?>
             </p>
         </div>
         <?php
     }
 }
 add_action( 'admin_notices', 'my_custom_pp_notice' );
 }}}
 Note: I just duplicated the WP_Privacy_Policy_Content::notice() function
 for the above customization, I'd suggest going directly to the latest
 version below in case it changes from the time of me writing this.
 Reference - https://github.com/WordPress/wordpress-
 develop/blob/aac637dcdc690050f51cc7cb20f1230bafe4a98d/src/wp-
 admin/includes/class-wp-privacy-policy-content.php#L300-L367

 Do note, it's a longer function as it is handling both Classic Editor and
 Block Editor interfaces.

 Marking as close since it's already possible to achieve the goal with the
 existing hook. Leaving open for now if someone has a good reason an
 additional filter would be beneficial beyond the hook we already have.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/52194#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list