Hello,
I need the "from" email and name fields in a notification to be populated by fields.
For instance, "email" would be [wpv-current-user info="email"] and name [wpv-current-user].
How may I do this ?
Thank you.
It is not possible in CRED.
What I can do is ask Luo, our CRED feature request master, to file this new feature as a request.
What you can try meanwhile is to use Custom Code with this CRED Hook:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_mail_header
There you can pass new Header Information as listed here:
hidden link
But only the "from" attribute is a modifiable one.
You will get the Current user Information with some basic WordPress API:
https://codex.wordpress.org/Function_Reference/wp_get_current_user
https://codex.wordpress.org/Function_Reference/get_userdata
That information can then be used to populate the CRED Hook.
There is a Code sample on the DOC page linked above.
I will assign this ticket to Luo now so that he can reply here on Monday.
Thank you.
I've looked into it and made this
/**************************************************
* Headers FROM des Notifications
**************************************************/
function customise_cred_notifications( $headers, $formid, $postid, $notification_name, $notification_number ) {
$myheaders = array();
$currentuser = get_user_by(get_current_user_id());
if ($formid==505 && $notification_number==0) {
$myheaders = array( 'From: '.$currentuser->user_email );
return array_merge($headers, $myheaders);
}
return $headers;
}
add_filter('cred_mail_header', 'customise_cred_notifications', 10, 5);
But it doesn't work... Can't understand what's the trouble in it ?!
Thank you !
Dear Roman,
Please try to modify your PHP codes as below and test again:
/**************************************************
* Headers FROM des Notifications
**************************************************/
function customise_cred_notifications( $headers, $formid, $postid, $notification_name, $notification_number ) {
if ($formid==505 && $notification_number==0) {
$myheaders = array();
$user_id = get_current_user_id();
$currentuser = get_user_by('ID', $user_id);
$myheaders = array( 'From: '.$currentuser->user_email );
$headers = array_merge($headers, $myheaders);
}
return $headers;
}
add_filter('cred_mail_header', 'customise_cred_notifications', 10, 5);
More help:
https://developer.wordpress.org/reference/functions/get_user_by/
Parameters:
$field
(string) (Required) The field to retrieve the user with. id | ID | slug | email | login.
$value
(int|string) (Required) A value for $field. A user ID, slug, email address, or login name.
Worked great ! Thank you very much.