Posts: 792
Threads: 47
Joined: Aug 2011
2012-06-18, 05:47 PM
(This post was last modified: 2012-06-18, 05:58 PM by Frank.Barry.)
Im playing about with the datahandler hooks to trigger post/thread errors and have an issue when using:
$plugins->add_hook("datahandler_post_validate_thread", "test_run");
When I use the hook above and the function below to trigger errors while creating a "new thread", the error displays but if the condition is true, the error still displays and prevents the thread from being created. Any ideas why ?
function test_run()
{
global $db,$mybb,$forum,$fid,$posthandler,$post,$thread;
if ($forum['fid'] == 1)
{
$mess = $post['message'];
if(strlen($mess) < 50)
{
$posthandler->set_error("Error Message Here.....");
return false;
}
}
}
Posts: 13,283
Threads: 159
Joined: Oct 2010
Reputation:
1,291
2012-06-18, 05:55 PM
Your hook second parameter and the function name are not same.
Posts: 792
Threads: 47
Joined: Aug 2011
2012-06-18, 05:58 PM
Thats a typo in the post sorry, thats not the issue.
Posts: 13,283
Threads: 159
Joined: Oct 2010
Reputation:
1,291
2012-06-18, 06:07 PM
OK, Try this;
function test_run()
{
global $db,$mybb,$forum,$fid,$posthandler,$post,$thread;
if ($forum['fid'] == 1)
{
$mess = $post['message'];
if(strlen($mess) < 50)
{
$post->is_validated = false;
$post->set_error("Error Message Here.....");
return $post;
}
}
}
Posts: 792
Threads: 47
Joined: Aug 2011
2012-06-18, 06:17 PM
Nope, getting this:
Fatal error: Call to undefined method stdClass::set_error()
Posts: 4,846
Threads: 180
Joined: May 2007
Reputation:
254
2012-06-18, 07:05 PM
you are using the hook wrong by missing the parameter for the handler pointer
function test_run(&$handler)
{
global $db,$mybb,$forum,$fid,$post,$thread;
if ($forum['fid'] == 1)
{
$mess = $post['message'];
if(strlen($mess) < 50)
{
$handler->set_error("Error Message Here.....");
}
}
}
Lost interest, sold my sites, will browse here once in a while. It's been fun.
Posts: 792
Threads: 47
Joined: Aug 2011
2012-06-18, 08:35 PM
(This post was last modified: 2012-06-18, 09:06 PM by Frank.Barry.)
I'll try that later but how come this hook works fine on post replies ? How come that doesn't need the parameter ?
$plugins->add_hook("datahandler_post_validate_posts", "test_run");
EDIT
@paveman : I've tried that code you posted above, its not working, I get the same result as my original code.
Posts: 4,846
Threads: 180
Joined: May 2007
Reputation:
254
2012-06-18, 10:22 PM
try adding "return true;" just above the last "}"
Lost interest, sold my sites, will browse here once in a while. It's been fun.
Posts: 792
Threads: 47
Joined: Aug 2011
2012-06-18, 10:28 PM
(2012-06-18, 10:22 PM)pavemen Wrote: try adding "return true;" just above the last "}"
No, still not working. Its weird because Ive no problems using the following hook to trigger an error when replying to a thread, it also works without adding the parameter:
$plugins->add_hook("datahandler_post_validate_posts", "test_run");
Posts: 4,846
Threads: 180
Joined: May 2007
Reputation:
254
2012-06-19, 12:11 AM
using the parameter just means one less global pointer getting created, since the parameter being passed is the local representation of the posthandler.
looking at the code, i can't why you are having issues unless it is a priority thing conflicting with another plugin using that hook.
try
$plugins->add_hook("datahandler_post_validate_thread", "test_run", 1);
Lost interest, sold my sites, will browse here once in a while. It's been fun.
|