WP-Mix

A fresh mix of code snippets and tutorials

PHP fix exif_imagetype() error

Working on my plugin USP Pro, it’s become apparent to me that some servers for whatever reason disable the function exif_imagetype() function. So some users would get an error when trying to upload images. To resolve this, I added the following simple function to the plugin core.

PHP output buffering example

PHP’s ob_start() and ob_get_clean() are useful for buffering output of printed content and so forth, but I use them very rarely and tend to forget their order/syntax. So this post provides a quick copy/paste example that I can grab the next time I need to output buffer something.

PHP Get Memory Usage vs. Total

Here is a useful function that I modified for my WordPress plugin, Dashboard Widgets Suite. It returns an array containing the current memory usage and the total memory usage, so you can get and display a ratio of the values as needed.

PHP Get Server Information

Here are some scrap PHP scripts leftover from my work on Dashboard Widgets Suite. These functions were considered specifically for use with the System Information Widget, and provide a variety of details about the current server configuration and software setup.

WordPress Dismissible Admin Notice

Here is an easy snippet for adding a dismissible admin notice to any theme or plugin.

PHP check if file exists by URL

This quick PHP snippet can be used to check if a specific URL exists. I use this in one of my projects for checking the existence of a robots.txt file on the site. Can be modified to check for files on any publicly accessible site.

Coda 2 Shortcuts

This post is a working roundup of any/all useful shortcuts that I can find for Coda 2 (code editor and FTP software). So far, most of the shortcuts in this post are taken from Brad Strickland’s great post*. So huge thanks to Brad for sharing.

Include Google jQuery with Local Fallback

Here’s a nice snippet of JavaScript for including Google-hosted jQuery with fallback.

WordPress widget_init not working

Working on USP Pro, I noticed that the included Form Widget stopped working. It didn’t display at all, like it wasn’t even registering with WordPress. After some investigating, I discovered that changes in the WordPress core required an update to the widget code. This article explains the process of troubleshooting and the working solution.

WordPress Example Child Theme

Here is a ready-to-go example Child Theme that you can download and use on your own WordPress-powered site.

Apache Request Method Types

Here is a list of all types of Apache Request methods. GET PUT POST DELETE CONNECT OPTIONS TRACE PATCH PROPFIND PROPPATCH MKCOL COPY MOVE LOCK UNLOCK VERSION_CONTROL CHECKOUT UNCHECKOUT CHECKIN UPDATE LABEL REPORT MKWORKSPACE MKACTIVITY BASELINE_CONTROL MERGE INVALID If you know of any others, let me know — thanks! :)

WordPress Disable REST API Header Links

WordPress 4.4 adds all sorts of new REST API functionality. Which is great if your site is using it. But if not, then you may want to remove all of the extra baggage that WordPress now adds to every page load. This tutorial explains how to disable it.