Skip to content

Instantly share code, notes, and snippets.

@dwanjuki
Created December 15, 2025 12:15
Show Gist options
  • Select an option

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

Select an option

Save dwanjuki/cf2b77a55adc16dfd21c49eafd3103ce to your computer and use it in GitHub Desktop.
Format phone User Field display value in the member directory.
<?php
/**
* Format phone User Field display value in the member directory.
*
* Replace cell_phone on line 14 with your phone field's field name/meta key if different.
*
* 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_pmpromd_phone_display_value( $value, $element, $pu, $displayed_levels ) {
if ( 'cell_phone' === $element ) {
// Get the raw value directly from user metadata.
$raw_value = get_user_meta( $pu->ID, $element, true );
// If no value is found, return the original value.
if ( empty( $raw_value ) ) {
return $value;
}
// Format the phone number.
$value = formatPhone( $raw_value );
}
return $value;
}
add_filter( 'pmpromd_get_display_value', 'my_pmpromd_phone_display_value', 10, 4 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment