WordPress.org

Make WordPress Core

#52194 closed enhancement (invalid)

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

Reported by: ninetyninew Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Privacy Keywords:
Focuses: administration Cc:

Description

On an assigned privacy policy page a notice appears when editing the page:

"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." with a link to a privacy policy guide.

It would be useful to have a filter here to completely remove or amend the text in this message, as this links to WordPress's own privacy policy guide.

If you are building a website for a client you may want to hide this or provide your own privacy policy instructions which aren't WordPress's.

Change History (4)

#1 @SergeyBiryukov
10 months ago

  • Component changed from General to Privacy
  • Focuses administration added

#2 @garrett-eclipse
10 months ago

  • Keywords close added

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;

function my_custom_pp_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.

Last edited 10 months ago by garrett-eclipse (previous) (diff)

#3 follow-up: @ninetyninew
10 months ago

Thanks @garrett-eclipse, I wanted to just remove it completely so this works for me, the only concern would be if the action name was changed for any reason later...?

#4 in reply to: ↑ 3 @garrett-eclipse
10 months ago

  • Keywords close removed
  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed
  • Version 5.6 deleted

Replying to ninetyninew:

Thanks @garrett-eclipse, I wanted to just remove it completely so this works for me, the only concern would be if the action name was changed for any reason later...?

Glad to hear. The admin_notices action is unlikely to change anytime soon, but any of those changes would be made with back-compat in mind so you shouldn't see a fatal in future.
Going to close this.

Note: See TracTickets for help on using tickets.