WordPress Privacy Policy Page API: wp_add_privacy_policy_content and get_privacy_policy_url

Suggest privacy policy text from a plugin and link to the policy page

Since WordPress 4.9.6 a site has an official privacy policy page, chosen in Settings → Privacy, and a “Privacy Policy Guide” with text suggestions from core and plugins. A plugin that collects personal data can add its own section to that guide with wp_add_privacy_policy_content(), and link to the policy page from its forms with get_privacy_policy_url(). The site owner then copies the parts that apply into the real policy.

Problem: A contact form plugin stores names, emails and IP addresses, and site owners do not know what to write about it in their privacy policy.

Solution: Call wp_add_privacy_policy_content() on admin_init with a plain description of what the plugin stores and for how long, and print a link to get_privacy_policy_url() next to the form when a policy page is set.

Adding the suggested text

<?php
add_action( 'admin_init', function () {
    if ( ! function_exists( 'wp_add_privacy_policy_content' ) ) {
        return;
    }

    $content  = '<p>' . __( 'When you send a message with the contact form, we store your name, your email address, the message and your IP address.', 'textdomain' ) . '</p>';
    $content .= '<p>' . __( 'The IP address is used to block spam. Messages are deleted after 90 days and are not shared with third parties.', 'textdomain' ) . '</p>';

    wp_add_privacy_policy_content( __( 'HA Contact Form', 'textdomain' ), wp_kses_post( $content ) );
} );

The first argument is the plugin name, shown as the heading of its section in the guide. Write the text for the site’s visitors, not for developers, and describe what the plugin really does: what is stored, why, for how long, and who receives it. Keep it in sync with the plugin; when the text changes, WordPress marks the policy as possibly outdated for the administrator.

Linking to the policy

<?php
function ha_privacy_note() {
    $url = get_privacy_policy_url(); // '' when no page is set or it is not published

    if ( $url ) {
        printf(
            '<p class="ha-privacy-note">%s <a href="%s">%s</a>.</p>',
            esc_html__( 'We handle your data as described in our', 'textdomain' ),
            esc_url( $url ),
            esc_html__( 'privacy policy', 'textdomain' )
        );
    }
}

get_the_privacy_policy_link() (WordPress 4.9.6+) returns a ready <a> tag with the page title, and themes often print it in the footer with the_privacy_policy_link(). The page ID is stored in the wp_page_for_privacy_policy option.

A consent checkbox is a separate decision: under GDPR, a form that only answers the visitor’s own request usually relies on that request, not on consent. Ask a lawyer rather than adding checkboxes to every form.

Export and erase

The guide text is only words. If the plugin stores personal data, it should also register an exporter and an eraser, so the site owner can answer data requests from Tools; how that works is shown in adding plugin data to the privacy export and erase tools.

NOTE: The suggested text never changes the published policy page automatically. It appears only in the guide, and the site owner decides what to copy. When a plugin is removed, its section stays in the guide marked as “removed”, so the owner knows to update the policy.