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
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
- Scaling
- Constant
- Instructions
- 8–72
- Plugin surface
- None
- Called by
- 0
Reaches the database via get_post().
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 98.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- querycontent query
get_post()called directly - optionoption read or write
get_option()called directly - hookthird-party callbacks
apply_filters()one call below WP_Privacy_Policy_Content::notice() - cacheobject cache
wp_cache_get()one call below WP_Privacy_Policy_Content::notice() - serializeserialisation
maybe_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 · 18 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.
| When | Instructions | Calls it makes |
|---|---|---|
$post === null && !($post instanceof) | 8 | none |
$post !== null && !($post instanceof) | 10 | get_post() |
$post === null && $post instanceof && !current_user_can() | 12 | current_user_can() |
$post !== null && $post instanceof && !current_user_can() | 14 | get_post(), current_user_can() |
$post === null && $post instanceof && current_user_can() | 23–26 | current_user_can(), get_current_screen(), get_option() |
$post !== null && $post instanceof && current_user_can() | 25–28 | get_post(), current_user_can(), get_current_screen(), get_option() |
$post === null && $post instanceof && current_user_can() && get_post() | 27–30 | current_user_can(), get_current_screen(), get_option(), get_post() |
$post === null && $post instanceof && current_user_can() && !get_post() | 28 | current_user_can(), get_current_screen(), get_option(), get_post(), update_option() |
$post !== null && $post instanceof && current_user_can() && get_post() | 29–32 | get_post(), current_user_can(), get_current_screen(), get_option(), get_post() |
$post !== null && $post instanceof && current_user_can() && !get_post() | 30 | get_post(), current_user_can(), get_current_screen(), get_option(), get_post(), update_option() |
$post === null && $post instanceof && current_user_can() && $policy_page_id === false && !->is_block_editor() | 61 | 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() | 63 | get_post(), current_user_can(), get_current_screen(), get_option(), __(), admin_url(), esc_url(), __(), get_current_screen(), ->is_block_editor(), __(), wp_admin_notice() |
6 further outcomes, up to 72 instructions
$post === null && $post instanceof && current_user_can() && get_post() && $policy_page_id === false && !->is_block_editor() | 65 | current_user_can(), get_current_screen(), get_option(), get_post(), __(), 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() | 66 | 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() |
$post !== null && $post instanceof && current_user_can() && get_post() && $policy_page_id === false && !->is_block_editor() | 67 | get_post(), current_user_can(), get_current_screen(), get_option(), get_post(), __(), 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() | 68 | get_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() |
$post === null && $post instanceof && current_user_can() && get_post() && $policy_page_id === false && ->is_block_editor() | 70 | current_user_can(), get_current_screen(), get_option(), get_post(), __(), 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() && get_post() && $policy_page_id === false && ->is_block_editor() | 72 | get_post(), current_user_can(), get_current_screen(), get_option(), get_post(), __(), admin_url(), esc_url(), __(), get_current_screen(), ->is_block_editor(), wp_enqueue_script(), wp_json_encode(), wp_add_inline_script() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 98 | 8–72 | 8 | |
| 8.5 | 98 | 8–72 | 8 | |
| 8.4 | 98 | 8–72 | 8 | 1 more instruction than PHP 8.3 |
| 8.3 | 97 | 8–72 | 8 | |
| 8.2 | 97 | 8–72 | 8 | |
| 8.1 | 97 | 8–72 | 8 | |
| 7.4 | 97 | 8–72 | 8 |
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 · 13
- get_post()Retrieves post data given a post ID or post object.
- current_user_can()Returns whether the current user has the specified capability.
- get_current_screen()Get the current screen object
- get_option()Retrieves an option value based on an option name.
- update_option()Updates the value of an option that was already added.
- __()Retrieves the translation of $text.
- esc_url()Checks and cleans a URL.
- admin_url()Retrieves the URL to the admin area for the current site.
- wp_enqueue_script()Enqueues a script.
- wp_add_inline_script()Adds extra code to a registered script.
- wp_json_encode()Encodes a variable into JSON, with some confidence checks.
- wp_admin_notice()Outputs an admin notice.
Show all 13
- get_current_screen()::is_block_editor()
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 the privacy policy page has been deleted, reset the option and bail. if ( $policy_page_id && ! get_post( $policy_page_id ) ) { update_option( 'wp_page_for_privacy_policy', 0 ); return; } 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.
Signature, return type and hooks compared across 5 parsed releases.
$post parameter was made optional.from the docblockAbout this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 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.