Skip Navigation

[Resolved] Email Notification to a User ID Specified in a Generic Field

This support ticket is created 7 years, 4 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 2 replies, has 2 voices.

Last updated by Noriko Sugiura 7 years, 4 months ago.

Assisted by: Beda.

Author
Posts
#548867

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?

#549013

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.

#549122

Thank you. I will try what you suggested.