JSON encoding Windows-1252 Unicode chars

While trying to use the json_encode function a Windows-1252 left and right quote character was breaking the encoding and I was ending up with no JSON. The string being encoded was from html within a PHP file. I’m guessing it was copy pasted from a Word doc. To fix this the mb_convert_encoding function, not the utf8_encode function, was needed. From … Continued

Add browser and device name to WordPress body class

Github Gist


Recursively List Video Files URL’s

This will recursively list video files (currently filtered by a ‘.mp4’ preg_match) links when put at the root of a url. Rough and not pretty but it’s functional. Github Gist  

Force Post Author Comments to Moderation in WordPress

By default in WordPress when an author of a post comments on their own posting the comment is automatically approved. This makes sense when authors are associated with the site, have access to admin, etc. There are cases where content from the general public is used to create posts and while the user is logged … Continued

Always Unset Values Passed by Reference in a Loop

I’d always read to unset the variables passed by reference in PHP’s foreach loop. Here’s an example: In the above code I was looping through a set of parent posts and using a custom method to get what I was calling the ‘current version’ which was really just the most recent child post. Then I … Continued

Allow html in Contact Form 7 error messages

Contact Form 7 has a filter where one can alter the messages being sent back to the browser called wpcf7_validation_error. A simple htmlspecialchars_decode altering the $message variable before returning will do the trick. This function will run on any error for any form you have in your site (any CF7 form that is). If you … Continued

Jetpack 404 not found: devicepx.js

Jetpack 404 not found: devicepx.js

While setting up this site I noticed some files not found errors in dev console. One was devicepx.js which was in the jetpack modules path. It’s used to optionally load retina/HiDPI versions of files. I believe it would be for gravatars and since this site doesn’t use gravatars I deemed it unnecessary. The above code … Continued

Earliest WordPress Hook Where Global $post Variable Exists

In the file wp-includes/class-wp.php there is a hook run which is simply named 'wp'. This, as far as I can tell, seems to be the earliest hook in which the $post object variable exists. The hook is passed the &$this object which the comments state: references the WP object. It allows for accessing the properties … Continued