Saltar navegación

[Resuelto] Placeholders do not work with user notification (relaunch)

Este hilo está resuelto. Aquí tiene una descripción del problema y la solución.

Problem:

I have checked and I have some code inside my function.php file related to placeholders, see details here:

https://toolset.com/forums/topic/placeholders-do-not-work-with-user-notification-relaunch/#post-1179816

Solution:

This is a custom PHP codes problem, I suggest to debug those custom PHP codes line by line.

Relevant Documentation:

This support ticket is created hace 6 años. 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.

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/Hong_Kong (GMT+08:00)

Este tema contiene 4 respuestas, tiene 2 mensajes.

Última actualización por Pat hace 6 años.

Asistido por: Luo Yang.

Autor
Mensajes
#1179816

Pat

Hello,

I'm coming back to the previews ticket : https://toolset.com/forums/topic/placeholders-do-not-work-with-user-notification/

As mentioned, the placeholders in the notification mail do not work. I have checked and I have some code inside my function.php file related to placeholders (that I have created some times ago in order to use some specific fields in the notification). Do you think that this code that is currently running could explain that the standard Cred placeholders are not working (ie : perhaps the fact that I create new placeholder erase all the standard ones?).
Here is my code :

add_filter('cred_body_notification_codes', 'cb_wpcf_belongs_concours_id_placeholder', 999, 3);
function cb_wpcf_belongs_concours_id_placeholder($defaultPlaceHolders,$form_id,$post_id) {
if(($form_id == 13595) OR ($form_id == 13660) OR ($form_id == 13694) OR ($form_id == 5442) OR ($form_id == 7543) OR ($form_id == 13693) OR ($form_id == 5459) OR ($form_id == 29223) OR ($form_id == 29209) OR ($form_id == 13723) OR ($form_id == 32939) OR ($form_id == 13782) OR ($form_id == 36574) OR ($form_id == 13729) OR ($form_id == 36590) OR ($form_id == 13736) OR ($form_id == 36588) OR ($form_id == 38826) OR ($form_id == 38792) OR ($form_id == 29721) OR ($form_id == 29731) OR ($form_id == 38839) OR ($form_id == 40425) OR ($form_id == 35712)) {
$form_data_posted=get_post($post_id,ARRAY_A);

if (isset($form_data_posted)) {
$current_user = wp_get_current_user();
$concours_id = get_post_meta($post_id, '_wpcf_belongs_concours_id', true);
$chevaux_concours_id = get_post_meta($post_id, '_wpcf_belongs_chevaux-concours_id', true);
$cavaliers_concours_id = get_post_meta($post_id, '_wpcf_belongs_cavaliers-concours_id', true);
$confirmation_id = get_post_meta($post_id, '_wpcf_belongs_confirmation_id', true);
/*$tarifm_id = get_post_meta($post_id, '_wpcf_belongs_confirmation_id', true);*/

$auteur = $current_user->ID;
$auteur .= ' - ';
$auteur .= $current_user->user_firstname;
$auteur .= ' - ';
$auteur .= $current_user->user_lastname;
$auteur .= ' - ';
$auteur .= $current_user->user_email;
$concours = get_the_title($concours_id);
$confirmation = get_the_title($confirmation_id);
$chevaux_concours = get_the_title($chevaux_concours_id);
$cavaliers_concours = get_the_title($cavaliers_concours_id);
$prenom_cavaliers_concours = get_post_meta($cavaliers_concours_id, 'wpcf-ca-prenom-du-cavalier', true);

return array_merge($defaultPlaceHolders, array(
'%%champauteur%%' => $auteur,
'%%champconcours%%' => $concours,
'%%champconfirmation%%' => $confirmation,
'%%champcheval%%' => $chevaux_concours,
'%%champcavalier%%' => $cavaliers_concours,
'%%champprenomcavalier%%' => $prenom_cavaliers_concours
));
}
}

}

Regards
Pat

#1179828

Dear Pat,

It is a custom PHP codes problem, I suggest you try to debug your PHP codes manually, especially these lines:

$chevaux_concours_id = get_post_meta($post_id, '_wpcf_belongs_chevaux-concours_id', true);
$cavaliers_concours_id = get_post_meta($post_id, '_wpcf_belongs_cavaliers-concours_id', true);
$confirmation_id = get_post_meta($post_id, '_wpcf_belongs_confirmation_id', true);

The custom field "_wpcf_belongs_[SLUG]_id" is a legacy of old version of Types plugin, in the latest version of Types plugin, please try new API function toolset_get_related_post(), see our document:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_post
Retrieve an ID of a single related post. Note: For more complex cases, use toolset_get_related_posts

#1179860

Pat

Hi Luoy,

Thanks for taking care.
In fact, I do not have issue with this php code. The placeholders defined in this code are working fine and I'm getting the right info inside my Cred notifications (but I'm using the additional placeholders only for Cred postypes notification. I can understand that I need to update it with the latest Types API and I will do.

Nevertheless, my issue is that using the standard placeholders in a Cred User notification is not working. As mentioned in my previews ticket (https://toolset.com/forums/topic/placeholders-do-not-work-with-user-notification/), I have inserted this in the notification body :

Username : %%USER_USERNAME%%</br>
Nickname : %%USER_NICKNAME%%</br>
Email : %%USER_EMAIL%%</br>
Login name : %%USER_LOGIN_NAME%%</br>
User display name : %%USER_DISPLAY_NAME%%</br>
Date : %%DATE_TIME%%

And I'm getting the same thing inside the notification mail when a user subscribes !
My question for this ticket was to try to understand if the fact to use a php code for adding new placeholders could makes that the standard placeholder functions stop to work (perhaps I need to redefine all placeholders in my php function when I add a new placeholder ???).

Let me know
Regards
Pat

#1179884
mail-log.JPG

Thanks for the details, you are using right filter hook "cred_body_notification_codes", I have tried the sample codes in our document:
https://toolset.com/documentation/user-guides/how-to-use-custom-placeholders-in-cred-notifications/#0f3b6
section "Setting up a custom placeholder"

In a fresh wordpress installation + latest version of Toolset plugins, it works fine, all placeholders are displaying correctly.

For example, use PHP codes as below:

add_filter('cred_body_notification_codes', 'custom_generic_field_notification', 10, 1);
 
function custom_generic_field_notification( $defaultPlaceHolders ) {
 
    $newPlaceHolders = array( 
        '%%PRODUCT_NAME%%' => 'Some product name'
    );
    $res = array_merge($defaultPlaceHolders, $newPlaceHolders );
	return $res;
}

Create a user form for creating users, use below codes in Email body:

Username : %%USER_USERNAME%%</br>
Nickname : %%USER_NICKNAME%%</br>
Email : %%USER_EMAIL%%</br>
Login name : %%USER_LOGIN_NAME%%</br>
User display name : %%USER_DISPLAY_NAME%%</br>
Date : %%DATE_TIME%%

%%PRODUCT_NAME%%

I can see all placeholders works fine in the email, see screenshot mail-log.JPG

So the problem you mentioned above is abnormal, I suggest you check these:
- deactivate other plugins, and switch to wordpress default theme 2019, and test again
- Test a simple PHP codes in a fresh wordpress.

#1182350

Pat

Hi Luoy,

I finally founded what was the issue. In fact, as mentioned, I had created a function in order to create new placeholders inside my function.php
Even if those placeholders where not used in the Cred user form, the fact not to select this form in the php code brought the issue. I have added the user form ID in the form list :

if(($form_id == 13595) OR ($form_id == 13660) OR ($form_id == 13694) OR ($form_id == 5442) OR ($form_id == 7543) OR ($form_id == 13693) OR ($form_id == 5459) OR ($form_id == 29223) OR ($form_id == 29209) OR ($form_id == 13723) OR ($form_id == 32939) OR ($form_id == 13782) OR ($form_id == 36574) OR ($form_id == 13729) OR ($form_id == 36590) OR ($form_id == 13736) OR ($form_id == 36588) OR ($form_id == 38826) OR ($form_id == 38792) OR ($form_id == 29721) OR ($form_id == 29731) OR ($form_id == 38839) OR ($form_id == 40425) OR ($form_id == 35712)) {
$form_data_posted=get_post($post_id,ARRAY_A);

and now, everything is working fine.
Thanks for your time.
Regards
Pat