Skip to content

Instantly share code, notes, and snippets.

@ipokkel
Last active November 7, 2023 08:20
Show Gist options
  • Save ipokkel/da6ae21ba81a064a38cb0eaf1b687976 to your computer and use it in GitHub Desktop.
Save ipokkel/da6ae21ba81a064a38cb0eaf1b687976 to your computer and use it in GitHub Desktop.
Remove columns from the PMPro Memberslist CSV export.
<?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' );
@ipokkel
Copy link
Author

ipokkel commented Dec 9, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment