Plugin Directory

Changeset 3037403


Ignore:
Timestamp:
02/18/2024 07:54:25 AM (2 years ago)
Author:
jhorowitz
Message:

Pre-populate mapped fields with currently saved values in User Update feeds.

Location:
member-profile-fields-for-wlm-and-gf-user-registration
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • member-profile-fields-for-wlm-and-gf-user-registration/trunk/member-profile-fields-for-wlm-and-gf-user-registration.php

    r2919493 r3037403  
    33 * Plugin Name:     Member Profile Fields for WishList Member and Gravity Forms User Registration Add-On
    44 * Description:     Allows setting WishList Member Fields when users are automatically created using Gravity Forms User Registration Add-On.
    5  * Version:         1.02
     5 * Version:         1.03
    66 * Author:          AoD Technologies LLC
    77 * Author URI:      https://aod-tech.com/
     
    1212 *
    1313 * Member Profile Fields for WishList Member and Gravity Forms User Registration Add-On Plugin
    14  * Copyright (C) 2020 - 2023 AoD Technologies LLC
     14 * Copyright (C) 2020 - 2024 AoD Technologies LLC
    1515 *
    1616 * This program is free software: you can redistribute it and/or modify
     
    3636class Plugin {
    3737    private $gf_user_registration = null;
     38    private $update_user_id = null;
    3839
    3940    public function __construct() {
     
    5556
    5657        add_filter( 'gform_userregistration_feed_settings_fields', array( $this, 'filter_feed_settings_fields' ) );
     58        add_filter( 'gform_user_registration_update_user_id', array( $this, 'set_filter_update_user_id_for_form_id' ), 10, 4 );
     59        add_filter( 'gform_user_registration_user_data_pre_populate', array( $this, 'filter_user_data_pre_populate' ), 10, 3 );
    5760
    5861        add_action( 'gform_user_registered', array( $this, 'update_wlm_data' ), 5, 3 );
     
    133136    }
    134137
     138    public function set_filter_update_user_id_for_form_id( $user_id, $entry, $form, $feed ) {
     139        remove_filter( 'gform_user_registration_update_user_id', array( $this, 'set_filter_update_user_id_for_form_id' ), 10, 4 );
     140
     141        add_filter( 'gform_user_registration_update_user_id_' . \rgar( $form, 'id' ), array( $this, 'filter_update_user_id' ), PHP_INT_MAX, 4);
     142
     143        return $user_id;
     144    }
     145
     146    public function filter_update_user_id( $user_id, $entry, $form, $feed ) {
     147        remove_filter( 'gform_user_registration_update_user_id_' . \rgar( $form, 'id' ), array( $this, 'filter_update_user_id' ), PHP_INT_MAX, 4);
     148
     149        $this->update_user_id = $user_id;
     150
     151        return $user_id;
     152    }
     153
     154    public function filter_user_data_pre_populate( $mapped_fields, $form, $feed ) {
     155        if ( empty( $this->update_user_id ) ) {
     156            return $mapped_fields;
     157        }
     158
     159        $meta = $this->get_wlm_meta( $feed );
     160
     161        if ( empty( $meta ) ) {
     162            return $mapped_fields;
     163        }
     164
     165        $get_member_response = \wlmapi_get_member( $this->update_user_id );
     166        if (
     167            $get_member_response['success'] === 0 ||
     168            empty( $get_member_response['member'] ) ||
     169            $get_member_response['member'][0]['ID'] === null
     170        ) {
     171            return $mapped_fields;
     172        }
     173
     174        $user_info = $get_member_response['member'][0]['UserInfo'];
     175
     176        foreach ( $meta as $wlm_field_id => $gf_field_id ) {
     177            if ( empty( $wlm_field_id ) || empty( $gf_field_id ) ) {
     178                continue;
     179            }
     180
     181            $value = null;
     182            if ( in_array( $wlm_field_id, array( 'company', 'address1', 'address2', 'city', 'state', 'zip', 'country' ) ) ) {
     183                $value = $user_info['wpm_useraddress'][$wlm_field_id];
     184            } else {
     185                if ( strpos( $wlm_field_id, 'custom_' ) !== 0 ) {
     186                    $wlm_field_id = 'custom_' . $wlm_field_id;
     187                }
     188
     189                $value = $user_info[$wlm_field_id];
     190            }
     191
     192            if ( empty( $value ) ) {
     193                continue;
     194            }
     195   
     196            $mapped_fields[(string) $gf_field_id] = $value;
     197        }
     198
     199        return $mapped_fields;
     200    }
     201
    135202    public function update_wlm_data( $user_id, $feed, $entry ) {
    136203        $wlm_data = $this->prepare_wlm_data( $user_id, $feed, $entry );
     
    188255
    189256new Plugin();
    190 
  • member-profile-fields-for-wlm-and-gf-user-registration/trunk/readme.txt

    r2919493 r3037403  
    44Tags: gravityforms, gravity forms, wishlist member, custom fields, user fields, user profile
    55Requires at least: 3.5
    6 Tested up to: 6.2.2
     6Tested up to: 6.4.3
    77Requires PHP: 5.6
    8 Stable tag: 1.02
     8Stable tag: 1.03
    99License: GPLv3 or later
    1010License URI: https://www.gnu.org/licenses/gpl-3.0.html
     
    3131== Changelog ==
    3232
     33= 1.03 =
     34* Pre-populate mapped fields with currently saved values in User Update feeds.
     35
    3336= 1.02 =
    3437* Actually load the text domain.
Note: See TracChangeset for help on using the changeset viewer.