Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function capture_role_change_on_step_complete( $step_id, $entry_id, $form_id, $status ) {
- // Check if the step ID matches any of the identified steps
- $allowed_step_ids = array( 8, 9, 10, 11, 16 );
- if ( in_array( $step_id, $allowed_step_ids ) ) {
- // Get Gravity Forms entry for this step
- $entry = GFAPI::get_entry( $entry_id );
- if ( ! is_wp_error( $entry ) && ! empty( $entry ) ) {
- // Extract the submitted email from the form entry
- $submitted_email = rgar( $entry, '2' ); // Assuming the email field ID is '2'
- // Get the user ID associated with the submitted email
- $user = get_user_by( 'email', $submitted_email );
- if ( $user ) {
- $user_id = $user->ID;
- // Fetch the new role from the element ID 32 (replace '32' with the actual field ID)
- $new_role = rgar( $entry, '32' );
- // Get old roles from user meta or any source as needed
- //$old_roles = $user->roles;
- // Call your function to record role changes
- record_role_change( $user_id, $new_role );
- }
- }
- }
- }
- add_action( 'gravityflow_step_complete', 'capture_role_change_on_step_complete', 10, 4 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement