Advertisement
designerken

gravityflow_capture_role_change

Dec 7th, 2023
1,005
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.27 KB | None | 0 0
  1. function capture_role_change_on_step_complete( $step_id, $entry_id, $form_id, $status ) {
  2.     // Check if the step ID matches any of the identified steps
  3.      $allowed_step_ids = array( 8, 9, 10, 11, 16 );
  4.  
  5.     if ( in_array( $step_id, $allowed_step_ids ) ) {
  6.         // Get Gravity Forms entry for this step
  7.         $entry = GFAPI::get_entry( $entry_id );
  8.  
  9.         if ( ! is_wp_error( $entry ) && ! empty( $entry ) ) {
  10.             // Extract the submitted email from the form entry
  11.             $submitted_email = rgar( $entry, '2' ); // Assuming the email field ID is '2'
  12.  
  13.             // Get the user ID associated with the submitted email
  14.             $user = get_user_by( 'email', $submitted_email );
  15.  
  16.             if ( $user ) {
  17.                 $user_id = $user->ID;
  18.                 // Fetch the new role from the element ID 32 (replace '32' with the actual field ID)
  19.                 $new_role = rgar( $entry, '32' );
  20.  
  21.                 // Get old roles from user meta or any source as needed
  22.                 //$old_roles = $user->roles;
  23.  
  24.                 // Call your function to record role changes
  25.                 record_role_change( $user_id, $new_role );
  26.             }
  27.         }
  28.     }
  29. }
  30. add_action( 'gravityflow_step_complete', 'capture_role_change_on_step_complete', 10, 4 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement