The server is probably telling you to run the plugin in debug mode because there is an error. If you turn on debug mode, then you can see exactly which line of code is causing the error.
I'm guessing stock_replace_all() is causing an error, the rest looks ok.