Skip Navigation

[Resolved] Email notification about new message – refers to

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.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 4 replies, has 2 voices.

Last updated by dirkF-2 11 months, 2 weeks ago.

Assisted by: Waqar.

Author
Posts
#2602441

Email notification about new message

In the email notification about a new message I would like to include which post this message refers to.

At the moment my code looks like this:

<p>Hi [types usermeta='firmenname' user_is_author='true'][/types],</p>
<p>A new message has received from: %%USER_DISPLAY_NAME%%
<p>Message: [types field='nachricht'][/types] [wpv-post-excerpt length="80" more="..."]</p>
<p>This is an automated email, please do not reply to it.</p>
<p>You can answer <a href="[wpv-post-url]">directly here</a>.</p>

Which placeholder can be used to indicate which post this message refers to?

#2602801

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

To use the title and the URL of the post where the new message form was submitted, you'll need to register custom placeholders for the email notifications:
https://toolset.com/documentation/programmer-reference/forms/how-to-use-custom-placeholders-in-cred-notifications/

For example:


add_filter('cred_subject_notification_codes', 'custom_generic_field_notification', 10, 1);
add_filter('cred_body_notification_codes', 'custom_generic_field_notification', 10, 1);

function custom_generic_field_notification( $defaultPlaceHolders ) {
	$newPlaceHolders = array( 
		'%%current-post-title%%' => $_REQUEST['current-post-title'],
		'%%current-post-url%%' => $_REQUEST['current-post-url']
	);
	return array_merge($defaultPlaceHolders, $newPlaceHolders );
}

The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.

After that, you'll be able to use these new placeholders in the email notifications, by following these steps:

1. In the form 'New message', you'll include two new hidden type generic fields:

a). first field's slug will be 'current-post-title' and for the default value you'll use the shortcode '[wpv-post-title]'.

b). second field's slug will be 'current-post-url' and for the default value you'll use the shortcode '[wpv-post-url]'.

2. And in the form's notification, you'll be able to call these field's values through the newly registered placeholders, like this:


<p>This message was sent related to <a href="%%current-post-url%%"> %%current-post-title%%</a>.</p>

I hope this helps and please let me know if you need further assistance.

regards,
Waqar

#2603711

I followed your instructions and now it works! Thank you!
The code "A new message has received from: %%USER_DISPLAY_NAME%%" is used as information from whom the message was sent.
I have tried to use a placeholder in which the company name (this is also requested during registration) is also provided. But I did not succeed. During registration, the company name receives the slug "firmenname". How can I include this information as placeholder?

#2604309

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thanks for the update and glad that it worked,

For the 'firmenname' field, you can add another hidden generic field with slug 'current-post-firmenname' and in the default value use the shortcode:


[types usermeta='firmenname' user_is_author='true'][/types]

Next, you can update the code from my last reply, to also include the placeholder '%%current-post-firmenname%%' for this new field too:


add_filter('cred_subject_notification_codes', 'custom_generic_field_notification', 10, 1);
add_filter('cred_body_notification_codes', 'custom_generic_field_notification', 10, 1);
 
function custom_generic_field_notification( $defaultPlaceHolders ) {
    $newPlaceHolders = array( 
        '%%current-post-title%%' => $_REQUEST['current-post-title'],
        '%%current-post-url%%' => $_REQUEST['current-post-url'],
        '%%current-post-firmenname%%' => $_REQUEST['current-post-firmenname']
    );
    return array_merge($defaultPlaceHolders, $newPlaceHolders );
}

And in the message's content, you'll be able to call this field's value using the placeholder '%%current-post-firmenname%%'.

#2604541

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.