messages_new_message sends double the threads when running more than 12 times in
-
I’m running Buddypress Version 2.9.2.
I have a need to send messages to multiple recipients from one sender.
I do this thru php.
My code is below.
When I have less than about 11 receipients the procedure works.
When I have 12 recipients the page seems to hang and it creates 2 messages to each recipient.
I’ve put echo messages to debug in bp-messages-functions.php and without a debugger can’t see what’s happening.
I was successful sending from one sender to a large array of recipients.
The problem with that is it’s a group message and one recipient replies they reply to all the recipients and the original sender.
<?php
//$arrayTrainers = [118,120,122,123,124,131,132,133]; //works$arrayTrainers = [76,77,81,82,118,120,122,123,124,131,132,133]; //doesn’t work
foreach ($arrayTrainers as $Recipient) {
$args = array(
‘sender_id’ => $Sender,
‘recipients’ => $Recipient,
‘subject’ => $subject,
‘content’ => $longcontent);
$lastThread = messages_new_message( $args ) ;
} //foreach
?>
-
messages_new_message()
accepts an array argument. “recipients” can be an array of user IDs. Try this:$args = array( 'sender_id' => bp_loggedin_user_id(), 'recipients' => array( 76, 77, 81, 82, 118, 120, 122, 123, 124, 131, 132, 133 ), 'subject' => 'Test subject', 'content' => 'Test content' ); messages_new_message( $args );
Yes that method works fine for me.
I was successful sending from one sender to a large array of recipients.
The problem with that is it’s a group message and one recipient replies they reply to all the recipients and the original sender.
That method is a message conversation between one sender and all the recipients.
If a recipient replies the other recipients get that reply.
I want many one way conversations, not one conversation with many.
I ended up writing my own code to send messages.
Now I can send many messages as needed for my website.
I suspect this in a php plugin issue when it gets in a longer for loop since when I have larger numbers to loop thru the code seems to take much much longer.
I think I’ll put my code in a plugin.
If someone has this issue again.
It may be something in my code also.
But I don’t know how to debug step thru the php code on a web page.
Thank you for your valuable post and information.As a developer in BEST SOFTWARE COMPANY IN OMAN ,i loved your post.Its very good information for me.I expect more post from you.
- You must be logged in to reply to this topic.