HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Get the post/topic creator name
vanillawhisky
New
in Feedback
Hallo Forum,
I guess this might be the simple questions for you guys.
How do you get the post creator name.
for example: with echo userAnchor($Author, 'Username');
you get the user name.
And I want to check if this user is also a post creator. something like this:
if ($Author) == $postCreator) { echo'this user is also a post creator'; } else { echo'this user is not a post creator'; }
The above code is just an example just to make my question clear.
I would appreciate your help.
Thank you!!!
Tagged:
0
Comments
So you are looking at a comment? In most cases you have
$sender->EventArguments['Discussion']
available and you can check$sender->EventArguments['Comment']->InsertUserID == $sender->EventArguments['Discussion']->InsertUserID
But if you tell us which event you are using, it would be much easier.
Yes I am looking at comment. On discussion.php (where you get post heading) you have
$sender->EventArguments['Discussion']
and I also tried writing$sender->EventArguments['Discussion']
on comment page but it gets null value.I tried this:
and I get null value. So how can I proceed.
When I put this in a plugin, I get the correct information.
Maybe the problem is the way you write your code. Do you use plugins and themehooks or are you trying to override files?
I am not using from plugins and themehooks but trying to overwrite helper_functions.php file in a function
if (!function_exists('WriteComment')):
Örks. Are you really convinced that this is needed? Most of the times using css and a themehooks file is all you need.
But anyway:
$Sender->EventArguments['Discussion']->InsertUserID
will give you the discussion authors user id in this case.In your code above you've used an ampersand before the variable name. I do not know why you have done so, but I bet it was the reason why your first try wasn't successful.
Well this 'ampersand ' is by default from vanilla. even without 'ampersand ' the result is same, NULL.
In views/discussion/discussion.php this code
$Sender->EventArguments['Discussion']->InsertUserID
works fine but not in views/discussion/helper_functions.php because here are only comments not the discission titles (i guess).Can you please test,if possible, in yours and let me know.
my main task is to see if the creator comments on his own discussion .
For example if I comment on my own discussion then beside my name there will be small text with 'creator'.
I hope you understand my question.
as an exaple , you can see schreenshot in spoiler.
I want this text just in comment section .
Yes, it is working for me. But instead of overriding a view, that would be the way to achieve what you've asked for:
Do you know about themehooks? Create a custom theme and put that code in your themehooks file.
And if you would like to only style such comments differently, you would use something like that:
... just to show you what you can achieve with Vanilla events
I also tried with themehooks but ,dont know why, its not working.
I created a file class.themehooks.php in themes/mythemename/class.themehooks.php.
and inside i have this code:
and now when I trigger an event in \themes\mythemename\views\discussion\helper_functions.php with:
<?php $Sender->fireEvent('AuthorInfo'); ?>
I get nothing.
Is there anything missing?
I also tried with test value:
public function discussionController_authorInfo_handler() { echo ('testing'); }
as a matter of fact , this function is never called.
Can you please suggest me what is wrong ?
The filename of your themehooks file must be class.yourpluginsnamethemehooks.php
Well Thanks. This atleast works. So what about this document http://docs.vanillaforums.com/developer/theming/hooks/
is this wrong ?
But my problem ist still ON.
In \themes\mythemename\views\discussion\helper_functions.php,
I have:
(note: if i dont use 'ampersand' it says undefined variables. )
and in themehook, when I var_dump the commented userID, it gives the value:
Output is : /.../themes/mythemename/class.whiskythemehooks.php:13:int 19068
But when I try to discussion`s userID ,it gives null:
Output is : /.../themes/mythemename/class.whiskythemehooks.php:13:int null
@R_J
Well I found the problem.
I forget to get the discussion data fron Gdn Controller.
so the solution is:
Since I have rewrite only the 'WriteComment' function,
In \themes\mythemename\views\discussion\helper_functions.php, add
$Discussion = Gdn::controller()->data('Discussion');
and everything works fine.
Thank you for your time @R_J
@R_J just wondering, How can I mark my discussion as solved?
Yes, obviously. You can correct it here and help others!
I don't know. A mod would have to do it, but I don't think it is that important...
If it is only one or the other function that you like to replace, I would advice you not to replace the complete file. Just add those functions e.g. below the themehooks class