Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
/**
* Trim the custom user meta field in the array of fields to display
* on the PMPro Member Directory pages.
*
* This helps remove spaces erroneously added to the list of fields
* to display on the PMPro Member Directory pages.
*
* 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 trim_member_profile_fields_array_values( $fields_array, $pu ) {
$new_fields_array = array();
foreach ( $fields_array as $fields_key => $field_array ) {
foreach ( $field_array as $field_key => $field_value ) {
$new_fields_array[ $fields_key ][ $field_key ] = trim( $field_value );
}
}
return $new_fields_array;
}
add_filter( 'pmpro_member_profile_fields', 'trim_member_profile_fields_array_values', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment