| 2614 | |
| 2615 | /** |
| 2616 | * Finds and exports group membership data associated with an email address. |
| 2617 | * |
| 2618 | * @since 4.0.0 |
| 2619 | * |
| 2620 | * @param string $email_address The user's email address. |
| 2621 | * @param int $page Batch number. |
| 2622 | * @return array An array of personal data. |
| 2623 | */ |
| 2624 | function bp_groups_memberships_personal_data_exporter( $email_address, $page ) { |
| 2625 | $number = 20; |
| 2626 | |
| 2627 | $email_address = trim( $email_address ); |
| 2628 | |
| 2629 | $data_to_export = array(); |
| 2630 | |
| 2631 | $user = get_user_by( 'email', $email_address ); |
| 2632 | |
| 2633 | if ( ! $user ) { |
| 2634 | return array( |
| 2635 | 'data' => array(), |
| 2636 | 'done' => true, |
| 2637 | ); |
| 2638 | } |
| 2639 | |
| 2640 | $memberships = BP_Groups_Member::get_user_memberships( $user->ID, array( |
| 2641 | 'type' => 'membership', |
| 2642 | 'page' => $page, |
| 2643 | 'per_page' => $number, |
| 2644 | ) ); |
| 2645 | |
| 2646 | foreach ( $memberships as $membership ) { |
| 2647 | $group = groups_get_group( $membership->group_id ); |
| 2648 | |
| 2649 | $item_data = array( |
| 2650 | array( |
| 2651 | 'name' => __( 'Group Name', 'buddypress' ), |
| 2652 | 'value' => bp_get_group_name( $group ), |
| 2653 | ), |
| 2654 | array( |
| 2655 | 'name' => __( 'Group URL', 'buddypress' ), |
| 2656 | 'value' => bp_get_group_permalink( $group ), |
| 2657 | ), |
| 2658 | ); |
| 2659 | |
| 2660 | if ( $membership->inviter_id ) { |
| 2661 | $item_data[] = array( |
| 2662 | 'name' => __( 'Invited By', 'buddypress' ), |
| 2663 | 'value' => bp_core_get_userlink( $membership->inviter_id ), |
| 2664 | ); |
| 2665 | } |
| 2666 | |
| 2667 | if ( $group->creator_id === $user->ID ) { |
| 2668 | $group_role = __( 'Creator', 'buddypress' ); |
| 2669 | } elseif ( $membership->is_admin ) { |
| 2670 | $group_role = __( 'Admin', 'buddypress' ); |
| 2671 | } elseif ( $membership->is_mod ) { |
| 2672 | $group_role = __( 'Moderator', 'buddypress' ); |
| 2673 | } else { |
| 2674 | $group_role = __( 'Member', 'buddypress' ); |
| 2675 | } |
| 2676 | |
| 2677 | $item_data[] = array( |
| 2678 | 'name' => __( 'Group Role', 'buddypress' ), |
| 2679 | 'value' => $group_role, |
| 2680 | ); |
| 2681 | |
| 2682 | $item_data[] = array( |
| 2683 | 'name' => __( 'Date Joined', 'buddypress' ), |
| 2684 | 'value' => $membership->date_modified, |
| 2685 | ); |
| 2686 | |
| 2687 | $data_to_export[] = array( |
| 2688 | 'group_id' => 'bp_groups_memberships', |
| 2689 | 'group_label' => __( 'Group Memberships', 'buddypress' ), |
| 2690 | 'item_id' => "bp-group-membership-{$group->id}", |
| 2691 | 'data' => $item_data, |
| 2692 | ); |
| 2693 | } |
| 2694 | |
| 2695 | // Tell core if we have more items to process. |
| 2696 | $done = count( $memberships ) < $number; |
| 2697 | |
| 2698 | return array( |
| 2699 | 'data' => $data_to_export, |
| 2700 | 'done' => $done, |
| 2701 | ); |
| 2702 | } |
| 2703 | |
| 2704 | /** |
| 2705 | * Finds and exports data on pending group membership requests associated with an email address. |
| 2706 | * |
| 2707 | * @since 4.0.0 |
| 2708 | * |
| 2709 | * @param string $email_address The user's email address. |
| 2710 | * @param int $page Batch number. |
| 2711 | * @return array An array of personal data. |
| 2712 | */ |
| 2713 | function bp_groups_pending_requests_personal_data_exporter( $email_address, $page ) { |
| 2714 | $number = 20; |
| 2715 | |
| 2716 | $email_address = trim( $email_address ); |
| 2717 | |
| 2718 | $data_to_export = array(); |
| 2719 | |
| 2720 | $user = get_user_by( 'email', $email_address ); |
| 2721 | |
| 2722 | if ( ! $user ) { |
| 2723 | return array( |
| 2724 | 'data' => array(), |
| 2725 | 'done' => true, |
| 2726 | ); |
| 2727 | } |
| 2728 | |
| 2729 | $requests = BP_Groups_Member::get_user_memberships( $user->ID, array( |
| 2730 | 'type' => 'pending_request', |
| 2731 | 'page' => $page, |
| 2732 | 'per_page' => $number, |
| 2733 | ) ); |
| 2734 | |
| 2735 | foreach ( $requests as $request ) { |
| 2736 | $group = groups_get_group( $request->group_id ); |
| 2737 | |
| 2738 | $item_data = array( |
| 2739 | array( |
| 2740 | 'name' => __( 'Group Name', 'buddypress' ), |
| 2741 | 'value' => bp_get_group_name( $group ), |
| 2742 | ), |
| 2743 | array( |
| 2744 | 'name' => __( 'Group URL', 'buddypress' ), |
| 2745 | 'value' => bp_get_group_permalink( $group ), |
| 2746 | ), |
| 2747 | array( |
| 2748 | 'name' => __( 'Date Sent', 'buddypress' ), |
| 2749 | 'value' => $request->date_modified, |
| 2750 | ), |
| 2751 | ); |
| 2752 | |
| 2753 | $data_to_export[] = array( |
| 2754 | 'group_id' => 'bp_groups_pending_requests', |
| 2755 | 'group_label' => __( 'Pending Group Membership Requests', 'buddypress' ), |
| 2756 | 'item_id' => "bp-group-pending-request-{$group->id}", |
| 2757 | 'data' => $item_data, |
| 2758 | ); |
| 2759 | } |
| 2760 | |
| 2761 | // Tell core if we have more items to process. |
| 2762 | $done = count( $requests ) < $number; |
| 2763 | |
| 2764 | return array( |
| 2765 | 'data' => $data_to_export, |
| 2766 | 'done' => $done, |
| 2767 | ); |
| 2768 | } |
| 2769 | |
| 2770 | /** |
| 2771 | * Finds and exports data on pending group invitations sent by a user associated with an email address. |
| 2772 | * |
| 2773 | * @since 4.0.0 |
| 2774 | * |
| 2775 | * @param string $email_address The user's email address. |
| 2776 | * @param int $page Batch number. |
| 2777 | * @return array An array of personal data. |
| 2778 | */ |
| 2779 | function bp_groups_pending_sent_invitations_personal_data_exporter( $email_address, $page ) { |
| 2780 | $number = 20; |
| 2781 | |
| 2782 | $email_address = trim( $email_address ); |
| 2783 | |
| 2784 | $data_to_export = array(); |
| 2785 | |
| 2786 | $user = get_user_by( 'email', $email_address ); |
| 2787 | |
| 2788 | if ( ! $user ) { |
| 2789 | return array( |
| 2790 | 'data' => array(), |
| 2791 | 'done' => true, |
| 2792 | ); |
| 2793 | } |
| 2794 | |
| 2795 | $invitations = BP_Groups_Member::get_user_memberships( $user->ID, array( |
| 2796 | 'type' => 'pending_sent_invitation', |
| 2797 | 'page' => $page, |
| 2798 | 'per_page' => $number, |
| 2799 | ) ); |
| 2800 | |
| 2801 | foreach ( $invitations as $invitation ) { |
| 2802 | $group = groups_get_group( $invitation->group_id ); |
| 2803 | |
| 2804 | $item_data = array( |
| 2805 | array( |
| 2806 | 'name' => __( 'Group Name', 'buddypress' ), |
| 2807 | 'value' => bp_get_group_name( $group ), |
| 2808 | ), |
| 2809 | array( |
| 2810 | 'name' => __( 'Group URL', 'buddypress' ), |
| 2811 | 'value' => bp_get_group_permalink( $group ), |
| 2812 | ), |
| 2813 | array( |
| 2814 | 'name' => __( 'Sent To', 'buddypress' ), |
| 2815 | 'value' => bp_core_get_userlink( $invitation->user_id ), |
| 2816 | ), |
| 2817 | array( |
| 2818 | 'name' => __( 'Date Sent', 'buddypress' ), |
| 2819 | 'value' => $invitation->date_modified, |
| 2820 | ), |
| 2821 | ); |
| 2822 | |
| 2823 | $data_to_export[] = array( |
| 2824 | 'group_id' => 'bp_groups_pending_sent_invitations', |
| 2825 | 'group_label' => __( 'Pending Group Invitations (Sent)', 'buddypress' ), |
| 2826 | 'item_id' => "bp-group-pending-sent-invitation-{$group->id}", |
| 2827 | 'data' => $item_data, |
| 2828 | ); |
| 2829 | } |
| 2830 | |
| 2831 | // Tell core if we have more items to process. |
| 2832 | $done = count( $invitations ) < $number; |
| 2833 | |
| 2834 | return array( |
| 2835 | 'data' => $data_to_export, |
| 2836 | 'done' => $done, |
| 2837 | ); |
| 2838 | } |
| 2839 | |
| 2840 | /** |
| 2841 | * Finds and exports data on pending group invitations received by a user associated with an email address. |
| 2842 | * |
| 2843 | * @since 4.0.0 |
| 2844 | * |
| 2845 | * @param string $email_address The user's email address. |
| 2846 | * @param int $page Batch number. |
| 2847 | * @return array An array of personal data. |
| 2848 | */ |
| 2849 | function bp_groups_pending_received_invitations_personal_data_exporter( $email_address, $page ) { |
| 2850 | $number = 20; |
| 2851 | |
| 2852 | $email_address = trim( $email_address ); |
| 2853 | |
| 2854 | $data_to_export = array(); |
| 2855 | |
| 2856 | $user = get_user_by( 'email', $email_address ); |
| 2857 | |
| 2858 | if ( ! $user ) { |
| 2859 | return array( |
| 2860 | 'data' => array(), |
| 2861 | 'done' => true, |
| 2862 | ); |
| 2863 | } |
| 2864 | |
| 2865 | $invitations = BP_Groups_Member::get_user_memberships( $user->ID, array( |
| 2866 | 'type' => 'pending_received_invitation', |
| 2867 | 'page' => $page, |
| 2868 | 'per_page' => $number, |
| 2869 | ) ); |
| 2870 | |
| 2871 | foreach ( $invitations as $invitation ) { |
| 2872 | $group = groups_get_group( $invitation->group_id ); |
| 2873 | |
| 2874 | $item_data = array( |
| 2875 | array( |
| 2876 | 'name' => __( 'Group Name', 'buddypress' ), |
| 2877 | 'value' => bp_get_group_name( $group ), |
| 2878 | ), |
| 2879 | array( |
| 2880 | 'name' => __( 'Group URL', 'buddypress' ), |
| 2881 | 'value' => bp_get_group_permalink( $group ), |
| 2882 | ), |
| 2883 | array( |
| 2884 | 'name' => __( 'Invited By', 'buddypress' ), |
| 2885 | 'value' => bp_core_get_userlink( $invitation->inviter_id ), |
| 2886 | ), |
| 2887 | array( |
| 2888 | 'name' => __( 'Date Sent', 'buddypress' ), |
| 2889 | 'value' => $invitation->date_modified, |
| 2890 | ), |
| 2891 | ); |
| 2892 | |
| 2893 | $data_to_export[] = array( |
| 2894 | 'group_id' => 'bp_groups_pending_received_invitations', |
| 2895 | 'group_label' => __( 'Pending Group Invitations (Received)', 'buddypress' ), |
| 2896 | 'item_id' => "bp-group-pending-received-invitation-{$group->id}", |
| 2897 | 'data' => $item_data, |
| 2898 | ); |
| 2899 | } |
| 2900 | |
| 2901 | // Tell core if we have more items to process. |
| 2902 | $done = count( $invitations ) < $number; |
| 2903 | |
| 2904 | return array( |
| 2905 | 'data' => $data_to_export, |
| 2906 | 'done' => $done, |
| 2907 | ); |
| 2908 | } |