Advertisement
verygoodplugins

Untitled

Sep 11th, 2019
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.81 KB | None | 0 0
  1. function wpf_chainedquiz() {
  2.  
  3.     if ( ! function_exists( 'wp_fusion' ) ) { // Just in case they deactivate WPF, we don't want it to break
  4.         return;
  5.     }
  6.  
  7.     $email = sanitize_email( $_POST['chainedemail'] );
  8.  
  9.     $contact_id = wp_fusion()->crm->get_contact_id( $email );
  10.  
  11.     $contact_data = array(
  12.         'user_email' => $email,
  13.         'first_name' => 'fname', // Populate this with the first name
  14.         'last_name'  => 'lname', // Populate this with the last name
  15.     );
  16.  
  17.     if ( false === $contact_id ) {
  18.  
  19.         // Add new contact
  20.  
  21.         $contact_id = wp_fusion()->crm->add_contact( $contact_data );
  22.  
  23.     } else {
  24.  
  25.         // Update existing contact
  26.  
  27.         wp_fusion()->crm->update_contact( $contact_id, $contact_data );
  28.  
  29.     }
  30.  
  31. }
  32.  
  33. add_action( 'wp_ajax_nopriv_chainedquiz_ajax', 'wpf_chainedquiz', 5 ); // Priority 5 so it runs before the main action
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement