Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save dwanjuki/22477854d56c2bb5c79708e84e5bc436 to your computer and use it in GitHub Desktop.

Select an option

Save dwanjuki/22477854d56c2bb5c79708e84e5bc436 to your computer and use it in GitHub Desktop.
Include the membership level name in the Members List CSV export filename.
<?php
/**
* Include the membership level name in the Members List CSV export filename.
*
* Retains the export ID in the name so the filename is unique.
*
* 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/
*/
function my_pmpro_members_export_add_level_in_filename( $file_name, $type, $export_id, $filters ) {
if ( 'members' !== $type ) {
return $file_name;
}
$l = isset( $filters['l'] ) ? $filters['l'] : '';
if ( 'oldmembers' === $l ) {
$level_slug = 'old-members';
} elseif ( 'expired' === $l ) {
$level_slug = 'expired';
} elseif ( 'cancelled' === $l ) {
$level_slug = 'cancelled';
} elseif ( is_numeric( $l ) ) {
$level = pmpro_getLevel( (int) $l );
$level_slug = ( $level && sanitize_title( $level->name ) ) ? sanitize_title( $level->name ) : 'level-' . (int) $l;
} else {
$level_slug = 'all-active-members';
}
// e.g. silver-1a2d44a8-f362-4b96-b5bd-c1eecd91b03c.csv
return $level_slug . '-' . $export_id . '.csv';
}
add_filter( 'pmpro_export_file_name', 'my_pmpro_members_export_add_level_in_filename', 10, 4 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment