Halloween Sale 15% off Ends in See the plans
PHP

Tell Visitors When the Privacy Policy Changes

Shows a small dismissible notice linking to your privacy policy whenever the policy page has been updated since the visitor last dismissed it. Logged-in users' choice is saved to their profile.

Don’t have WPIDE yet? Install it on your site

Code

add_action( 'wp_footer', function () {
    $page_id = (int) get_option( 'wp_page_for_privacy_policy' );

    if ( ! $page_id || 'publish' !== get_post_status( $page_id ) || is_page( $page_id ) ) {
        return;
    }

    $version = (string) get_post_modified_time( 'U', true, $page_id );

    if ( is_user_logged_in() && get_user_meta( get_current_user_id(), 'wpide_policy_seen', true ) === $version ) {
        return;
    }
    ?>
<div id="wpide-policy-update" role="region" aria-label="Privacy policy update" hidden style="position:fixed;left:12px;right:12px;bottom:12px;z-index:99980;max-width:560px;margin:0 auto;padding:12px 16px;border-radius:8px;background:#fff;color:#1d2327;box-shadow:0 4px 20px rgba(0,0,0,.2);font-size:15px;">
    We have updated our <a href="<?php echo esc_url( get_permalink( $page_id ) ); ?>">privacy policy</a>.
    <button type="button" style="margin-left:8px;" data-version="<?php echo esc_attr( $version ); ?>">OK</button>
</div>
<script>
(function () {
    var box = document.getElementById('wpide-policy-update');
    var btn = box.querySelector('button');
    var version = btn.getAttribute('data-version');
    var seen = '';
    try { seen = localStorage.getItem('wpidePolicySeen') || ''; } catch (e) {}
    if (seen === version) { return; }
    box.hidden = false;
    btn.addEventListener('click', function () {
        box.hidden = true;
        try { localStorage.setItem('wpidePolicySeen', version); } catch (e) {}
        <?php if ( is_user_logged_in() ) : ?>
        var body = new URLSearchParams({ action: 'wpide_policy_seen', version: version, _ajax_nonce: <?php echo wp_json_encode( wp_create_nonce( 'wpide_policy_seen' ) ); ?> });
        fetch(<?php echo wp_json_encode( admin_url( 'admin-ajax.php' ) ); ?>, { method: 'POST', body: body, credentials: 'same-origin' });
        <?php endif; ?>
    });
})();
</script>
    <?php
} );

add_action( 'wp_ajax_wpide_policy_seen', function () {
    check_ajax_referer( 'wpide_policy_seen' );
    update_user_meta( get_current_user_id(), 'wpide_policy_seen', isset( $_POST['version'] ) ? sanitize_text_field( wp_unslash( $_POST['version'] ) ) : '' );
    wp_send_json_success();
} );

Notes

Only shown once a privacy policy page is set in Settings > Privacy; it reappears each time you update that page.

How to add this snippet

  1. Install WPIDE on your WordPress site (it is free) and open Code Snippets.
  2. Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
  3. It is added inactive: review the code and settings, then switch it on.

Have a snippet worth sharing?

Publish it to the library from WPIDE or right here. Sign in with any WordPress site that runs WPIDE, free or Pro. Public snippets are reviewed by the WPIDE team before they appear.

Which site should get this snippet?

Enter the address of your WordPress site. WPIDE opens there in a new tab with the snippet ready to review and save.

Remembered in this browser only, so you are asked once.

Report this snippet

Tell the WPIDE team what is wrong: broken code, something harmful, spam or copied work.