Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function load_contact( $contact_id ) {
- if ( ! $this->params ) {
- $this->get_params();
- }
- $request = $this->api_url . $this->get_contact_str . $contact_id;
- $response = wp_remote_get( $request, $this->params );
- if ( is_wp_error( $response ) ) {
- return $response;
- }
- $body_json = json_decode( wp_remote_retrieve_body( $response ) );
- $loaded_meta = array();
- if ( ! empty( $body_json->properties ) ) {
- foreach ( $body_json->properties as $field_object ) {
- if ( ! empty( $field_object->subtype ) ) {
- $loaded_meta[ $field_object->name . '+' . $field_object->subtype ] = $field_object->value;
- } else {
- $value = '';
- if ( isset( $field_object->value ) ) {
- $value = $field_object->value;
- }
- $maybe_json = json_decode( $value );
- if ( json_last_error() === JSON_ERROR_NONE && is_object( $maybe_json ) ) {
- foreach ( (array) $maybe_json as $key => $value ) {
- $loaded_meta[ $field_object->name . '+' . $key ] = $value;
- }
- } else {
- // Multi-checkbox (ADDED BY JACK NOV 11th)
- if ( 'MULTICHECKBOX' == $field_object->field_type && ! empty( $value ) ) {
- $value = explode( ',', $value );
- }
- // END NOV 11th CODE
- $loaded_meta[ $field_object->name ] = $value;
- }
- }
- }
- }
- // Fix email fields if no main email is set
- if ( empty( $loaded_meta['email'] ) ) {
- if ( ! empty( $loaded_meta['email+work'] ) ) {
- $loaded_meta['email'] = $loaded_meta['email+work'];
- } elseif ( ! empty( $loaded_meta['email+home'] ) ) {
- $loaded_meta['email'] = $loaded_meta['email+home'];
- }
- }
- // grab list of fields to process
- $user_meta = array();
- $contact_fields = wp_fusion()->settings->get( 'contact_fields' );
- foreach ( $contact_fields as $field_id => $field_data ) {
- if ( $field_data['active'] == true && isset( $loaded_meta[ $field_data['crm_field'] ] ) ) {
- $user_meta[ $field_id ] = $loaded_meta[ $field_data['crm_field'] ];
- }
- }
- // Set missing fields
- $crm_fields = wp_fusion()->settings->get( 'crm_fields' );
- foreach ( $loaded_meta as $name => $value ) {
- if ( ! isset( $crm_fields['Standard Fields'][ $name ] ) && ! isset( $crm_fields['Custom Fields'][ $name ] ) ) {
- $crm_fields['Custom Fields'][ $name ] = $name;
- wp_fusion()->settings->set( 'crm_fields', $crm_fields );
- }
- }
- return $user_meta;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement