Skip to content

Instantly share code, notes, and snippets.

@ipokkel
Created November 16, 2022 12:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ipokkel/17266debaf7eeb3f349de1392be473e6 to your computer and use it in GitHub Desktop.
Save ipokkel/17266debaf7eeb3f349de1392be473e6 to your computer and use it in GitHub Desktop.
<?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