Skip to:
Content

BuddyPress.org

Changeset 12112


Ignore:
Timestamp:
05/23/2018 02:37:41 AM (8 years ago)
Author:
boonebgorges
Message:

Privacy: Data exporter for Activity.

See #7818.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-activity/bp-activity-filters.php

    r12067 r12112  
    109109
    110110add_filter( 'bp_activity_get_embed_excerpt', 'bp_activity_embed_excerpt_onclick_location_filter', 9 );
     111
     112// Personal data export.
     113add_filter( 'wp_privacy_personal_data_exporters', 'bp_activity_register_personal_data_exporter' );
    111114
    112115/* Actions *******************************************************************/
     
    803806}
    804807add_filter( 'bp_activity_set_mentions_scope_args', 'bp_activity_filter_mentions_scope', 10, 2 );
     808
     809/**
     810 * Registers Activity personal data exporter.
     811 *
     812 * @since 4.0.0
     813 *
     814 * @param array $exporters  An array of personal data exporters.
     815 * @return array An array of personal data exporters.
     816 */
     817function bp_activity_register_personal_data_exporter( $exporters ) {
     818        $exporters['buddypress-activity'] = array(
     819                'exporter_friendly_name' => __( 'BuddyPress Activity Data', 'buddypress' ),
     820                'callback'               => 'bp_activity_personal_data_exporter',
     821        );
     822
     823        return $exporters;
     824}
  • trunk/src/bp-activity/bp-activity-functions.php

    r11883 r12112  
    41564156}
    41574157add_action( 'transition_comment_status', 'bp_activity_transition_post_type_comment_status', 10, 3 );
     4158
     4159/**
     4160 * Finds and exports personal data associated with an email address from the Activity tables.
     4161 *
     4162 * @since 4.0.0
     4163 *
     4164 * @param string $email_address  The user's email address.
     4165 * @param int    $page           Batch number.
     4166 * @return array An array of personal data.
     4167 */
     4168function bp_activity_personal_data_exporter( $email_address, $page ) {
     4169        $number = 50;
     4170
     4171        $email_address = trim( $email_address );
     4172
     4173        $data_to_export = array();
     4174
     4175        $user = get_user_by( 'email', $email_address );
     4176
     4177        if ( ! $user ) {
     4178                return array(
     4179                        'data' => array(),
     4180                        'done' => true,
     4181                );
     4182        }
     4183
     4184        $activities = bp_activity_get( array(
     4185                'display_comments' => 'stream',
     4186                'per_page'         => $number,
     4187                'page'             => $page,
     4188                'show_hidden'      => true,
     4189                'filter'           => array(
     4190                        'user_id' => $user->ID,
     4191                ),
     4192        ) );
     4193
     4194        $user_data_to_export = array();
     4195        $activity_actions    = bp_activity_get_actions();
     4196
     4197        foreach ( $activities['activities'] as $activity ) {
     4198                if ( ! empty( $activity_actions->{$activity->component}->{$activity->type}['format_callback'] ) ) {
     4199                        $description = call_user_func( $activity_actions->{$activity->component}->{$activity->type}['format_callback'], '', $activity );
     4200                } elseif ( ! empty( $activity->action ) ) {
     4201                        $description = $activity->action;
     4202                } else {
     4203                        $description = $activity->type;
     4204                }
     4205
     4206                $item_data = array(
     4207                        array(
     4208                                'name'  => __( 'Activity Date', 'buddypress' ),
     4209                                'value' => $activity->date_recorded,
     4210                        ),
     4211                        array(
     4212                                'name'  => __( 'Activity Description', 'buddypress' ),
     4213                                'value' => $description,
     4214                        ),
     4215                        array(
     4216                                'name'  => __( 'Activity URL', 'buddypress' ),
     4217                                'value' => bp_activity_get_permalink( $activity->id, $activity ),
     4218                        ),
     4219                );
     4220
     4221                if ( ! empty( $activity->content ) ) {
     4222                        $item_data[] = array(
     4223                                'name'  => __( 'Activity Content', 'buddypress' ),
     4224                                'value' => $activity->content,
     4225                        );
     4226                }
     4227
     4228                /**
     4229                 * Filters the data associated with an activity item when assembled for a WP personal data export.
     4230                 *
     4231                 * Plugins that register activity types whose `action` string doesn't adequately
     4232                 * describe the activity item for the purposes of data export may filter the activity
     4233                 * item data here.
     4234                 *
     4235                 * @since 4.0.0
     4236                 *
     4237                 * @param array                $item_data Array of data describing the activity item.
     4238                 * @param BP_Activity_Activity $activity  Activity item.
     4239                 */
     4240                $item_data = apply_filters( 'bp_activity_personal_data_export_item_data', $item_data, $activity );
     4241
     4242                $data_to_export[] = array(
     4243                        'group_id'    => 'bp_activity',
     4244                        'group_label' => __( 'Activity' ),
     4245                        'item_id'     => "bp-activity-{$activity->id}",
     4246                        'data'        => $item_data,
     4247                );
     4248        }
     4249
     4250        // Tell core if we have more items to process.
     4251        $done = count( $activities['activities'] ) < $number;
     4252
     4253        return array(
     4254                'data' => $data_to_export,
     4255                'done' => $done,
     4256        );
     4257}
  • trunk/tests/phpunit/testcases/activity/functions.php

    r11806 r12112  
    16081608                }
    16091609        }
     1610
     1611        /**
     1612         * @ticket BP7818
     1613         * @ticket BP7698
     1614         */
     1615        public function test_bp_activity_personal_data_exporter() {
     1616                $u = self::factory()->user->create();
     1617
     1618                $a1 = self::factory()->activity->create(
     1619                        array(
     1620                                'user_id'   => $u,
     1621                                'component' => 'activity',
     1622                                'type'      => 'activity_update',
     1623                        )
     1624                );
     1625
     1626                $a2 = self::factory()->activity->create(
     1627                        array(
     1628                                'user_id'           => $u,
     1629                                'component'         => 'activity',
     1630                                'type'              => 'activity_comment',
     1631                                'item_id'           => $a1,
     1632                                'secondary_item_id' => $a1,
     1633                        )
     1634                );
     1635
     1636                $g = self::factory()->group->create(
     1637                        array(
     1638                                'name' => 'My Cool Group',
     1639                        )
     1640                );
     1641
     1642                $a3 = self::factory()->activity->create(
     1643                        array(
     1644                                'user_id'   => $u,
     1645                                'component' => 'groups',
     1646                                'type'      => 'activity_update',
     1647                                'item_id'   => $g,
     1648                        )
     1649                );
     1650
     1651                $test_user = new WP_User( $u );
     1652
     1653                $actual = bp_activity_personal_data_exporter( $test_user->user_email, 1 );
     1654
     1655                $this->assertTrue( $actual['done'] );
     1656
     1657                // Number of exported activity items.
     1658                $this->assertSame( 3, count( $actual['data'] ) );
     1659        }
    16101660}
Note: See TracChangeset for help on using the changeset viewer.