verygoodplugins

Untitled

Nov 11th, 2020
579
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     public function load_contact( $contact_id ) {
  2.  
  3.         if ( ! $this->params ) {
  4.             $this->get_params();
  5.         }
  6.  
  7.         $request  = $this->api_url . $this->get_contact_str . $contact_id;
  8.         $response = wp_remote_get( $request, $this->params );
  9.  
  10.         if ( is_wp_error( $response ) ) {
  11.             return $response;
  12.         }
  13.  
  14.         $body_json = json_decode( wp_remote_retrieve_body( $response ) );
  15.  
  16.         $loaded_meta = array();
  17.  
  18.         if ( ! empty( $body_json->properties ) ) {
  19.  
  20.             foreach ( $body_json->properties as $field_object ) {
  21.  
  22.                 if ( ! empty( $field_object->subtype ) ) {
  23.  
  24.                     $loaded_meta[ $field_object->name . '+' . $field_object->subtype ] = $field_object->value;
  25.  
  26.                 } else {
  27.  
  28.                     $value = '';
  29.  
  30.                     if ( isset( $field_object->value ) ) {
  31.                         $value = $field_object->value;
  32.                     }
  33.  
  34.                     $maybe_json = json_decode( $value );
  35.  
  36.                     if ( json_last_error() === JSON_ERROR_NONE && is_object( $maybe_json ) ) {
  37.  
  38.                         foreach ( (array) $maybe_json as $key => $value ) {
  39.                             $loaded_meta[ $field_object->name . '+' . $key ] = $value;
  40.                         }
  41.                     } else {
  42.  
  43.                         // Multi-checkbox (ADDED BY JACK NOV 11th)
  44.  
  45.                         if ( 'MULTICHECKBOX' == $field_object->field_type && ! empty( $value ) ) {
  46.                             $value = explode( ',', $value );
  47.                         }
  48.  
  49.                         // END NOV 11th CODE
  50.  
  51.                         $loaded_meta[ $field_object->name ] = $value;
  52.  
  53.                     }
  54.                 }
  55.             }
  56.         }
  57.  
  58.         // Fix email fields if no main email is set
  59.         if ( empty( $loaded_meta['email'] ) ) {
  60.             if ( ! empty( $loaded_meta['email+work'] ) ) {
  61.                 $loaded_meta['email'] = $loaded_meta['email+work'];
  62.             } elseif ( ! empty( $loaded_meta['email+home'] ) ) {
  63.                 $loaded_meta['email'] = $loaded_meta['email+home'];
  64.             }
  65.         }
  66.  
  67.         // grab list of fields to process
  68.         $user_meta      = array();
  69.         $contact_fields = wp_fusion()->settings->get( 'contact_fields' );
  70.  
  71.         foreach ( $contact_fields as $field_id => $field_data ) {
  72.  
  73.             if ( $field_data['active'] == true && isset( $loaded_meta[ $field_data['crm_field'] ] ) ) {
  74.                 $user_meta[ $field_id ] = $loaded_meta[ $field_data['crm_field'] ];
  75.             }
  76.         }
  77.  
  78.         // Set missing fields
  79.         $crm_fields = wp_fusion()->settings->get( 'crm_fields' );
  80.  
  81.         foreach ( $loaded_meta as $name => $value ) {
  82.  
  83.             if ( ! isset( $crm_fields['Standard Fields'][ $name ] ) && ! isset( $crm_fields['Custom Fields'][ $name ] ) ) {
  84.                 $crm_fields['Custom Fields'][ $name ] = $name;
  85.                 wp_fusion()->settings->set( 'crm_fields', $crm_fields );
  86.             }
  87.         }
  88.  
  89.         return $user_meta;
  90.     }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×