Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ipokkel/40ee69356e5c42d35c90c7c1d6dd16b3 to your computer and use it in GitHub Desktop.
Save ipokkel/40ee69356e5c42d35c90c7c1d6dd16b3 to your computer and use it in GitHub Desktop.
Show user fields (user meta) as bullets on the PMPro Membership Account page.
<?php
/**
* Add user fields to the account page bullets.
*
* 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 pmpro_account_bullets_add_user_meta() {
/*
Add user meta fields to the account page.
format: 'meta_key' => 'Meta Label' (The user field's "name" is the meta key.)
*/
$user_meta = array(
'example_field_name' => 'Example Field Label', // e.g. 'pet_name' => 'Pet Name'
'another_example_field_name' => 'Example Field Label', // e.g. 'member_number' => 'Member Number'
);
// Let's work with the user meta fields.
foreach ( $user_meta as $meta_key => $meta_label ) {
// Get the user meta value.
$meta_value = get_user_meta( get_current_user_id(), $meta_key, true );
// If there's a value, add it to the list.
if ( ! empty( $meta_value ) ) {
echo '<li><strong>' . esc_html( $meta_label ) . ':</strong> ' . esc_html( $meta_value ) . '</li>';
}
}
}
add_action( 'pmpro_account_bullets_bottom', 'pmpro_account_bullets_add_user_meta' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment