• Resolved oguruma

    (@oguruma)


    I need to integrate this plugin with Mautic. I have a custom field (Mobile Number) that I have created with UsersWP.

    I need to fetch that mobile number from the database and pass it to Mautic.

    Per a Mautic developer the Mautic side code is

    add_filter('wpmautic_tracking_attributes', function(array $attributes) {
        $phone = …; //whatever is to retrieve the phone number
    
        $attributes['sitephonenumber'] = $phone;
    
        return $attributes;
    });

    Any input on what logic I would use to pull that WpUsers custom field in?

    • This topic was modified 4 years, 2 months ago by oguruma.
Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Contributor Paolo

    (@paoltaia)

    Hi @oguruma,

    you can use the normal WP functions and prefix the key with “uwp_meta_”

    or use the UsersWP own function:

    uwp_get_usermeta( $user_id = false, $key = 'ADD_KEY_HERE', $default = false )

    Let us know how it goes.

    Thank you!

    Thread Starter oguruma

    (@oguruma)

    Just to make sure I have this

    $current_user       = wp_get_current_user();
    $current_user->user_email;

    will get me the default WordPress user email meta.

    $current_user       = wp_get_current_user();
    $current_user->uwp_meta_mobilenumber;

    Would get me the number from the UsersWP field I created (called “mobilenumber”)?

    Plugin Contributor Paolo

    (@paoltaia)

    I don’t think that will work, but I haven’t tested it TBH.

    I’d use this if I were in you:

    echo uwp_get_usermeta( get_current_user_id() , 'uwp_mobilenumber', 'no mobile set' );

    This is tested and should work just fine.

    Let me know how it goes.

    Thread Starter oguruma

    (@oguruma)

    I don’t understand the , ‘no mobile set’ bit, what am I trying to do with this?

    Plugin Contributor Paolo

    (@paoltaia)

    That’s the fallback string for if/when a user didn’t enter a mobile number. It’s just text, you can change that to whatever you want.

    • This reply was modified 4 years, 2 months ago by Paolo.
    Thread Starter oguruma

    (@oguruma)

    Hmmmm, so I have

    add_filter('wpmautic_tracking_attributes', function(array $attributes) {
        $phone = uwp_get_usermeta( $user_id = false, $key = 'uwp_Mobile', $default = notgiven); //whatever is to retrieve the phone number
    
        $attributes['phone'] = $phone;
    
        return $attributes;
    });
    

    It’s updating Mautic contacts as “notgiven”, so I know it’s sending something to Mautic, however it’s not fetching the actual mobile number in their profile. Do I have the key right? I just named it “mobile” in the UsersWP form buider.

    Plugin Contributor Paolo

    (@paoltaia)

    this is wrong:

    $phone = uwp_get_usermeta( $user_id = false, $key = 'uwp_Mobile', $default = notgiven); //whatever is to retrieve the phone number

    it should be

    $phone = uwp_get_usermeta( get_current_user_id() , 'uwp_mobile', 'notgiven' );

    To make sure you have the key right, simply click the “show advanced” button for your custom field. The field key will become visible and you’ll be able to verify it.

    Let me know how it goes.

    Thanks

    Thread Starter oguruma

    (@oguruma)

    `add_filter(‘wpmautic_tracking_attributes’, function(array $attributes) {

    $phone = uwp_get_usermeta( get_current_user_id() , ‘uwp_mobile’, ‘notgiven2’ );//logic to get phone number from UsersWP

    $attributes[‘phone’] = $phone;

    return $attributes;
    });’

    is still passing “notgiven2” to Mautic (I appended “2” to “notgiven” to ensure that the code was still updating Mautic after the change)…..

    Plugin Contributor Paolo

    (@paoltaia)

    did you check the field key?

    Thread Starter oguruma

    (@oguruma)

    Ah, I got it working. I misunderstood. I thought I had to append the field key with uwp_.

    The field key, when entered as-is will get the right UWP user meta. So, the correct code is

    add_filter('wpmautic_tracking_attributes', function(array $attributes) {
        
    $phone = uwp_get_usermeta( get_current_user_id() , 'mobile', 'notgiven' );//logic to get phone number from UsersWP
    
    $attributes['phone'] = $phone;
    
        return $attributes;
    });
    • This reply was modified 4 years, 2 months ago by oguruma.
    Plugin Contributor Paolo

    (@paoltaia)

    excellent, glad you got it to work correctly.

    Cheers

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Fetch a custom field from the database’ is closed to new replies.