In Which Contexts are Plugins Responsible for Data Validation/Sanitization?

I want to make sure all of the data in my plugins/themes is handled securely before entering the database and before being output to the browser. My problem is that there are situations where the API handles the sanitization for you — like when saving post meta fields — and others where the plugin/theme author … Read more

Remove type attribute from script and style tags added by WordPress

Warning: The type attribute is unnecessary for JavaScript resources. From line 10, column 146; to line 10, column 176 feed/” /> <script type=”text/javascript”>window Warning: The type attribute for the style element is not needed and should be omitted. From line 11, column 1798; to line 11, column 1820 </script> <style type=”text/css”>img.wp Warning: The type attribute … Read more

Validate decimal numbers in JavaScript – IsNumeric()

What’s the cleanest, most effective way to validate decimal numbers in JavaScript? Bonus points for: Clarity. Solution should be clean and simple. Cross-platform. Test cases: 01. IsNumeric(‘-1’) => true 02. IsNumeric(‘-1.5’) => true 03. IsNumeric(‘0’) => true 04. IsNumeric(‘0.42’) => true 05. IsNumeric(‘.42’) => true 06. IsNumeric(‘99,999’) => false 07. IsNumeric(‘0x89f’) => false 08. IsNumeric(‘#abcdef’) … Read more

How can I validate an email address using a regular expression?

Over the years I have slowly developed a regular expression that validates most email addresses correctly, assuming they don’t use an IP address as the server part. I use it in several PHP programs, and it works most of the time. However, from time to time I get contacted by someone that is having trouble … Read more