Skip to:
Content

BuddyPress.org

Ticket #7823: 7823.diff

File 7823.diff, 5.2 KB (added by boonebgorges, 2 years ago)
  • new file src/bp-settings/bp-settings-filters.php

    diff --git a/src/bp-settings/bp-settings-filters.php b/src/bp-settings/bp-settings-filters.php
    new file mode 100644
    index 000000000..2c9d1e573
    - +  
     1<?php
     2
     3/**
     4 * Filters related to the Settings component.
     5 *
     6 * @since 4.0.0
     7 */
     8
     9// Personal data export.
     10add_filter( 'wp_privacy_personal_data_exporters', 'bp_settings_register_personal_data_exporter' );
     11
     12/**
     13 * Registers Settings personal data exporter.
     14 *
     15 * @since 4.0.0
     16 *
     17 * @param array $exporters  An array of personal data exporters.
     18 * @return array An array of personal data exporters.
     19 */
     20function bp_settings_register_personal_data_exporter( $exporters ) {
     21        $exporters['buddypress-settings'] = array(
     22                'exporter_friendly_name' => __( 'BuddyPress Settings Data', 'buddypress' ),
     23                'callback'               => 'bp_settings_personal_data_exporter',
     24        );
     25
     26        return $exporters;
     27}
  • src/bp-settings/bp-settings-functions.php

    diff --git a/src/bp-settings/bp-settings-functions.php b/src/bp-settings/bp-settings-functions.php
    index 0a7fb5318..c792d9126 100644
    a b function bp_settings_get_registered_notification_keys() { 
    108108
    109109        return $key_whitelist;
    110110}
     111
     112/**
     113 * Finds and exports personal data associated with an email address from the Settings component.
     114 *
     115 * @since 4.0.0
     116 *
     117 * @param string $email_address  The user's email address.
     118 * @param int    $page           Batch number.
     119 * @return array An array of personal data.
     120 */
     121function bp_settings_personal_data_exporter( $email_address, $page ) {
     122        $email_address = trim( $email_address );
     123
     124        $data_to_export = array();
     125
     126        $user = get_user_by( 'email', $email_address );
     127
     128        if ( ! $user ) {
     129                return array(
     130                        'data' => array(),
     131                        'done' => true,
     132                );
     133        }
     134
     135        $yes = __( 'Yes', 'buddypress' );
     136        $no  = __( 'No', 'buddypress' );
     137
     138        $user_settings = array();
     139
     140        // These settings all default to 'yes' when nothing is saved, so we have to do some pre-processing.
     141        $notification_settings = array();
     142
     143        if ( bp_is_active( 'activity' ) ) {
     144                $notification_settings[] = array(
     145                        'name' => __( 'Receive email when a member mentions you in an update?', 'buddypress' ),
     146                        'key'  => 'notification_activity_new_mention',
     147                );
     148                $notification_settings[] = array(
     149                        'name' => __( 'Receive email when a member replies to an update or comment you\'ve posted?', 'buddypress' ),
     150                        'key'  => 'notification_activity_new_reply',
     151                );
     152        }
     153
     154        if ( bp_is_active( 'messages' ) ) {
     155                $notification_settings[] = array(
     156                        'name' => __( 'Receive email when a member sends you a new message?', 'buddypress' ),
     157                        'key'  => 'notification_messages_new_message',
     158                );
     159        }
     160
     161        if ( bp_is_active( 'friends' ) ) {
     162                $notification_settings[] = array(
     163                        'name' => __( 'Receive email when a member invites you to join a group?', 'buddypress' ),
     164                        'key'  => 'notification_groups_invite',
     165                );
     166        }
     167
     168        if ( bp_is_active( 'groups' ) ) {
     169                $notification_settings[] = array(
     170                        'name' => __( 'Receive email when group information is updated?', 'buddypress' ),
     171                        'key'  => 'notification_groups_group_updated',
     172                );
     173                $notification_settings[] = array(
     174                        'name' => __( 'Receive email when you are promoted to a group administrator or moderator?', 'buddypress' ),
     175                        'key'  => 'notification_groups_admin_promoted',
     176                );
     177                $notification_settings[] = array(
     178                        'name' => __( 'Receive email when a member requests to join a private group for which you are an admin?', 'buddypress' ),
     179                        'key'  => 'notification_groups_membership_request',
     180                );
     181                $notification_settings[] = array(
     182                        'name' => __( 'Receive email when your request to join a group has been approved or denied?', 'buddypress' ),
     183                        'key'  => 'notification_membership_request_completed',
     184                );
     185        }
     186
     187        foreach ( $notification_settings as $notification_setting ) {
     188                $user_notification_setting = bp_get_user_meta( $user->ID, $notification_setting['key'], true );
     189                if ( empty( $user_notification_setting ) ) {
     190                        $user_notification_setting = 'yes';
     191                }
     192
     193                $user_settings[] = array(
     194                        'name'  => $notification_setting['name'],
     195                        'value' => 'yes' === $user_notification_setting ? $yes : $no,
     196                );
     197        }
     198
     199        if ( function_exists( 'bp_nouveau_groups_get_group_invites_setting' ) ) {
     200                $user_settings[] = array(
     201                        'name'  => __( 'Receive group invitations from my friends only?', 'buddypress' ),
     202                        'value' => bp_nouveau_groups_get_group_invites_setting() ? $yes : $no,
     203                );
     204        }
     205
     206        $data_to_export[] = array(
     207                'group_id'    => 'bp_settings',
     208                'group_label' => __( 'Settings', 'buddypress' ),
     209                'item_id'     => "bp-settings-{$user->ID}",
     210                'data'        => $user_settings,
     211        );
     212
     213        return array(
     214                'data' => $data_to_export,
     215                'done' => true,
     216        );
     217}
  • src/bp-settings/classes/class-bp-settings-component.php

    diff --git a/src/bp-settings/classes/class-bp-settings-component.php b/src/bp-settings/classes/class-bp-settings-component.php
    index 6439ab980..4176aa4e2 100644
    a b class BP_Settings_Component extends BP_Component { 
    4343        public function includes( $includes = array() ) {
    4444                parent::includes( array(
    4545                        'template',
     46                        'filters',
    4647                        'functions',
    4748                ) );
    4849        }