Last active
June 25, 2020 18:59
-
-
Save andrewlimaza/3d88d926cb41f602292623afbea059fa to your computer and use it in GitHub Desktop.
Prepopulate Gravity Forms field with Paid Memberships Pro Membership Level ID.
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 | |
| /** | |
| * Example on how to auto-populate a Gravity Form Field "membership_level" with the user's current membership level for Paid Memberships Pro. | |
| * If user is not logged-in or doesn't have a membership level leave it blank. | |
| * Adjust the 'gform_field_value_membership_level' name to match that of your field name parameter name. | |
| */ | |
| function my_auto_populate_gforms_pmpro_level( $value ) { | |
| if ( ! defined( 'PMPRO_VERSION' ) || ! is_user_logged_in() ) { | |
| return; | |
| } | |
| global $current_user; | |
| $level = pmpro_getMembershipLevelForUser( $current_user->ID ); | |
| if ( ! empty( $level ) ) { | |
| $r = $level->ID; | |
| } else { | |
| $r = ''; | |
| } | |
| return $r; | |
| } | |
| add_filter( 'gform_field_value_membership_level', 'my_auto_populate_gforms_pmpro_level' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment