Paid Memberships Pro, by Stranger Studios
Add provided code to functions.php and update Settings.
Calculation option “Use prices modified by other plugins” must be ON.
System option “Suppress other pricing plugins in frontend” must be OFF.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
function wdp_get_all_memberships_levels() { global $wpdb; $levels = array(); if ( isset( $wpdb->pmpro_membership_levels ) ) { $levels = $wpdb->get_results( "SELECT * FROM {$wpdb->pmpro_membership_levels} ORDER BY name" ); } return is_array( $levels ) ? $levels : array(); } add_filter( 'wdp_preloaded_list_user_roles', function ( $list ) { if ( ! function_exists('wdp_get_all_memberships_levels') ) { return $list; } foreach ( wdp_get_all_memberships_levels() as $level ) { $list[] = array( 'id' => 'membership_' . $level->id, 'text' => '(membership) ' . $level->name, ); } return $list; } ); add_filter( 'wdp_current_user_roles', function ( $roles ) { /** * @var WDP_User_Impl $wdp_user */ if ( ! function_exists('pmpro_getMembershipLevelsForUser') ) { return $roles; } $user_memberships = pmpro_getMembershipLevelsForUser( get_current_user_id() ); if ( ! $user_memberships ) { return $roles; } $user_memberships = array_map( function ( $id ) { return 'membership_' . $id; }, array_column( $user_memberships, 'id' ) ); return array_merge( $roles, $user_memberships ); }, 10, 1 ); |