WP_Privacy_Policy_Content::notice()public staticWP 4.9.6

Adds a notice with a link to the guide when editing the privacy policy page.

Method of the class: WP_Privacy_Policy_Content{}

No Hooks.

Return

null. Nothing (null).

Usage

$result = WP_Privacy_Policy_Content::notice( $post );
$post(WP_Post|null)
The currently edited post.
Default: null

Notes

  • Global. WP_Post. $post Global post object.

Changelog

Since 4.9.6 Introduced.
Since 5.0.0 The $post parameter was made optional.

WP_Privacy_Policy_Content::notice() code WP 6.4.3

public static 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 = __( '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.' );
	$url     = esc_url( admin_url( 'options-privacy.php?tab=policyguide' ) );
	$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 {
		$message .= sprintf(
			' <a href="%s" target="_blank">%s <span class="screen-reader-text">%s</span></a>',
			$url,
			$label,
			/* translators: Hidden accessibility text. */
			__( '(opens in a new tab)' )
		);
		wp_admin_notice(
			$message,
			array(
				'type'               => 'warning',
				'additional_classes' => array( 'inline', 'wp-pp-notice' ),
			)
		);
	}
}