wppaste
WordPress

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

Since
4.9.6, 5.0.0
Source
wp-admin/includes/class-wp-privacy-policy-content.php:314
Adds a notice with a link to the guide when editing the privacy policy page.

Compatibility

WordPress
since 5.0.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$postWP_Post|nulloptional
The currently edited post. Default null.Default: null

Performance profile

How much work a call to WP_Privacy_Policy_Content::notice() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Heavy

Reaches the database via get_post().

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
8–67

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 88.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • querycontent queryget_post()called directly
  • optionoption read or writeget_option()called directly
  • hookthird-party callbacksapply_filters()one call below WP_Privacy_Policy_Content::notice()
  • cacheobject cachewp_cache_get()one call below WP_Privacy_Policy_Content::notice()
  • serializeserialisationmaybe_unserialize()one call below WP_Privacy_Policy_Content::notice()

Further down the call graph this can also reach transient. That is the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 10 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Privacy_Policy_Content::notice() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
$post === null && !($post instanceof)8none
$post !== null && !($post instanceof)10get_post()
$post === null && $post instanceof && !current_user_can()12current_user_can()
$post !== null && $post instanceof && !current_user_can()14get_post(), current_user_can()
$post === null && $post instanceof && current_user_can()22–25current_user_can(), get_current_screen(), get_option()
$post !== null && $post instanceof && current_user_can()24–27get_post(), current_user_can(), get_current_screen(), get_option()
$post === null && $post instanceof && current_user_can() && $policy_page_id === false && !->is_block_editor()60current_user_can(), get_current_screen(), get_option(), __(), admin_url(), esc_url(), __(), get_current_screen(), ->is_block_editor(), __(), wp_admin_notice()
$post !== null && $post instanceof && current_user_can() && $policy_page_id === false && !->is_block_editor()62get_post(), current_user_can(), get_current_screen(), get_option(), __(), admin_url(), esc_url(), __(), get_current_screen(), ->is_block_editor(), __(), wp_admin_notice()
$post === null && $post instanceof && current_user_can() && $policy_page_id === false && ->is_block_editor()65current_user_can(), get_current_screen(), get_option(), __(), admin_url(), esc_url(), __(), get_current_screen(), ->is_block_editor(), wp_enqueue_script(), wp_json_encode(), wp_add_inline_script()
$post !== null && $post instanceof && current_user_can() && $policy_page_id === false && ->is_block_editor()67get_post(), current_user_can(), get_current_screen(), get_option(), __(), admin_url(), esc_url(), __(), get_current_screen(), ->is_block_editor(), wp_enqueue_script(), wp_json_encode(), wp_add_inline_script()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev888–676
8.5888–676
8.4888–6761 more instruction than PHP 8.3
8.3878–676
8.2878–676
8.1878–676
7.4878–676

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Uses · 12

Source code

	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 the 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, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES )				),				'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' ),				)			);		}	}

Changelog

Introduced in 4.9.6. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

5.0.0
The $post parameter was made optional.from the docblock
4.9.6
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 7.0.4 tag, from src/wp-admin/includes/class-wp-privacy-policy-content.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.