Changeset 12160
- Timestamp:
- 06/04/2018 08:02:30 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-friends/bp-friends-filters.php
r11865 r12160 48 48 } 49 49 add_filter( 'bp_user_query_populate_extras', 'bp_friends_filter_user_query_populate_extras', 4, 2 ); 50 51 /** 52 * Registers Friends personal data exporter. 53 * 54 * @since 4.0.0 55 * 56 * @param array $exporters An array of personal data exporters. 57 * @return array An array of personal data exporters. 58 */ 59 function bp_friends_register_personal_data_exporters( $exporters ) { 60 $exporters['buddypress-friends'] = array( 61 'exporter_friendly_name' => __( 'BuddyPress Friends', 'buddypress' ), 62 'callback' => 'bp_friends_personal_data_exporter', 63 ); 64 65 $exporters['buddypress-friends-pending-sent-requests'] = array( 66 'exporter_friendly_name' => __( 'BuddyPress Friend Requests (Sent)', 'buddypress' ), 67 'callback' => 'bp_friends_pending_sent_requests_personal_data_exporter', 68 ); 69 70 $exporters['buddypress-friends-pending-received-requests'] = array( 71 'exporter_friendly_name' => __( 'BuddyPress Friend Requests (Received)', 'buddypress' ), 72 'callback' => 'bp_friends_pending_received_requests_personal_data_exporter', 73 ); 74 75 return $exporters; 76 } 77 add_filter( 'wp_privacy_personal_data_exporters', 'bp_friends_register_personal_data_exporters' ); -
trunk/src/bp-friends/bp-friends-functions.php
r11693 r12160 898 898 } 899 899 add_action( 'friends_friendship_accepted', 'friends_notification_accepted_request', 10, 3 ); 900 901 /** 902 * Finds and exports friendship data associated with an email address. 903 * 904 * @since 4.0.0 905 * 906 * @param string $email_address The user's email address. 907 * @param int $page Batch number. 908 * @return array An array of personal data. 909 */ 910 function bp_friends_personal_data_exporter( $email_address, $page ) { 911 $number = 50; 912 913 $email_address = trim( $email_address ); 914 915 $data_to_export = array(); 916 917 $user = get_user_by( 'email', $email_address ); 918 919 if ( ! $user ) { 920 return array( 921 'data' => array(), 922 'done' => true, 923 ); 924 } 925 926 $friendships = BP_Friends_Friendship::get_friendships( $user->ID, array( 927 'is_confirmed' => true, 928 'page' => $page, 929 'per_page' => $number, 930 ) ); 931 932 $user_data_to_export = array(); 933 934 foreach ( $friendships as $friendship ) { 935 if ( (int) $user->ID === (int) $friendship->initiator_user_id ) { 936 $friend_id = $friendship->friend_user_id; 937 $user_is_initiator = true; 938 } else { 939 $friend_id = $friendship->initiator_user_id; 940 $user_is_initiator = false; 941 } 942 943 $item_data = array( 944 array( 945 'name' => __( 'Friend', 'buddypress' ), 946 'value' => bp_core_get_userlink( $friend_id ), 947 ), 948 array( 949 'name' => __( 'Initiated By Me', 'buddypress' ), 950 'value' => $user_is_initiator ? __( 'Yes', 'buddypress' ) : __( 'No', 'buddypress' ), 951 ), 952 array( 953 'name' => __( 'Friendship Date', 'buddypress' ), 954 'value' => $friendship->date_created, 955 ), 956 ); 957 958 $data_to_export[] = array( 959 'group_id' => 'bp_friends', 960 'group_label' => __( 'Friends', 'buddypress' ), 961 'item_id' => "bp-friends-{$friend_id}", 962 'data' => $item_data, 963 ); 964 } 965 966 // Tell core if we have more items to process. 967 $done = count( $friendships ) < $number; 968 969 return array( 970 'data' => $data_to_export, 971 'done' => $done, 972 ); 973 } 974 975 /** 976 * Finds and exports pending sent friendship request data associated with an email address. 977 * 978 * @since 4.0.0 979 * 980 * @param string $email_address The user's email address. 981 * @param int $page Batch number. 982 * @return array An array of personal data. 983 */ 984 function bp_friends_pending_sent_requests_personal_data_exporter( $email_address, $page ) { 985 $number = 50; 986 987 $email_address = trim( $email_address ); 988 989 $data_to_export = array(); 990 991 $user = get_user_by( 'email', $email_address ); 992 993 if ( ! $user ) { 994 return array( 995 'data' => array(), 996 'done' => true, 997 ); 998 } 999 1000 $friendships = BP_Friends_Friendship::get_friendships( $user->ID, array( 1001 'is_confirmed' => false, 1002 'initiator_user_id' => $user->ID, 1003 'page' => $page, 1004 'per_page' => $number, 1005 ) ); 1006 1007 $user_data_to_export = array(); 1008 1009 foreach ( $friendships as $friendship ) { 1010 $item_data = array( 1011 array( 1012 'name' => __( 'Recipient', 'buddypress' ), 1013 'value' => bp_core_get_userlink( $friendship->friend_user_id ), 1014 ), 1015 array( 1016 'name' => __( 'Date Sent', 'buddypress' ), 1017 'value' => $friendship->date_created, 1018 ), 1019 ); 1020 1021 $data_to_export[] = array( 1022 'group_id' => 'bp_friends_pending_sent_requests', 1023 'group_label' => __( 'Pending Friend Requests (Sent)', 'buddypress' ), 1024 'item_id' => "bp-friends-pending-sent-request-{$friendship->friend_user_id}", 1025 'data' => $item_data, 1026 ); 1027 } 1028 1029 // Tell core if we have more items to process. 1030 $done = count( $friendships ) < $number; 1031 1032 return array( 1033 'data' => $data_to_export, 1034 'done' => $done, 1035 ); 1036 } 1037 1038 /** 1039 * Finds and exports pending received friendship request data associated with an email address. 1040 * 1041 * @since 4.0.0 1042 * 1043 * @param string $email_address The user's email address. 1044 * @param int $page Batch number. 1045 * @return array An array of personal data. 1046 */ 1047 function bp_friends_pending_received_requests_personal_data_exporter( $email_address, $page ) { 1048 $number = 50; 1049 1050 $email_address = trim( $email_address ); 1051 1052 $data_to_export = array(); 1053 1054 $user = get_user_by( 'email', $email_address ); 1055 1056 if ( ! $user ) { 1057 return array( 1058 'data' => array(), 1059 'done' => true, 1060 ); 1061 } 1062 1063 $friendships = BP_Friends_Friendship::get_friendships( $user->ID, array( 1064 'is_confirmed' => false, 1065 'friend_user_id' => $user->ID, 1066 'page' => $page, 1067 'per_page' => $number, 1068 ) ); 1069 1070 $user_data_to_export = array(); 1071 1072 foreach ( $friendships as $friendship ) { 1073 $item_data = array( 1074 array( 1075 'name' => __( 'Requester', 'buddypress' ), 1076 'value' => bp_core_get_userlink( $friendship->initiator_user_id ), 1077 ), 1078 array( 1079 'name' => __( 'Date Sent', 'buddypress' ), 1080 'value' => $friendship->date_created, 1081 ), 1082 ); 1083 1084 $data_to_export[] = array( 1085 'group_id' => 'bp_friends_pending_received_requests', 1086 'group_label' => __( 'Pending Friend Requests (Received)', 'buddypress' ), 1087 'item_id' => "bp-friends-pending-received-request-{$friendship->initiator_user_id}", 1088 'data' => $item_data, 1089 ); 1090 } 1091 1092 // Tell core if we have more items to process. 1093 $done = count( $friendships ) < $number; 1094 1095 return array( 1096 'data' => $data_to_export, 1097 'done' => $done, 1098 ); 1099 } -
trunk/tests/phpunit/testcases/friends/functions.php
r12114 r12160 414 414 $this->assertEquals( $newest['users'][2]->id, $u2 ); 415 415 } 416 417 /** 418 * @ticket BP7821 419 * @ticket BP7698 420 */ 421 public function test_bp_friends_personal_data_exporter() { 422 friends_add_friend( self::$user_ids[0], self::$user_ids[1], true ); 423 friends_add_friend( self::$user_ids[0], self::$user_ids[2], false ); 424 friends_add_friend( self::$user_ids[3], self::$user_ids[0], true ); 425 friends_add_friend( self::$user_ids[4], self::$user_ids[0], false ); 426 427 $test_user = new WP_User( self::$user_ids[0] ); 428 429 $actual = bp_friends_personal_data_exporter( $test_user->user_email, 1 ); 430 431 $this->assertTrue( $actual['done'] ); 432 $this->assertCount( 2, $actual['data'] ); 433 434 $expected_ids = array( 435 'bp-friends-' . self::$user_ids[1], 436 'bp-friends-' . self::$user_ids[3], 437 ); 438 $this->assertEqualSets( $expected_ids, wp_list_pluck( $actual['data'], 'item_id' ) ); 439 } 440 441 /** 442 * @ticket BP7821 443 * @ticket BP7698 444 */ 445 public function test_bp_friends_pending_sent_requests_personal_data_exporter() { 446 friends_add_friend( self::$user_ids[0], self::$user_ids[1], true ); 447 friends_add_friend( self::$user_ids[0], self::$user_ids[2], false ); 448 friends_add_friend( self::$user_ids[3], self::$user_ids[0], true ); 449 friends_add_friend( self::$user_ids[4], self::$user_ids[0], false ); 450 451 $test_user = new WP_User( self::$user_ids[0] ); 452 453 $actual = bp_friends_pending_sent_requests_personal_data_exporter( $test_user->user_email, 1 ); 454 455 $this->assertTrue( $actual['done'] ); 456 $this->assertCount( 1, $actual['data'] ); 457 458 $expected_ids = array( 459 'bp-friends-pending-sent-request-' . self::$user_ids[2], 460 ); 461 $this->assertEqualSets( $expected_ids, wp_list_pluck( $actual['data'], 'item_id' ) ); 462 } 463 464 /** 465 * @ticket BP7821 466 * @ticket BP7698 467 */ 468 public function test_bp_friends_pending_received_requests_personal_data_exporter() { 469 friends_add_friend( self::$user_ids[0], self::$user_ids[1], true ); 470 friends_add_friend( self::$user_ids[0], self::$user_ids[2], false ); 471 friends_add_friend( self::$user_ids[3], self::$user_ids[0], true ); 472 friends_add_friend( self::$user_ids[4], self::$user_ids[0], false ); 473 474 $test_user = new WP_User( self::$user_ids[0] ); 475 476 $actual = bp_friends_pending_received_requests_personal_data_exporter( $test_user->user_email, 1 ); 477 478 $this->assertTrue( $actual['done'] ); 479 $this->assertCount( 1, $actual['data'] ); 480 481 $expected_ids = array( 482 'bp-friends-pending-received-request-' . self::$user_ids[4], 483 ); 484 $this->assertEqualSets( $expected_ids, wp_list_pluck( $actual['data'], 'item_id' ) ); 485 } 416 486 }
Note: See TracChangeset
for help on using the changeset viewer.