Skip to content

Commit

Permalink
fix: show "My Membership" links in My Account menu for team members
Browse files Browse the repository at this point in the history
  • Loading branch information
dkoo authored and adekbadek committed Nov 13, 2024
1 parent 6903b64 commit 634dd69
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions includes/plugins/class-teams-for-memberships.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Teams_For_Memberships {
public static function init() {
add_filter( 'newspack_ras_metadata_keys', [ __CLASS__, 'add_teams_metadata_keys' ] );
add_filter( 'newspack_esp_sync_contact', [ __CLASS__, 'handle_esp_sync_contact' ] );
add_filter( 'newspack_my_account_disabled_pages', [ __CLASS__, 'enable_members_area_for_team_members' ] );
}

/**
Expand Down Expand Up @@ -101,6 +102,26 @@ public static function handle_esp_sync_contact( $contact ) {

return $contact;
}

/**
* Enable Members Area for team members only. Team owners/managers get access to the "Teams" menu instead.
*
* @param array $disabled_wc_menu_items Disabled WooCommerce menu items.
*
* @return array Updated disabled WooCommerce menu items.
*/
public static function enable_members_area_for_team_members( $disabled_wc_menu_items ) {
if ( ! function_exists( 'wc_memberships_for_teams_get_teams' ) ) {
return $disabled_wc_menu_items;
}
if (
in_array( 'members-area', $disabled_wc_menu_items, true ) &&
! empty( \wc_memberships_for_teams_get_teams( \get_current_user_id(), [ 'role' => 'member' ] ) )
) {
$disabled_wc_menu_items = array_values( array_diff( $disabled_wc_menu_items, [ 'members-area' ] ) );
}
return $disabled_wc_menu_items;
}
}

Teams_For_Memberships::init();

0 comments on commit 634dd69

Please sign in to comment.