Last active
April 20, 2026 14:02
-
-
Save kimwhite/4a6cf131ff257ece31b1f0b50d4bf74d to your computer and use it in GitHub Desktop.
Show enddate in directory pages for child accounts
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 | |
| /** | |
| * On a child group member's Directory Profile page, replace the membership_enddate | |
| * display value with the Group Leader's expiration date. | |
| * | |
| * Requires: Paid Memberships Pro, Member Directory Add On, Group Accounts Add On. | |
| * | |
| * 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 pmpromd_group_child_use_leader_enddate( $value, $element, $pu, $displayed_levels ) { | |
| if ( 'membership_enddate' !== $element ) { | |
| return $value; | |
| } | |
| if ( ! class_exists( 'PMProGroupAcct_Group_Member' ) || ! class_exists( 'PMProGroupAcct_Group' ) ) { | |
| return $value; | |
| } | |
| // Check if this user is an active group child member. | |
| $group_memberships = PMProGroupAcct_Group_Member::get_group_members( array( | |
| 'group_child_user_id' => $pu->ID, | |
| 'group_child_status' => 'active', | |
| ) ); | |
| if ( empty( $group_memberships ) ) { | |
| return $value; | |
| } | |
| // Use the first group found. | |
| $group = new PMProGroupAcct_Group( (int) $group_memberships[0]->group_id ); | |
| if ( empty( $group->id ) ) { | |
| return $value; | |
| } | |
| // Get the leader's specific parent level to retrieve the expiration date. | |
| $parent_level = pmpro_getSpecificMembershipLevelForUser( $group->group_parent_user_id, $group->group_parent_level_id ); | |
| if ( ! empty( $parent_level->enddate ) && '0000-00-00 00:00:00' !== $parent_level->enddate ) { | |
| return date_i18n( get_option( 'date_format' ), strtotime( $parent_level->enddate ) ); | |
| } | |
| return $value; | |
| } | |
| add_filter( 'pmpromd_get_display_value', 'pmpromd_group_child_use_leader_enddate', 10, 4 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment