wp_add_privacy_policy_content()
概述
wp_add_privacy_policy_content() 是一个辅助函数,用于向 WordPress 隐私政策指南添加建议内容。插件和主题应使用此函数提供影响用户隐私的功能描述,以帮助网站所有者完善隐私政策。
关键要点
- 函数用于插件或主题向隐私政策指南添加建议文本,需包含影响用户隐私的功能信息。
- 可多次调用以模块化方式呈现内容,例如 WooCommerce 或 Jetpack 根据启用模块调整建议。
- 参数包括 $plugin_name(插件或主题名称)和 $policy_text(建议内容),均为必需字符串。
- 建议内容支持 .privacy-policy-tutorial CSS 类,该类内容在复制时会被省略。
- 应在 'admin_init' 动作钩子中使用,否则会触发 _doing_it_wrong() 警告。
- 函数内部检查环境,确保仅在 wp-admin 中调用,并依赖 WP_Privacy_Policy_Content 类。
代码示例
$policy_text = __( 'Example privacy policy text.', 'example-plugin' );
wp_add_privacy_policy_content( __( 'Example plugin', 'example-plugin' ), $policy_text );注意事项
- 如果插件支持国际化,$plugin_name 参数值应通过翻译函数传递,以确保名称可翻译。
- 参考 Plugin Handbook 获取更多信息:https://developer.wordpress.org/plugins/privacy/suggesting-text-for-the-site-privacy-policy/。
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.
Parameters
$plugin_namestringrequired-
The name of the plugin or theme that is suggesting content for the site’s privacy policy.
$policy_textstringrequired-
The suggested content for inclusion in the policy.
Source
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
| Version | Description |
|---|---|
| 4.9.6 | Introduced. |
Skip to note 2 content
nlpro
Note that if a plugin implements i18n (internationalization/translation) the $plugin_name parameter value needs to be passed to the function using a translation function. Example:
$policy_text = __( 'Example privacy policy text.', 'example-plugin' ); wp_add_privacy_policy_content( __( 'Example plugin', 'example-plugin' ), $policy_text );