MyBB Community Forums

Full Version: Need help with add_hook
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
How to add a hook to quick reply please?

$plugins->add_hook("datahandler_post_validate_post", "wordfilter");
$plugins->add_hook("datahandler_post_validate_thread", "wordfilter");
http://docs.mybb.com/MyBB_Plugin_Hooks.html - there is no specific hook for quick reply. You can try modifying it by hooking to showthread_end though. But I'm not sure what you exactly mean and need.
Actually, you can hook to newreply_do_newreply_end and check for $mybb->input['ajax']: if present, the post was made via the quick reply box.
I have created a simple plugin to block URLs but for some reason error message doesn't show when posting through quick reply help me to fix this issue?

if(preg_match($regex, $post->data['message'], $match))
    {
        $post->errors['urlfilter']['error_code'] = "Your post has triggered our moderation system!<br/> Please make sure you are not posting any URL as you YET can't post any!<br/> Also check for any grammar errors!";
    }
@shade:
Can't it be done with this?
if($mybb->input['method'] == "quickreply")
{
	// Do something ...
}
(2014-01-06, 10:38 PM)marcus123 Wrote: [ -> ]I have created a simple plugin to block URLs but for some reason error message doesn't show when posting through quick reply help me to fix this issue?

if(preg_match($regex, $post->data['message'], $match))
    {
        $post->errors['urlfilter']['error_code'] = "Your post has triggered our moderation system!<br/> Please make sure you are not posting any URL as you YET can't post any!<br/> Also check for any grammar errors!";
    }

The post datahandler has already validated your post at newreply_do_newreply_end. You will need to hook @ datahandler_post_validate_post instead and set an error like this:

$this->set_error("Your post has triggered our moderation system!<br/> Please make sure you are not posting any URL as you YET can't post any!<br/> Also check for any grammar errors!");

Or using an error code of your own and add a language variable in newreply.lang.php.

Strip off that $match variable also. You don't need it.

(2014-01-06, 11:56 PM)effone Wrote: [ -> ]@shade:
Can't it be done with this?
if($mybb->input['method'] == "quickreply")
{
	// Do something ...
}

Also. But other plugins might use the quick reply system without actually setting the method to quickreply, so you might lose some functionalities. Checking for the ajax token will cover them as it's used also in the core.
Guys thanks very much I have just changed how the error shows and now it works great