Created
April 7, 2021 13:46
-
-
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.
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 | |
/* | |
* 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' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To list sponsored member account user's first and last names instead of display names see https://gist.github.com/ipokkel/dee4b53a669bdf2a306e754ad56d7f37