Last active
November 7, 2023 08:20
-
-
Save ipokkel/da6ae21ba81a064a38cb0eaf1b687976 to your computer and use it in GitHub Desktop.
Remove columns from the PMPro Memberslist CSV export.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This recipe removes defined column headers from the Members Export CSV | |
* | |
* You can add this recipe to your site by creating a custom plugin | |
* or using the Code Snippets plugin available for free in the WordPress repository. | |
* Read this companion article for step-by-step directions on either method. | |
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
// Remove column headings | |
function my_pmpro_members_list_csv_heading( $csv_header ) { | |
$heading = explode( ',', $csv_header ); | |
/* | |
* Add or remove the column headers that you | |
* would like removed in the $remove array. | |
*/ | |
$remove = array( 'discount_code_id', 'discount_code' ); // remove discount code and discount code id | |
foreach ( $heading as $key => $title ) { | |
if ( in_array( $title, $remove ) ) { | |
unset( $heading[ $key ] ); | |
} | |
} | |
$csv_header = implode( ',', $heading ); | |
return $csv_header; | |
} | |
add_filter( 'pmpro_members_list_csv_heading', 'my_pmpro_members_list_csv_heading' ); | |
// Remove column data | |
function my_pmpro_members_list_csv_default_columns( $default_columns ) { | |
$new_default_columns = array(); | |
$remove = array( 'id', 'code' ); // remove discount code and discount code id | |
foreach ( $default_columns as $key => $value ) { | |
if ( ! in_array( $value[1], $remove ) ) { | |
$new_default_columns[] = $value; | |
} | |
} | |
return $new_default_columns; | |
} | |
add_filter( 'pmpro_members_list_csv_default_columns', 'my_pmpro_members_list_csv_default_columns' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The default column name can be obtained from here
https://github.com/strangerstudios/paid-memberships-pro/blob/2b372ffdd0131ec5e1427033f4cc3730993bf304/adminpages/memberslist-csv.php#L97-L119