Steve Grunwell

Open-source contributor, speaker, and electronics tinkerer

Category: Code

A rainbow made of different file folders

Working with profiles for new sites in WordPress Multisite

I wanted to take a quick moment to share a pattern I stumbled upon last week while building something for a client: this particular client runs a large, multisite WordPress network and often needs to be able to provision new sites quickly. In this case, we recently built an new theme designed to handle press sites for live events (photos, transcripts, live streams, etc.), and while I could automate a lot of the setup process (there’s literally a one-click “set all of the defaults for me” button on the dashboard), provisioning the new site still means creating the site as a Network Admin, assigning the theme, and clicking that button.

It’s good, but we can do better.

Continue reading→

A photo of a mountain with increasingly smaller copies of the same image overlaid on top.

Automatically Set WordPress Thumbnail Sizes When Switching Themes

Right now, one of my main projects at work is a totally new theme for the official news outlet for a major corporation. Along with a million other changes, one thing that needs to happen ASAP after switching to the new theme is that the image thumbnail sizes – controlled through Settings › Media in wp-admin – need to be changed.

Of course, being the lazy, automation-obsessed developer that I am, I wanted to find a way to automatically set these thumbnail sizes the instant we changed themes. Fortunately, where there’s a hook, there’s a way to make this happen automatically.

Continue reading→

Ron Burgundy and the Channel 4 News Team (from the film Anchorman: The Legend of Ron Burgundy) jumping into the air

Cropping and Resizing Animated Gifs with Gifsicle

I recently had an interesting request on a client project: how can we resize animated gifs without losing the animation in the thumbnails? WordPress lets you upload animated gifs, but as soon as it resizes them the thumbnails are decidedly less animated. As a purveyor of fine, animated gifs, I can tell you that an animated gif with no animation is no gif worth having!

Fortunately, there’s a free, open-source library called Gifsicle designed to manipulate animated gifs. The fun part is using Gifsicle to resize your gifs for you, automatically.

Continue reading→

How did I not know about get_post_types_by_support()?

Every once in a while (well, more often then I’d care to admit, actually), WordPress core surprises me with a function that I had no idea existed. They often come in the form of utility functions, things written when developers decide “oh no, I have to write this piece of logic again?!”. Heck, there have even been talks on these hidden little bits of code that make the world a brighter place.

Today, that function is get_post_types_by_support().

Continue reading→

Generating a new Reveal.js presentation using a Yeoman generator

Building Presentations with Reveal.js

As I mentioned in my Exporting Reveal.js Slides to PDF Using Decktape post last week, I tend to use Reveal.js – a HTML- and JavaScript-powered presentation framework – for most of my conference talks. Having given a fair number of presentations using the framework over the last few years, I thought it might be useful for speakers who haven’t yet tried (or found their footing with) Reveal.js if I laid out my preparation workflow.

Continue reading→

Cranes constructing a new building

WordPress Plugins: Procedural or OOP?

As you may be aware, I have a profile on PHP Mentoring and am currently working with a number of PHP developers looking to grow their skills and kick-start their careers. Last week, I received an interesting question through the site, and half-way into writing my response I realized it would make a useful blog post: when writing a WordPress plugin, should I be using procedural or object-oriented programming?

Continue reading→

Close-up of a Rivera guitar amplifier

Getting started with AMP for WordPress

Late last year, Google and other organizations rolled out the open-source Accelerated Mobile Pages (AMP) Project, with the goal of introducing lightweight, lightning-fast content for users on mobile devices. AMP is essentially a subset of HTML and scripts – optimized for caching and performance – designed to speed up the mobile web and to make content accessible to every user, regardless of connection speed or strength.

A few months ago, 10up President Jake Goldman published What Google’s Accelerated Mobile Pages (AMP) means for Consumers, Publishers, and the Future, a piece that has helped spark a lot of interest in Accelerated Mobile Pages among 10up’s clientele, a group lined with major publishers and news outlets. In the article, Goldman concludes that publishers “in a crowded or hotly contested news space, or seeing meaningful traffic to stories from Google, need to quickly prioritize AMP HTML.”

Continue reading→

Enhance your Editorial Experience with Advanced Post Excerpt

I recently released Advanced Post Excerpt, a free plugin that replaces the standard WordPress “Post Excerpt” meta box (a plain textarea) with a stripped down TinyMCE editor instance. Finally, there’s no need for your authors to write HTML (or copy it out of the “Text” tab of the main editor); instead, they’re given the essentials for WYSIWYG text editing (bold, italic, link, etc.) and nothing more.

Continue reading→

Announcing WP404

I’ve been behind on announcing new projects, but I wanted to make sure I shared this one:WP404 is a framework for capturing additional information and details about WordPress 404 errors, packaged as a WordPress plugin.

The plugin was born out of a need to capture tricky, time-based 404s on a client site. I figured I could either throw something together quickly on the client’s dime or spend my lunchtime and evening building something the community could use. Guess who didn’t want a half-assed tool? ?

Continue reading→

Announcing WP Enforcer

Anyone who’s had to do code reviews on a team before can tell you that inconsistent coding standards add a lot of unnecessary noise to the review process. Even minor things like trailing whitespace, spaces v. tabs, code indentation, and whitespace (or lack thereof) around function declarations can cause merge conflicts and increase the time it takes to do a good code review.

Fortunately, coding standards are pretty easy to check, and there are great tools like PHP_CodeSniffer that can scan your codebase for issues with coding standards. WordPress has a well-defined set of coding standards, and there’s even a collection of PHP_CodeSniffer standards for WordPress. With Composer and a little bit of configuration we can check our coding standards, catch common security issues (missing input sanitization, output escaping, etc.), and even validate that everything’s well-documented.

We have the tools to write standards-compliant code, so now we just have to configure them and make them run automatically. That’s where my latest project comes in: I’m happy to announce WP Enforcer is available for your projects!

Continue reading→

Page 4 of 7

Be excellent to each other.