本文档指导插件开发者如何为收集、使用或存储用户数据的插件添加隐私政策建议文本,以便网站管理员整合到其隐私政策中。核心是通过 wp_add_privacy_policy_content 函数实现,并建议在 admin_init 钩子中调用。
/**
* Adds a privacy policy statement.
*/
function wporg_add_privacy_policy_content() {
if ( ! function_exists( 'wp_add_privacy_policy_content' ) ) {
return;
}
$content = '<p class="privacy-policy-tutorial">' . __( 'Some introductory content for the suggested text.', 'text-domain' ) . '</p>'
. '<strong class="privacy-policy-tutorial">' . __( 'Suggested Text:', 'my_plugin_textdomain' ) . '</strong> '
. sprintf(
__( 'When you leave a comment on this site, we send your name, email address, IP address and comment text to example.com. Example.com does not retain your personal data. The example.com privacy policy is <a href="%1$s" target="_blank">here</a>.', 'text-domain' ),
'https://example.com/privacy-policy'
);
wp_add_privacy_policy_content( 'Example Plugin', wp_kses_post( wpautop( $content, false ) ) );
}
add_action( 'admin_init', 'wporg_add_privacy_policy_content' ); Every plugin that collects, uses, or stores user data, or passes it to an external source or third party, should add a section of suggested text to the privacy policy postbox. This is best done with wp_add_privacy_policy_content( $plugin_name, $policy_text ). This will allow site administrators to pull that information into their site’s privacy policy.
To make this simpler for the users, the text should address the questions provided in the default privacy policy:
While not all of these questions will be applicable to all plugins, we recommend taking care with the sections on data sharing.
.privacy-policy-tutorial CSS class. Any content contained within HTML elements that have this CSS class applied will be omitted from the clipboard when the section content is copied./**
* Adds a privacy policy statement.
*/
function wporg_add_privacy_policy_content() {
if ( ! function_exists( 'wp_add_privacy_policy_content' ) ) {
return;
}
$content = '<p class="privacy-policy-tutorial">' . __( 'Some introductory content for the suggested text.', 'text-domain' ) . '</p>'
. '<strong class="privacy-policy-tutorial">' . __( 'Suggested Text:', 'my_plugin_textdomain' ) . '</strong> '
. sprintf(
__( 'When you leave a comment on this site, we send your name, email address, IP address and comment text to example.com. Example.com does not retain your personal data. The example.com privacy policy is <a href="%1$s" target="_blank">here</a>.', 'text-domain' ),
'https://example.com/privacy-policy'
);
wp_add_privacy_policy_content( 'Example Plugin', wp_kses_post( wpautop( $content, false ) ) );
}
add_action( 'admin_init', 'wporg_add_privacy_policy_content' );