Home › Toolset Professional Support › [Resolved] Split: Messaging to the group/Individual user. – connect message
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.
This topic is split from https://toolset.com/forums/topic/messaging-to-the-group-individual-user/
This topic contains 0 replies, has 0 voices.
Last updated by jum 19 hours, 30 minutes ago.
Assisted by: Christopher Amirian.
Hi Minesh,
Thanks for the support
Yes now the view show result based on dynamic post ID.
2) the custom code is not updating the custom field wpcf-email-group-users
add_action( 'cred_save_data_192677', 'set_post_id_in_field_group_email', 10, 2 );
function set_post_id_in_field_group_email( $post_id, $form_data ) {
// Retrieve the parent post ID from the 'wpcf-message-to' custom field
$parent_id = get_post_meta($post_id, 'wpcf-message-to', true); // Get the parent ID from the meta field
$relationship_slug = 'uni-group-user-group';
// Get all child posts related to the parent group
$related_posts = toolset_get_related_posts(
$parent_id, // The ID of the parent post
$relationship_slug, // The relationship slug
'parent', // 'parent' means get child posts
100, // Limit (100 as an example)
0, // Offset (no offset)
[], // No additional filters
'post_id', // Get the post IDs
'child' // We're looking for child posts
);
if (!empty($related_posts)) {
$child_ids = []; // Initialize an array to store child post IDs
// Loop through each related post (child post)
foreach ($related_posts as $child_id) {
// Add each child post ID to the array
$child_ids[] = $child_id;
}
// If there are any child post IDs, update the custom field 'wpcf-email-group-users'
if (!empty($child_ids)) {
update_post_meta($post_id, 'wpcf-email-group-users', $child_ids); // Save the child IDs in the parent post's custom field
}
} else {
// Handle the case when no related posts are found (optional)
echo '
No related posts found.
';
}
}
Hello. Thank you for contacting the Toolset support.
Can you please share details of workflow where you added the form and from where I should submit the form and to what user's it should send the messages.
Please share all workflow with URLs of that and your expected result.
I have set the next reply to private which means only you and I have access to it.
Hi Minesh,
The workflow:
Group post type have many to many relationship for User post type .
Requirement: when a new message is sent to the particular group the users in that group need to get the email notification.
I noticed in your messaging module : The wpcf-message-to custom field is used for email notification.
I tried to use this method to work with some alternatives.
What i have done:
Created new form: hidden link
Message to: changed to get the current page ID(group ID)
I created a custom field in messages : email-group-users
I am trying to update this field with ID of the users in the particular group after the form submit using above code.
Then using this field to send the email notification in the form. But the field is not updating after the form submit.
Page: hidden link
same page i shared before
Please guide me how to do it or any other alternative for sending email notification to the user after the message form is submitted.
Thanks in advance,
Can you please share frontend user access details.
I mean I should login as what frontend user and send reply using the form available at bottom of the following page so that it send message to group attached to the following page:
=> hidden link
I have set the next reply to private which means only you and I have access to it.
Toolset Form's offers hook called cred_notification_recipients to modify email notification recipients on fly.
More info:
- https://toolset.com/documentation/programmer-reference/cred-api/#cred_notification_recipients
Can you please check now: hidden link
I've added the following code to "Custom Code" section offered by Toolset with code snippet "toolset-custom-code":
=> hidden link
add_filter('cred_notification_recipients', 'func_send_notification_to_child_emails', 10, 4); function func_send_notification_to_child_emails($recipients, $notification, $form_id, $post_id) { // Check notification name matches target notification if ( $form_id == 192677 ) { // Get the parent ID from the meta field $parent_id = get_post_meta($post_id, 'wpcf-message-to', true); $relationship_slug = 'uni-group-user-group'; // Get all child posts related to the parent group $related_posts = toolset_get_related_posts( $parent_id, // The ID of the parent post $relationship_slug, // The relationship slug 'parent', // 'parent' means get child posts 999, // Limit (100 as an example) 0, // Offset (no offset) [], // No additional filters 'post_id', // Get the post IDs 'child' // We're looking for child posts ); if (!empty($related_posts)) { // Loop through each related post (child post) foreach ($related_posts as $child_id) { $user_email = get_post_meta($child_id, 'wpcf-user-email', true); $recipients[] = array( 'to' => 'to', 'address' => $user_email, ); } } } return $recipients; }
More info:
=> https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_post
Hi Minesh,
Yes i receive the email notification and it works from my side.
When i select the message sent by you: group message222 it don´t see the message and reply option , it shows you cannot view this message.
I checked with new messages sent to other user in subscriber user account . I can see the reply option for that and its works
I wonder why it not showing reply to the message send by you. I have admin access so i have all permission and I dont see any condition for this post.
Thanks for the support.
Can you please share using what user you logged-in and from where you are trying to access the message and send me access details for the same user.
I have set the next reply to private which means only you and I have access to it.
Can you please tell me on what post/page I can see the reply form and what reply form is used?
Hi Minesh,
The reply form i used is the same used in your messaging module.
The reply form is in Message single item
hidden link
Reply form: Reply message
I would like to know to what single specific message you are trying to reply using the testuser you shared. Can you please share that single message URL.
This is the message i trying to reply
hidden link
now, when I try to login as "Testuser" using the access details you shared I could not able to login.
Can you please send me frontend user access details using what user I should reply to the following message?
=> hidden link
I have set the next reply to private which means only you and I have access to it.
Well - I can see the reply form on the following page:
- hidden link
And when I reply it does display afer the submit the reply form. I'm not sure what exactly is not working for you.
Hi Minesh,
I see another shortcode i added for testing is not removed properly that made confusion. I set it back to default template. Please check now
Messages->Message-single item.
The message single item template have
[wpv-conditional if="( '[wpv-current-user info='id']' eq '[types field='message-to' output='raw'][/types]' ) OR ( '[wpv-current-user info='id']' eq '[types field='message-from' output='raw'][/types]' )" debug="true"]
[wpv-post-title id="[types field='first-message-id' output='raw'][/types]"]
[wpv-view name="Related messages" field="first-message-id" raw="true"]
[/types]"]
[cred_form form="Reply message"]
[/wpv-conditional]
here for my group message it wont satisfy the condition current user == message to / message from for all user message as it was a group.
So only the sender is able to see the reply message form
Ex: for message group222 only the toolset user can see the reply form not the testuser in the group because the condition wont be satisfy.
FYI --> In group message form the message FROM- current user the Message To is the current group id.
Please guide me in this issue.
Hi Minesh ,
I tried adding a new condition OR condition for the reply form but it not working.
What i did:
when message form is submitted it update the form with the email-group-user custom field with the user id of the related user in that group.
I used this field to compare if current user is avaliable in the group then show the form
current user id== email-group-users but it not working
OR ( strpos('[types field="email-group-users" output="raw"]', '[wpv-current-user info="id"]') !== false )" debug="true"]
over all condition
-------------------------
[wpv-conditional if="( '[wpv-current-user info='id']' eq '[types field='message-to' output='raw'][/types]' ) OR ( '[wpv-current-user info='id']' eq '[types field='message-from' output='raw'][/types]' ) OR ( strpos('[types field="email-group-users" output="raw"]', '[wpv-current-user info="id"]') !== false )" debug="true"]
[wpv-post-title id="[types field='first-message-id' output='raw'][/types]"]
[wpv-view name="Related messages" message="[types field='first-message-id' raw='true'][/types]"]
[cred_form form="Reply message"]
[/wpv-conditional]
post with this field updated:
please guide me how i need to set this condition.