There is a function called messages_send() in start.php file of the messages plugin. I want to add a function called push_notification_message() within that function at line 320. So my final code will look like this:
if (($recipient_guid != elgg_get_logged_in_user_guid()) && $notify) { $recipient = get_user($recipient_guid); $sender = get_user($sender_guid); $subject = elgg_echo('messages:email:subject', array(), $recipient->language); $body = elgg_echo('messages:email:body', array( $sender->name, $message_contents, elgg_get_site_url() . "messages/inbox/" . $recipient->username, $sender->name, elgg_get_site_url() . "messages/compose?send_to=" . $sender_guid ), $recipient->language ); notify_user($recipient_guid, $sender_guid, $subject, $body);
push_notification_message($sender->name, $sender->username, $recipient->name, $recipient->username, $message_sent->title, $message_sent->description); // <- I want to add this here}
How can I do this without modifying the original source code.
info@elgg.org
Security issues should be reported to security@elgg.org!
©2014 the Elgg Foundation
Elgg is a registered trademark of Thematic Networks.
Cover image by RaĆ¼l Utrera is used under Creative Commons license.
Icons by Flaticon and FontAwesome.
Just add this code in your own plugin. That's all
You mean to say that entire messages_send() function along with my push_notification_message() function in my own plugin?
In that case, if there is any update in the core file, I have to manually update it on my plugin. Wouldn't that be a hectic job. Isn't there any easy way?
Then register action:
And call:
Sorry, RvR. I don't think you can "just add this code in your own plugin". You can't replace a function by adding a function with the same name. It simply won't work.
But it might be possible if you don't add your code to the messages_send() function. Instead you can register a plugin hook callback function for the 'send', 'notification:email' and / or the 'send', 'notification:site' plugin hooks. Within the callback function you can then add your own code. This plugin hook is triggered when a message is sent to a user. See engine/lib/notification.php in the function notify_user what parameters are given to the plugin hook when triggered. Within the callback function you can retrieve these parameters to work with.
@iionly
I've meant: put the same code with another function's name in your own plugin.
But I forgot about notify_user, really ...
This is what I am trying to do: https://github.com/manlui/elgg_with_rest_api/issues/1#issuecomment-182927651
Can anyone help me with the code that I have to write in my start.php of my plugin.
This is my push_notification_message() function:
@iionly.. this is what I did:
I added the following plugin hook in my init function
and the mobile_notifications_send code is like
but this is not working. Any suggestion/Idea on how can I know that this function is even being called?
Print something to the server error log from the handler:
Using echo doesn't work because the handler gets called during an action, not during loading a page that is displayed to the user.
Nothing is being generated in my error log file.
Here is my code: https://github.com/rohit1290/elgg_with_rest_api/blob/master/web_services/start.php
Can you tell me why isn't the function being called?
Is the site_notification plugin enabled and is the user setting for receiving site notifications enabled for the user account receiving the notification? Otherwise, the 'send', 'notification:site' plugin hook won't get triggered when the message is sent.
- Previous
- 1
- 2
- Next
You must log in to post replies.