I have a CRED form containing the following field:
[cred_generic_field field='opponent' type='hidden' class='' urlparam='']
{
"generic_type" : "user_id",
"required":1,
"validate_format":0,
"persist" : 1,
"default":"[types field='opponent'][/types]"
}
[/cred_generic_field]
Then I set up a notification for a user specified in a form field.
The "opponent" field contains the user login, not the user ID. I tested with the user ID and notification works, but not with the user login.
My problem is that I only have the user login where I am using my CRED. I don't have the user ID. Thus, is it possible to send a notification specifying the user login?
If it's not possible, I think I will have a workaround by creating a shortcode such as "get_user_id_by_login", but was wondering if there is an easier way to do it. Perhaps changing that "generic_type : user_id" to something else?
With that CRED Generic Field, you will send notifications that are set as "Send notification to a WordPress user specified in a form field".
There you have to choose a Field that is populated with an ID of the User, there is no way around that.
But if on the form you can access the User Login, you can also access the ID.
Both are in the User Object, hence, accessing them is the same, just the argument of output changes.
https://codex.wordpress.org/Function_Reference/get_currentuserinfo
How do you get the User Login into the Field [types field='opponent'][/types]?
With https://developer.wordpress.org/reference/functions/get_current_user_id/?
I suggest to use get_currentuserinfo and create Custom ShortCode, or, use the Views ShortCode [wpv-user field="ID"].
This can get the ID of the current user or of any specified user.
I assume you need the current logged in user, as such, that will work.
If not, then you would need maybe to get the User by some other criteria.
Hence a Custom ShortCode would probably be the way to go.
Thank you. I will try what you suggested.