WP_Privacy_Policy_Content::notice() WordPress Method

The WP_Privacy_Policy_Content::notice() method is used to display a notice about the content of the privacy policy. This notice will be displayed at the top of the privacy policy page, above the content. It is important to note that this notice is not displayed if the user is not logged in.

WP_Privacy_Policy_Content::notice( WP_Post|null $post = null ) #

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


Parameters

$post

(WP_Post|null)(Optional)The currently edited post.

Default value: null


Top ↑

Source

File: wp-admin/includes/class-wp-privacy-policy-content.php

	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 {
			?>
			<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
		}
	}


Top ↑

Changelog

Changelog
VersionDescription
5.0.0The $post parameter was made optional.
4.9.6Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.