Skip to:
Content

BuddyPress.org

Changeset 12272


Ignore:
Timestamp:
11/02/2018 02:17:03 PM (6 years 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.

Location:
trunk/src
Files:
4 added
5 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}
  • trunk/src/bp-settings/classes/class-bp-settings-component.php

    r12159 r12272  
    6767        }
    6868
    69         $actions = array( 'notifications', 'capabilities', 'delete-account' );
     69        $actions = array( 'notifications', 'capabilities', 'data', 'delete-account' );
    7070
    7171        // Authenticated actions.
     
    184184        }
    185185
     186        /**
     187         * Filter whether the site should show the "Settings > Data" page.
     188         *
     189         * @since 4.0.0
     190         *
     191         * @param bool $show Defaults to true.
     192         */
     193        $show_data_page = apply_filters( 'bp_settings_show_user_data_page', true );
     194
     195        // Export Data - only available for WP 4.9.6+.
     196        if ( true === $show_data_page && version_compare( $GLOBALS['wp_version'], '4.9.6', '>=' ) ) {
     197            $sub_nav[] = array(
     198                'name'            => __( 'Export Data', 'buddypress' ),
     199                'slug'            => 'data',
     200                'parent_url'      => $settings_link,
     201                'parent_slug'     => $slug,
     202                'screen_function' => 'bp_settings_screen_data',
     203                'position'        => 89,
     204                'user_has_access' => $access,
     205            );
     206        }
     207
    186208        // Add Delete Account nav item.
    187209        if ( ( ! bp_disable_account_deletion() && bp_is_my_profile() ) || bp_current_user_can( 'delete_users' ) ) {
     
    243265            }
    244266
     267            /** This filter is documented in bp-settings/classes/class-bp-settings-component.php */
     268            $show_data_page = apply_filters( 'bp_settings_show_user_data_page', true );
     269
     270            // Export Data.
     271            if ( true === $show_data_page && version_compare( $GLOBALS['wp_version'], '4.9.6', '>=' ) ) {
     272                $wp_admin_nav[] = array(
     273                    'parent'   => 'my-account-' . $this->id,
     274                    'id'       => 'my-account-' . $this->id . '-data',
     275                    'title'    => __( 'Export Data', 'buddypress' ),
     276                    'href'     => trailingslashit( $settings_link . 'data' ),
     277                    'position' => 89,
     278                );
     279            }
     280
    245281            // Delete Account
    246282            if ( !bp_current_user_can( 'bp_moderate' ) && ! bp_core_get_root_option( 'bp-disable-account-deletion' ) ) {
  • trunk/src/bp-templates/bp-legacy/buddypress/members/single/settings.php

    r12082 r12272  
    3838        bp_get_template_part( 'members/single/settings/profile'        );
    3939        break;
     40    case 'data'           :
     41        bp_get_template_part( 'members/single/settings/data'           );
     42        break;
    4043    default:
    4144        bp_get_template_part( 'members/single/plugins'                 );
  • trunk/src/bp-templates/bp-nouveau/buddypress/members/single/settings.php

    r12082 r12272  
    33 * BuddyPress - Users Settings
    44 *
    5  * @version 3.0.0
     5 * @version 4.0.0
    66 */
    77
     
    4040        bp_get_template_part( 'members/single/settings/group-invites' );
    4141        break;
     42    case 'data':
     43        bp_get_template_part( 'members/single/settings/data' );
     44        break;
    4245    default:
    4346        bp_get_template_part( 'members/single/plugins' );
  • trunk/src/bp-templates/bp-nouveau/buddypress/members/single/settings/delete-account.php

    r12189 r12272  
    44 *
    55 * @since 3.0.0
    6  * @version 3.1.0
     6 * @version 4.0.0
    77 */
    88
     
    1717<form action="<?php echo esc_url( bp_displayed_user_domain() . bp_get_settings_slug() . '/delete-account' ); ?>" name="account-delete-form" id="#account-delete-form" class="standard-form" method="post">
    1818
    19     <label class="warn" for="delete-account-understand">
    20         <input id="delete-account-understand" class="disabled" type="checkbox" name="delete-account-understand" value="1" data-bp-disable-input="#delete-account-button" />
     19    <label id="delete-account-understand" class="warn" for="delete-account-understand">
     20        <input class="disabled" type="checkbox" name="delete-account-understand" value="1" data-bp-disable-input="#delete-account-button" />
    2121        <?php esc_html_e( 'I understand the consequences.', 'buddypress' ); ?>
    2222    </label>
Note: See TracChangeset for help on using the changeset viewer.