Skip to content

Instantly share code, notes, and snippets.

@kimwhite
Created July 26, 2024 14:39
Show Gist options
  • Save kimwhite/270d9269d6daf76a6be949ea021938b5 to your computer and use it in GitHub Desktop.
Save kimwhite/270d9269d6daf76a6be949ea021938b5 to your computer and use it in GitHub Desktop.
This recipe will show the Group Leaders Expiration Date for the child's membership level.
<?php
/*
* Show the Group Leaders expiration for the child in various places on frontend and admin pages in PMPro.
*
* 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_pmprogroupacct_membership_expiration_text( $text, $level, $user ) {
// Check if Group Accounts is active.
if ( ! class_exists( 'PMProGroupAcct_Group_Member' ) ) {
return $text;
}
// Get the member object for the user.
$group_members = PMProGroupAcct_Group_Member::get_group_members(
array(
'group_child_user_id' => $user->ID,
'group_child_level_id' => $level->id,
'group_child_status' => 'active',
)
);
// If there is not a group member, return the text as is.
if ( empty( $group_members ) ) {
return $text;
}
// Get the group member object.
$group_member = $group_members[0];
// Get the group object.
$groups = PMProGroupAcct_Group::get_groups(
array(
'id' => $group_member->group_id,
)
);
// If there is not a group, return the text as is.
if ( empty( $groups ) ) {
return $text;
}
// Get the group object.
$group = $groups[0];
return pmpro_get_membership_expiration_text( $group->group_parent_level_id, $group->group_parent_user_id, '' );
}
add_filter( 'pmpro_membership_expiration_text', 'my_pmprogroupacct_membership_expiration_text', 10, 4 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment