Changeset 12164
- Timestamp:
- 06/04/2018 08:54:02 PM (6 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-messages/bp-messages-filters.php
r12067 r12164 80 80 add_filter( 'bp_get_message_thread_content', 'stripslashes_deep', 1 ); 81 81 82 // Personal data export. 83 add_filter( 'wp_privacy_personal_data_exporters', 'bp_messages_register_personal_data_exporter' ); 84 82 85 /** 83 86 * Enforce limitations on viewing private message contents … … 127 130 return wp_kses( $content, $messages_allowedtags ); 128 131 } 132 133 /** 134 * Register Messages personal data exporter. 135 * 136 * @since 4.0.0 137 * 138 * @param array $exporters An array of personal data exporters. 139 * @return array An array of personal data exporters. 140 */ 141 function bp_messages_register_personal_data_exporter( $exporters ) { 142 $exporters['buddypress-messages'] = array( 143 'exporter_friendly_name' => __( 'BuddyPress Messages', 'buddypress' ), 144 'callback' => 'bp_messages_personal_data_exporter', 145 ); 146 147 return $exporters; 148 } -
trunk/src/bp-messages/bp-messages-functions.php
r12139 r12164 631 631 } 632 632 add_action( 'messages_message_sent', 'messages_notification_new_message', 10 ); 633 634 /** 635 * Finds and exports personal data associated with an email address from the Messages tables. 636 * 637 * @since 4.0.0 638 * 639 * @param string $email_address The user's email address. 640 * @param int $page Batch number. 641 * @return array An array of personal data. 642 */ 643 function bp_messages_personal_data_exporter( $email_address, $page ) { 644 $number = 10; 645 646 $email_address = trim( $email_address ); 647 648 $data_to_export = array(); 649 650 $user = get_user_by( 'email', $email_address ); 651 652 if ( ! $user ) { 653 return array( 654 'data' => array(), 655 'done' => true, 656 ); 657 } 658 659 $user_data_to_export = array(); 660 661 $user_threads = BP_Messages_Thread::get_current_threads_for_user( array( 662 'user_id' => $user->ID, 663 'box' => 'sentbox', 664 'type' => null, 665 'limit' => $number, 666 'page' => $page, 667 ) ); 668 669 foreach ( $user_threads['threads'] as $thread ) { 670 $recipient_links = array(); 671 foreach ( $thread->recipients as $recipient ) { 672 if ( $recipient->user_id === $user->ID ) { 673 continue; 674 } 675 676 $recipient_links[] = bp_core_get_userlink( $recipient->user_id ); 677 } 678 $recipients = implode( ', ', $recipient_links ); 679 680 $thread_link = bp_get_message_thread_view_link( $thread->thread_id, $user->ID ); 681 682 foreach ( $thread->messages as $message_index => $message ) { 683 // Only include messages written by the user. 684 if ( $recipient->user_id !== $message->sender_id ) { 685 continue; 686 } 687 688 $message_data = array( 689 array( 690 'name' => __( 'Message Subject', 'buddypress' ), 691 'value' => $message->subject, 692 ), 693 array( 694 'name' => __( 'Message Content', 'buddypress' ), 695 'value' => $message->message, 696 ), 697 array( 698 'name' => __( 'Date Sent', 'buddypress' ), 699 'value' => $message->date_sent, 700 ), 701 array( 702 'name' => __( 'Recipients', 'buddypress' ), 703 'value' => $recipients, 704 ), 705 array( 706 'name' => __( 'Thread URL', 'buddypress' ), 707 'value' => $thread_link, 708 ), 709 ); 710 711 $data_to_export[] = array( 712 'group_id' => 'bp_messages', 713 'group_label' => __( 'Private Messages', 'buddypress' ), 714 'item_id' => "bp-messages-{$message->id}", 715 'data' => $message_data, 716 ); 717 } 718 } 719 720 return array( 721 'data' => $data_to_export, 722 'done' => true, 723 ); 724 } -
trunk/tests/phpunit/testcases/messages/functions.php
r11737 r12164 90 90 $message->recipients = array(); 91 91 } 92 93 /** 94 * @ticket BP7819 95 * @ticket BP7698 96 */ 97 public function test_bp_messages_personal_data_exporter() { 98 $u1 = self::factory()->user->create(); 99 $u2 = self::factory()->user->create(); 100 101 $time = time(); 102 103 $t1 = messages_new_message( array( 104 'sender_id' => $u1, 105 'recipients' => array( $u2 ), 106 'subject' => 'A new message', 107 'content' => 'Hey there!', 108 'date_sent' => date( 'Y-m-d H:i:s', $time - ( 3 * HOUR_IN_SECONDS ) ), 109 ) ); 110 111 $t1m1 = messages_new_message( array( 112 'sender_id' => $u2, 113 'thread_id' => $t1, 114 'recipients' => array( $u1 ), 115 'subject' => 'Reply to ' . $t1, 116 'content' => 'Hey there!', 117 'date_sent' => date( 'Y-m-d H:i:s', $time - ( 2 * HOUR_IN_SECONDS ) ), 118 ) ); 119 120 $t1m2 = messages_new_message( array( 121 'sender_id' => $u1, 122 'thread_id' => $t1, 123 'recipients' => array( $u2 ), 124 'subject' => 'Reply to ' . $t1, 125 'content' => 'Hey there!', 126 'date_sent' => date( 'Y-m-d H:i:s', $time - ( 2 * HOUR_IN_SECONDS ) ), 127 ) ); 128 129 $t2 = messages_new_message( array( 130 'sender_id' => $u2, 131 'recipients' => array( $u1 ), 132 'subject' => 'A new message', 133 'content' => 'Hey there!', 134 'date_sent' => date( 'Y-m-d H:i:s', $time - ( 5 * HOUR_IN_SECONDS ) ), 135 ) ); 136 137 $t2m1 = messages_new_message( array( 138 'sender_id' => $u1, 139 'thread_id' => $t2, 140 'recipients' => array( $u2 ), 141 'subject' => 'Reply to ' . $t2, 142 'content' => 'Hey there!', 143 'date_sent' => date( 'Y-m-d H:i:s', $time - ( 4 * HOUR_IN_SECONDS ) ), 144 ) ); 145 146 $test_user = new WP_User( $u1 ); 147 148 $actual = bp_messages_personal_data_exporter( $test_user->user_email, 1 ); 149 150 $this->assertTrue( $actual['done'] ); 151 152 // Number of exported messages. 153 $this->assertSame( 3, count( $actual['data'] ) ); 154 } 92 155 }
Note: See TracChangeset
for help on using the changeset viewer.