wppaste
WordPress

wp_add_privacy_policy_content( string $plugin_name, string $policy_text )

Since
4.9.6
Source
wp-admin/includes/plugin.php:2416
Declares a helper function for adding content to the Privacy Policy Guide.

Description

Plugins and themes should suggest text for inclusion in the site's privacy policy.
The suggested text should contain information about any functionality that affects user privacy, and will be shown on the Privacy Policy Guide screen.

A plugin or theme can use this function multiple times as long as it will help to better present the suggested policy content. For example modular plugins such as WooCommerse or Jetpack can add or remove suggested content depending on the modules/extensions that are enabled.
For more information see the Plugin Handbook: https://developer.wordpress.org/plugins/privacy/suggesting-text-for-the-site-privacy-policy/.

The HTML contents of the $policy_text supports use of a specialized .privacy-policy-tutorial CSS class which can be used to provide supplemental information. Any content contained within HTML elements that have the .privacy-policy-tutorial CSS class applied will be omitted from the clipboard when the section content is copied.

Intended for use with the 'admin_init' action.

Compatibility

WordPress
since 4.9.6
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

$plugin_namestring
The name of the plugin or theme that is suggesting content for the site's privacy policy.
$policy_textstring
The suggested content for inclusion in the policy.

Performance profile

How much work a call to wp_add_privacy_policy_content() 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
Trivial

Touches nothing outside its own arguments.

Scaling
Constant

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

Instructions
16–26

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

Plugin surface
None

Nothing here hands control to plugin code.

Called by
2

2 places in core call this, so the cost is paid more often than your own code shows.

What it touches

  • hookthird-party callbacksdo_action()one call below wp_add_privacy_policy_content()

Further down the call graph this can also reach query, option, cache, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 4 distinct outcomes

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

WhenInstructionsCalls it makes
is_admin() && doing_action()16–19is_admin(), doing_action(), ::WP_Privacy_Policy_Content()
!is_admin()18is_admin(), __(), sprintf(), _doing_it_wrong()
is_admin() && !doing_action() && did_action()20–23is_admin(), doing_action(), did_action(), ::WP_Privacy_Policy_Content()
is_admin() && !doing_action() && !did_action()26is_admin(), doing_action(), did_action(), __(), sprintf(), _doing_it_wrong()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev4916–264
8.54916–264
8.44916–2642 fewer instructions than PHP 8.3
8.35118–264
8.25118–264
8.15118–264
7.45118–264

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 · 6

  • is_admin()Determines whether the current request is for an administrative interface page.
  • _doing_it_wrong()Marks something as being incorrectly called.
  • __()Retrieves the translation of $text.
  • doing_action()Returns whether or not an action hook is currently being processed.
  • did_action()Retrieves the number of times an action has been fired during the current request.
  • WP_Privacy_Policy_Content::add()Adds content to the postbox shown when editing the privacy policy.

Used by · 2

Source code

function wp_add_privacy_policy_content( $plugin_name, $policy_text ) {	if ( ! is_admin() ) {		_doing_it_wrong(			__FUNCTION__,			sprintf(				/* translators: %s: admin_init */				__( 'The suggested privacy policy content should be added only in wp-admin by using the %s (or later) action.' ),				'<code>admin_init</code>'			),			'4.9.7'		);		return;	} elseif ( ! doing_action( 'admin_init' ) && ! did_action( 'admin_init' ) ) {		_doing_it_wrong(			__FUNCTION__,			sprintf(				/* translators: %s: admin_init */				__( 'The suggested privacy policy content should be added by using the %s (or later) action. Please see the inline documentation.' ),				'<code>admin_init</code>'			),			'4.9.7'		);		return;	} 	if ( ! class_exists( 'WP_Privacy_Policy_Content' ) ) {		require_once ABSPATH . 'wp-admin/includes/class-wp-privacy-policy-content.php';	} 	WP_Privacy_Policy_Content::add( $plugin_name, $policy_text );}

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.

About this page

Parsed data
Generated from the wordpress-develop 6.8.8 tag, from src/wp-admin/includes/plugin.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.