Changeset 12158
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-notifications/bp-notifications-functions.php
r11933 r12158 795 795 return $retval; 796 796 } 797 798 /** 799 * Finds and exports personal data associated with an email address from the Notifications tables. 800 * 801 * @since 4.0.0 802 * 803 * @param string $email_address The users email address. 804 * @param int $page Batch number. 805 * @return array An array of personal data. 806 */ 807 function bp_notifications_personal_data_exporter( $email_address, $page ) { 808 $number = 50; 809 810 $email_address = trim( $email_address ); 811 812 $data_to_export = array(); 813 814 $user = get_user_by( 'email', $email_address ); 815 816 if ( ! $user ) { 817 return array( 818 'data' => array(), 819 'done' => true, 820 ); 821 } 822 823 $notifications = BP_Notifications_Notification::get( array( 824 'is_new' => null, 825 'per_page' => $number, 826 'page' => $page, 827 'user_id' => $user->ID, 828 'order' => 'DESC', 829 ) ); 830 831 $user_data_to_export = array(); 832 833 foreach ( $notifications as $notification ) { 834 if ( 'xprofile' === $notification->component_name ) { 835 $component_name = 'profile'; 836 } else { 837 $component_name = $notification->component_name; 838 } 839 840 // Format notifications. 841 if ( isset( buddypress()->{$component_name}->notification_callback ) && is_callable( buddypress()->{$component_name}->notification_callback ) ) { 842 $content = call_user_func( buddypress()->{$component_name}->notification_callback, $notification->component_action, $notification->item_id, $notification->secondary_item_id, 1, 'string', $notification->id ); 843 } else { 844 // The array to reference with apply_filters_ref_array(). 845 $ref_array = array( 846 $notification->component_action, 847 $notification->item_id, 848 $notification->secondary_item_id, 849 $notification->total_count, 850 'string', 851 $notification->component_action, 852 $component_name, 853 $notification_item->id, 854 ); 855 856 /** This filter is documented in bp-notifications/bp-notifications-functions.php */ 857 $content = apply_filters_ref_array( 'bp_notifications_get_notifications_for_user', $ref_array ); 858 } 859 860 $item_data = array( 861 array( 862 'name' => __( 'Notification Content', 'buddypress' ), 863 'value' => $content, 864 ), 865 array( 866 'name' => __( 'Notification Date', 'buddypress' ), 867 'value' => $notification->date_notified, 868 ), 869 array( 870 'name' => __( 'Status', 'buddypress' ), 871 'value' => $notification->is_new ? __( 'Unread', 'buddypress' ) : __( 'Read', 'buddypress' ), 872 ), 873 ); 874 875 $data_to_export[] = array( 876 'group_id' => 'bp_notifications', 877 'group_label' => __( 'Notifications' ), 878 'item_id' => "bp-notifications-{$notification->id}", 879 'data' => $item_data, 880 ); 881 } 882 883 // Tell core if we have more items to process. 884 $done = count( $notifications ) < $number; 885 886 return array( 887 'data' => $data_to_export, 888 'done' => $done, 889 ); 890 } -
trunk/src/bp-notifications/classes/class-bp-notifications-component.php
r11933 r12158 47 47 'adminbar', 48 48 'template', 49 'filters', 49 50 'functions', 50 51 'cache', -
trunk/tests/phpunit/testcases/notifications/functions.php
r11888 r12158 433 433 $this->assertEquals( 2, $found[0]->total_count ); 434 434 } 435 436 /** 437 * @ticket BP7827 438 */ 439 public function test_bp_notifications_personal_data_exporter() { 440 $u = self::factory()->user->create(); 441 442 // Create notifications 443 $n1 = self::factory()->notification->create( array( 444 'component_name' => 'messages', 445 'component_action' => 'new_message', 446 'item_id' => 99, 447 'user_id' => $u, 448 ) ); 449 450 $n2 = self::factory()->notification->create( array( 451 'component_name' => 'activity', 452 'component_action' => 'new_at_mention', 453 'item_id' => 99, 454 'user_id' => $u, 455 ) ); 456 457 $test_user = new WP_User( $u ); 458 459 $actual = bp_notifications_personal_data_exporter( $test_user->user_email, 1 ); 460 461 $this->assertTrue( $actual['done'] ); 462 463 // Number of exported notification items. 464 $this->assertSame( 2, count( $actual['data'] ) ); 465 } 435 466 }
Note: See TracChangeset
for help on using the changeset viewer.