Feature #12447 » group-members-export-to-csv.php
1 |
<?php
|
---|---|
2 |
|
3 |
global $wpdb, $bp; |
4 |
|
5 |
$gms = $wpdb->get_results( "SELECT * FROM {$bp->groups->table_name_members} WHERE is_banned = 0 AND is_confirmed = 1" ); |
6 |
|
7 |
$cols = [ |
8 |
0 => 'user_id', |
9 |
1 => 'user_email', |
10 |
2 => 'group_name', |
11 |
3 => 'group_id', |
12 |
];
|
13 |
|
14 |
$data_rows = array_map( |
15 |
function( $gm ) { |
16 |
$user = get_userdata( $gm->user_id ); |
17 |
$group = groups_get_group( $gm->group_id ); |
18 |
|
19 |
return [ |
20 |
0 => $user->ID, |
21 |
1 => $user->user_email, |
22 |
2 => $group->name, |
23 |
3 => $group->id |
24 |
];
|
25 |
},
|
26 |
$gms
|
27 |
);
|
28 |
|
29 |
$csv_path = ABSPATH . '/al-cop-group-members-' . date( 'Y-m-d' ) . '.csv'; |
30 |
|
31 |
$fh = fopen( $csv_path, 'w+' ); |
32 |
|
33 |
fprintf( $fh, chr(0xEF) . chr(0xBB) . chr(0xBF) ); |
34 |
|
35 |
fputcsv( $fh, $cols ); |
36 |
|
37 |
foreach ( $data_rows as $data_row ) { |
38 |
fputcsv( $fh, $data_row ); |
39 |
}
|
40 |
|
41 |
fclose( $fh ); |
42 |
die(); |