-
Notifications
You must be signed in to change notification settings - Fork 15
/
rcp-custom-member-export-columns.php
60 lines (51 loc) · 1.75 KB
/
rcp-custom-member-export-columns.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
/**
* Plugin Name: Restrict Content Pro - Custom Membership Export Columns
* Description: Adds custom user meta or membership meta data to each membership export row.
* Version: 1.0
* Author: Sandhills Development, LLC
* Author URI: https://sandhillsdev.com
* License: GPL2
*/
/**
* Adds custom user meta data to each member's export row.
*
* 1. Add your column IDs / Names
* 2. Fill the column values from get_user_meta() using your unique meta keys
*/
/**
* Add additional columns
*
* @param array $columns Array of columns.
*
* @return array
*/
function pw_rcp_register_export_columns( $columns ) {
$columns[ 'my_custom_column' ] = 'My Column Name';
$columns[ 'my_second_custom_column' ] = 'My Second Column Name';
$columns[ 'my_third_custom_column' ] = 'My Third Column Name';
return $columns;
}
add_filter( 'rcp_export_csv_cols_members', 'pw_rcp_register_export_columns' );
/**
* Add values to each membership row
*
* @param array $data Array of member data to be included in the CSV export.
* @param RCP_Membership $membership Membership object.
*
* @return array Array with new data added.
*/
function pw_rcp_add_fields_to_export( $data, $membership ) {
/*
* This example is for including user meta data.
*/
$user_id = $membership->get_customer()->get_user_id();
$data[ 'my_custom_column' ] = get_user_meta( $user_id, 'my_meta_key', true );
$data[ 'my_second_custom_column' ] = get_user_meta( $user_id, 'my_second_meta_key', true );
/*
* This example is for including membership meta data.
*/
$data[ 'my_third_custom_column' ] = rcp_get_membership_meta( $membership->get_id(), 'my_third_meta_key', true );
return $data;
}
add_filter( 'rcp_export_memberships_get_data_row', 'pw_rcp_add_fields_to_export', 10, 2 );