Last active
August 13, 2025 08:45
-
-
Save dwanjuki/dbfab1d7c77ae8dd71bcb87fc52e3250 to your computer and use it in GitHub Desktop.
Add a [pmpromd_user_field] shortcode that displays User Field values on the Member Directory "Profile" pages.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Add a [pmpromd_user_field] shortcode to display User Field values on the | |
* Member Directory Profile pages. | |
* | |
* Usage: [pmpromd_user_field field_name="your_field_name"] | |
* | |
* This is an advanced customization recipe that may require further development | |
* to suit specific needs and/or setups. For more details, please see: | |
* https://www.paidmembershipspro.com/developers/ | |
* | |
* 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_profile_user_field_value_shortcode( $atts ) { | |
global $pmpro_pages; | |
// Get shortcode attributes. | |
$atts = shortcode_atts( | |
array( | |
'field_name' => '', | |
), | |
$atts | |
); | |
// Bail if no field name is provided. | |
if ( empty( $atts['field_name'] ) ) { | |
return ''; | |
} | |
// Bail if Member Directory Add On is not active. | |
if ( ! function_exists( 'pmpromd_get_user' ) ) { | |
return ''; | |
} | |
// Bail if not on a Member Directory Profile page. | |
if ( empty( $pmpro_pages['profile'] ) || ! is_page( $pmpro_pages['profile'] ) ) { | |
return ''; | |
} | |
// Get profile user. | |
$user = pmpromd_get_user(); | |
// Bail if we can't get the user. | |
if ( ! $user ) { | |
return ''; | |
} | |
// Get and return the user field value. | |
$value = get_user_meta( $user->ID, $atts['field_name'], true ); | |
return esc_html( $value ); | |
} | |
add_shortcode( 'pmpromd_user_field', 'my_pmpromd_profile_user_field_value_shortcode' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment