Hi,
I am new to elgg plugin programming and I am currantly doing some small excercises that don't add any great functionality but more for practising reasons.
I don't know what I am doing wrong here, I have been stuck on this for quite a while now: On the event that a user 'friends' another user I want to log the event to the browser log (which is activated). Debuggin with XDebug showed me that my funciton 'new_relationship_log' is not even called. It's probably a very small and stupid error, but I just can't find it. I'd appreciate any kind of help! Thanks!
Here is what the code in start.php of my plugin looks like:
<?php
/*
*
*/
elgg_register_event_handler('init', 'system', 'new_relationship_init');
function new_relationship_init(){
elgg_register_event_handler('create', 'friend', 'new_relationship_log');
}
function new_relationship_log($event, $type, $object) {
elgg_dump("function called");
$user_one=get_entity($object->guid_one);
$user_two=get_entity($object->guid_two);
$name1=$user_one->name;
$name2=$user_two->name;
$subject = elgg_echo('new_relationship:subject', array($site->name));
$message = elgg_echo('new_relationship:body', array($name1, $name2));
elgg_dump("Subject $subject");
elgg_dump("$message");
}
?>
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.
- Matt Beckett@Beck24
Matt Beckett - 0 likes
- Jerome Bakker@jeabakker
Jerome Bakker - 0 likes
- Tom Schelo@tomschelo
Tom Schelo - 0 likes
- ihayredinov@ihayredinov
ihayredinov - 0 likes
- Matt Beckett@Beck24
Matt Beckett - 0 likes
- iionly@iionly
iionly - 0 likes
- Tom Schelo@tomschelo
Tom Schelo - 0 likes
You must log in to post replies.Are you using the plugin 'friend_request'?
If so then that's your problem, that plugin unregisters the event so it never gets called. I got stuck on that a while back too.
https://github.com/ColdTrick/friend_request/issues/4
@Matt Beckett:
I forgot about this, but yes that could be the issue ;)
Thanks for your help! But unfortunately I'm not using that plugin. Any other thoughts?
Have you tried calling add_entity_relationship() directly? Have you tried logging directly with error_log()?
yeah, maybe elgg_dump isn't doing what you're expecting. When in doubt, I use var_dump($var); exit; and blatantly interrupt the process to see what's going on.
The way you are using elgg_dump the error message would be displayed on the screen. This might be failing due to the debug settings on your site set in the admin section.
Try
elgg_dump("function called", false, 'NOTICE');
This way the output gets added to the log file. Check if it is there. If not, the function quite surely does not get called (for whatever reason). If you see the log entry though, you know at least that it gets called and there's another reason it is not shown on the screen.
I appreciate your help! For whatever reason it still won't fire with the event. Since this was only an excersise I will no longer waste my time on this. If it occurs again and I find the solution I'll post it here! :)