HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

BeforeRegister event question

AoleeAolee Hobbyist & Coder ✭✭
edited August 2019 in Feedback

Hi guys,

Sorry tried searching the forum but all i found were 2011 or 2012 posts not sure if no longer relevant. Im trying to make a simple plugin for additional validation on email during registration but seems like this event is not being called? or am i using/doing it wrongly?

Im expecting it ("BeforeRegister" hook) to be called here under UserModel

just additional note, the Plugin is enabled. also tried doing a disable -> enable plugin everytime i change my code, guessing it could be cached somewhere but still not working.

Appreciate if anyone can share their exp. thanks.



  • R_JR_J Ex-Fanboy Munich Admin

    The code looks perfectly okay. I've used that event in a small plugin as well.

    Delete the /cache/addon.json file and retry.

    Some odd behaviour which had occured to me a very few times in the past have happened when I was pasting code from somewhere: I had to retype the code! If in doubt simply manually reenter: public function userModel_beforeRegister_handler($sender, $args)

    Just a hint: debugging with var_dump often fails. I've got two alternatives for you:

    Gdn::set('Debug'.LINE, dbencode($something)); This will write to the GDN_UserMeta table

    Or simulate Vanills "decho" command by echoing to a file. Create a folder called /log. Create a file called bootstrap.before.php and insert the following code:

    function fecho($data) {
       $separatorBold = str_repeat('=', 80)."\n";
       $separator = str_repeat('-', 80)."\n";
       $stack = debug_backtrace();
       $header = sprintf(
           "FILE: %s\nLINE: %s\nTIME: %s\n",
           date("Y-m-d H:i:s")
       $content = print_r((array)$data, true);

    After that you can use it like that: fecho($something); and you will get a /log/debug.txt file with whatever you wanted to dump.

  • charrondevcharrondev Developer Lead (PHP, JS) Montreal Vanilla Staff

    Another great debugging strategy (but it only works locally): Use vanilla-docker . It has XDebug setup instructions. Alternatively you could configure XDebug yourself in the your local installation.

    Being able to set breakpoints and step through a debugger is probably the easiest way to understand what data is being passed around where in the older parts of Vanilla (such as the non-interfaced, old event system that a lot of plugins use).

  • AoleeAolee Hobbyist & Coder ✭✭

    Hi @R_J thanks , this is exactly similar to the plugin I wanted to do but I plan to use https://quickemailverification.com/ for the verification. they seem to offer decent free 100 validations per day and since I dont get more than 50 signups, i thought it would be a good idea to try them.

    I noticed the only difference with our code is the method name's case sensitivity . i'll try yours :)

    Once I've completed this small plugin. ill share it with you guys too.

    @charrondev ill try this one out too :) Many thanks for sharing.

  • charrondevcharrondev Developer Lead (PHP, JS) Montreal Vanilla Staff

    I noticed the only difference with our code is the method name's case sensitivity . i'll try yours :)

    I'll just note that this shouldn't make any difference. PHP methods are case insensitive, so whether the method is named in all-caps, all lower-case, the way you wrote it, or the way @R_J wrote it, will have no effect.

    Our own coding standard for official Vanilla repos is the way that @R_J configured it though.

  • AoleeAolee Hobbyist & Coder ✭✭

    sorry it was a rookie mistake. I seem to have missed the "Plugin" in the classname

    class Quickemailvalidation<Plugin> extends Gdn_Plugin {


  • AoleeAolee Hobbyist & Coder ✭✭

    All looks good, these pesky spammers (one who always post links from the Activity) are being blocked now (52 unknown) and what's good is. only valid email counts towards the 100/day free credits!

    BTW I'm trying to upload the plugin but I'm getting a License requirement. Can't figure out what was changed. Is this correct?

    Im getting the error below during plugin upload.

  • R_JR_J Ex-Fanboy Munich Admin

    Not sure if uppercase/lowercase could be a problem but a) I would use an addon.json instead where all keys need to start with lower case letters and b) if you use a PluginInfo, you should start keys with an upper case letter

  • AoleeAolee Hobbyist & Coder ✭✭

    HI @R_J still cant upload, getting a weird issue after uploading

    Here are my addons.json content and also the plugininfo array

    plugininfo array

  • R_JR_J Ex-Fanboy Munich Admin

    I do not have a new plugin at hand to try it out by myself, therefore you must test everything that I can think of, sorry. Contributing shouldn't be so hard :-(

    Can you please delete the PluginInfo? addon.json is there to replace it

  • AoleeAolee Hobbyist & Coder ✭✭

    just removed the PluginInfo but same error :(

  • R_JR_J Ex-Fanboy Munich Admin

    Can you attach the plugin here so that I can try some things out?

  • AoleeAolee Hobbyist & Coder ✭✭

    Hi @R_J Sorry gotten a bit busy the past few weeks.

    Here's my plugin. note that ive removed the .json file from this version

    It works great so far from my end. Happy that those pesky spammers are no longer spamming my activity page with unwanted url links.

    e.g feel free to browse my site: xxxxxx

    This plugin checks for disposable + checks for unknown + invalid (no mx record) + offers suggestion whether it's safe to send to the email address used in Registration page.

    Please do share to me your solution if you managed to find the issue.

  • R_JR_J Ex-Fanboy Munich Admin

    I've simply renamed the file to Quickemailverification.zip and used the description from the plugin as a normal description:

    This plugin uses QuickEmailVerifcation API to validate email during Registration. Sign up for a free account to get an API KEY. Free account is entitled to 100 validations per day. Consider Purchasing credits from them if you find it very useful and 100 validations per day is not enough.

    With that I could upload the plugin without any problems at all. I've already deleted it so that you can upload it again.

  • AoleeAolee Hobbyist & Coder ✭✭

    Thank you @R_J ! Managed to upload it this time. :)

Sign In or Register to comment.