Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kimcoleman/38d4a32604002c5d88938a0d3f36233e to your computer and use it in GitHub Desktop.
Save kimcoleman/38d4a32604002c5d88938a0d3f36233e to your computer and use it in GitHub Desktop.
Show a list of the sponsored member accounts on the parent's profile page on the Member Directory's Profile page.
<?php
/*
* Show a list of the sponsored (child) member accounts on the parent's profile page on the Member Directory's Profile page.
*
* 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 show_sponsored_child_accounts_pmpro_member_profile_after( $pu ) {
$sponsored_ids = pmprosm_getChildren( $pu->ID );
if ( empty( $sponsored_ids ) ) {
return;
}
$sponsored_list = new WP_User_Query(
array(
'include' => $sponsored_ids,
'orderby' => 'name',
'order' => 'ASC'
)
);
$sponsored_members = $sponsored_list->get_results();
if ( ! empty( $sponsored_members ) ) {
echo '<strong>Sponsored Members</strong>';
echo '<ul>';
foreach( $sponsored_members as $sponsored_member ) {
echo '<li>' . esc_html( $sponsored_member->data->display_name ) . '</li>';
}
echo '</ul>';
}
}
add_action( 'pmpro_member_profile_after', 'show_sponsored_child_accounts_pmpro_member_profile_after' );
@ipokkel
Copy link

ipokkel commented Oct 12, 2021

To list sponsored member account user's first and last names instead of display names see https://gist.github.com/ipokkel/dee4b53a669bdf2a306e754ad56d7f37

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment