Within public function generate_coupons( $user_id )
, on its 3rd line shows $coupon_code = substr( "abcdefghijklmnopqrstuvwxyz123456789", mt_rand(0, 50) , 1) .substr( md5( time() ), 1); // Code
Why is it mt_rand(0, 50)
instead of mt_rand(0, 34)
since there are only 35 characters in the string of the first portion?
substr( "abcdefghijklmnopqrstuvwxyz123456789", mt_rand(0, 50) , 1)
returns only 1 character
substr( md5( time() ), 1)
returns the last 31 out of 32 characters.
I’ll change the second portion to substr( md5( time() ), mt_rand(0, 31), 9) )
, which will randomly pick the start of the 32 characters, and extract the next 9 characters from that point. At least, this will shorten the overall code length to 10 characters.
By the way, is there any way not to hack into your plugin? Perhaps a hook will be better.