php fatal error $message->send()
-
Hello everyone, thanks in advance.
I’m trying to filter messages through ‘messages_message_before_save’ action hook.
When the test is positive, I remove the recipient with unset.
If I have no recipients I get a php error.[22-Nov-2015 14:25:22 UTC] PHP Fatal error: Call to a member function get_error_message() on a non-object in xxxxxxxxxxxxxx/wp-content/plugins/buddypress/bp-messages/bp-messages-actions.php on line 104
.....bp-messages-actions.php......... ................................. // Message could not be sent. } else { $success = false; $feedback = $send->get_error_message(); //LINE 104 bp-messages-actions.php }
It’s because I have not created an error message.
I tried with:bp_core_add_message( 'Message error.', 'error' );
but don’t works.
How can i fix this?
This is my code.
function messages_control($args){ if(!is_super_admin()){ foreach($args->recipients as $key => $value){ $receiver = $value->user_id; if( $receiver === X ){ // X is an integer error_log('MESSAGE UNSET'); unset($args->recipients[$key]); } } if(empty($args->recipients)){ bp_core_add_message( 'Message error.', 'error' ); // ???????? } } } add_action('messages_message_before_save','messages_control',10,1);
Thanks in advance. Sorry for my english…..
-
If I have no recipients I get a php error.
Are you sure the problem is you have no recipients?
Once
messages_control()
returns, the following code is executed immediately:if ( empty( $this->recipients ) ) return false;
This will ensure the message isn’t sent if you have no recipients.
@garprogram – This fatal error is due to some changes we made in BP v2.4.0 to give users proper feedback messages when a private message fails to send.
It looks like we might have to add some additional hooks so plugin devs can set the error message.
In the meantime, here are two things I would recommend:
1. Use the
'bp_messages_recipients'
filter instead of using the'messages_message_before_save'
action:
https://buddypress.trac.wordpress.org/browser/tags/2.4.0/src/bp-messages/bp-messages-actions.php?marks=77-84#L772. As Henry mentioned, if you have to unset one recipient, you should unset all of the recipients to avoid the message from sending. The default error message will probably not suit your needs, so you might have to filter the error message with the
'gettext'
filter temporarily until we introduce better error handling for plugin developers.
- The topic ‘php fatal error $message->send()’ is closed to new replies.