Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Comment Body Modification
I was having trouble modifying comments via a plugin I am working on, so I decided to modify the source code and see if my code was just wrong or if there was something wrong in my plugin setup.
By putting my code in the source file, I am able to modify a comment before it is saved by adding this line:
As line 489 of the class.commentmodel.php file. Basically, it just appends a bit of text to the end of a comment, no big deal.
Unfortunately, I cannot get this to work from my plugin. The entirety of my default.php plugin file is below:
As I mentioned, the comment is not modified properly when the code is placed in the plugin file.
I'm trying to figure out where to go from here. Any thoughts?
My initial thoughts are:
1. &$Sender is unable to be modified via a plugin
2. There is some additional setup for the plugin required that I did not notice (it shows up in the plugin manager and it is enabled, though)
3. My code is wrong. Maybe I should reference the body in a different way.
Any help would be greatly appreciated.
Thanks!
John
By putting my code in the source file, I am able to modify a comment before it is saved by adding this line:
$Fields['Body'] = $Fields['Body'] . " Hello world!";
As line 489 of the class.commentmodel.php file. Basically, it just appends a bit of text to the end of a comment, no big deal.
Unfortunately, I cannot get this to work from my plugin. The entirety of my default.php plugin file is below:
<?php
// Define the plugin:
$PluginInfo['DiceRoller'] = array(
'Name' => 'Dice Roller',
'Description' => 'Dice Rolling Plugin for Play By Post RPGs.',
'Version' => '0.1',
'Author' => "John Hesch",
'AuthorEmail' => 'galwinganoon@yahoo.com',
'AuthorUrl' => 'toasty-fish.com'
);
class DiceRollerPlugin implements Gdn_Plugin{
public function CommentModel_BeforeSaveComment_Handler (&$Sender){
$Sender->$Fields['Body'] = $Sender->$Fields['Body'] . " Hello world!";
}
}
As I mentioned, the comment is not modified properly when the code is placed in the plugin file.
I'm trying to figure out where to go from here. Any thoughts?
My initial thoughts are:
1. &$Sender is unable to be modified via a plugin
2. There is some additional setup for the plugin required that I did not notice (it shows up in the plugin manager and it is enabled, though)
3. My code is wrong. Maybe I should reference the body in a different way.
Any help would be greatly appreciated.
Thanks!
John
Tagged:
0
Comments
public function CommentModel_BeforeSaveComment_Handler ($Sender){ $Sender->Fields['Body'] = $Sender->Fields['Body'] . " Hello world! "; }
But it still does not modify the comment.
$Sender->EventArguments['FormPostValues']['Body'] .= ' Hello';
It's possible it's $Sender->EventArguments['FormPostValues']->Body instead, sorry a bit rusty at the moment.
I'm wondering if the plugin is actually being read... Even when it's enabled, I can't get anything to happen. For example, I tried throwing an exception, but nothing happened.
Is there more to setting up a Plugin than:
1. Creating a folder (DiceRoller, in this case)
2. Creating a default.php file with code (see above for my code)
3. Uploading these into the /plugins directory
4. Enabling the plugin on the dashboard?
Thanks
John
For posterity, I had to change:
class diceRoller implements Gdn_Plugin {
to
class diceRoller extends Gdn_Plugin {
Before Vanilla would actually process my code. I'm not sure what the difference is, so I can't give a great explanation about why this is the case.
It would have been nice had Vanilla given an error or something, but I wasn't getting anything.
Anyway, Lincoln, the first suggestion you provided:
$Sender->EventArguments['FormPostValues']['Body']
Was right on as far as how to access the comment body.
I'm going to clean the code up a bit and try to figure out how to publish the plugin on this site.
There was an error rendering this rich post.
Plugin live at:
http://vanillaforums.org/addon/diceroller-plugin