Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
11/02/2018 02:17:03 PM (14 months ago)
Author:
boonebgorges
Message:

Privacy: Introduce 'Export Data' settings panel.

This new panel allows users to request a data export. It also has
information on deleting one's personal data, which in BuddyPress means
deleting one's account.

Props r-a-y.
Fixes #7826.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-settings/bp-settings-functions.php

    r12159 r12272  
    216216    );
    217217}
     218
     219/**
     220 * Fetches a user's personal data request.
     221 *
     222 * @since 4.0.0
     223 *
     224 * @param int WP user ID.
     225 * @return WP_User_Request|false WP_User_Request object on success, boolean false on failure.
     226 */
     227function bp_settings_get_personal_data_request( $user_id = 0 ) {
     228    if ( empty( $user_id ) ) {
     229        $user_id = bp_displayed_user_id();
     230    }
     231
     232    if ( empty( $user_id ) ) {
     233        return false;
     234    }
     235
     236    $user = get_userdata( $user_id );
     237    if ( empty( $user ) ) {
     238        return false;
     239    }
     240
     241    $query = new WP_Query( array(
     242        'author'        => (int) $user_id,
     243        'post_type'     => 'user_request',
     244        'post_status'   => 'any',
     245        'post_name__in' => array(
     246            'export_personal_data',
     247        ),
     248    ) );
     249
     250    if ( ! empty( $query->post ) ) {
     251        return wp_get_user_request_data( $query->post->ID );
     252    } else {
     253        return false;
     254    }
     255}
     256
     257/**
     258 * Fetches the expiration date for when a user request expires.
     259 *
     260 * @since 4.0.0
     261 *
     262 * @param WP_User_Request $request User request object.
     263 * @return string Formatted date.
     264 */
     265function bp_settings_get_personal_data_expiration_date( WP_User_Request $request ) {
     266    /** This filter is documented in wp-admin/includes/file.php */
     267    $expiration = apply_filters( 'wp_privacy_export_expiration', 3 * DAY_IN_SECONDS );
     268
     269    return bp_format_time( $request->completed_timestamp + $expiration, true );
     270}
     271
     272/**
     273 * Fetches the confirmation date for a user request object.
     274 *
     275 * @since 4.0.0
     276 *
     277 * @param WP_User_Request $request User request object.
     278 * @return string Formatted date for the confirmation date.
     279 */
     280function bp_settings_get_personal_data_confirmation_date( WP_User_Request $request ) {
     281    return bp_format_time( $request->confirmed_timestamp, true );
     282}
     283
     284/**
     285 * Fetches the URL for a personal data export file.
     286 *
     287 * @since 4.0.0
     288 *
     289 * @param WP_User_Request $request User request object.
     290 * @return string Export file URL.
     291 */
     292function bp_settings_get_personal_data_export_url( WP_User_Request $request ) {
     293    return get_post_meta( $request->ID, '_export_file_url', true );
     294}
     295
     296/**
     297 * Check if the generated data export file still exists or not.
     298 *
     299 * @since 4.0.0
     300 *
     301 * @param  WP_User_Request $request User request object.
     302 * @return bool
     303 */
     304function bp_settings_personal_data_export_exists( WP_User_Request $request ) {
     305    $file = get_post_meta( $request->ID, '_export_file_path', true );
     306    if ( file_exists( $file ) ) {
     307        return true;
     308    } else {
     309        return false;
     310    }
     311}
     312
     313/**
     314 * Template tag to output a list of data exporter items.
     315 *
     316 * Piggybacks off of the 'wp_privacy_personal_data_exporters' filter and the
     317 * 'exporter_friendly_name' key, which is meant for the admin area.
     318 *
     319 * @todo We should look for a custom key like 'exporter_frontend_name' if available.
     320 *
     321 * @since 4.0.0
     322 */
     323function bp_settings_data_exporter_items() {
     324    /** This filter is documented in /wp-admin/includes/ajax-actions.php */
     325    $exporters = apply_filters( 'wp_privacy_personal_data_exporters', array() );
     326
     327?>
     328    <ul>
     329    <?php foreach ( $exporters as $exporter => $data ) :
     330        /**
     331         * Filters the data exporter name for display on the "Settings > Data" page.
     332         *
     333         * @since 4.0.0
     334         *
     335         * @param string $name     Data exporter friendly name.
     336         * @param string $exporter Internal exporter name.
     337         */
     338        $item = apply_filters( 'bp_settings_data_exporter_name', esc_html( $data['exporter_friendly_name'] ), $exporter );
     339    ?>
     340
     341        <li><?php echo $item; ?></li>
     342
     343    <?php endforeach; ?>
     344    </ul>
     345
     346<?php
     347}
Note: See TracChangeset for help on using the changeset viewer.