Steve Grunwell

Open-source contributor, speaker, and coffee snob

Category: WordPress

Sunsetting WP Password Generator

My WP Password Generator plugin was my first foray into WordPress plugin development. It started back in 2010, just over a month after I started at Fahlgren Mortine, when my friend Greg Laycock and I were working on a client’s WordPress site and decided that manually generating passwords was a total pain. I suggested “what if we have a ‘Generate Password’ button on the user edit screen?”, he agreed, and I spent that night writing a quick plugin that makes an Ajax call to a script that generated a password. After we submitted it to the repository, we watched the download counts climb (I remember how thrilled we were once we crossed 100, and it just continued to rise from there).

As time went on, feature requests rolled in through the plugin forums and GitHub, but we intentionally kept the features simple (it’s a password generator, not a whole user management suite, after all). It was eventually rewritten to better adhere to the WordPress coding standards and use the native WordPress wp_generate_password() function instead of my home-rolled solution (which was actually pretty similar). It was never the flashiest plugin, but it was a perfect learning experience for both WordPress plugin development and managing an open-source project.

Continue reading→

Quick Tip: Prevent OneAll from Creating New Users

I’m working on a site right now that uses the Social Login plugin by OneAll, which is the first time I’ve dealt with users logging into a WordPress account via social networks. The plugin works really well, but I ran into one major issue: new user accounts were being created when matches weren’t found.

This particular project is a BuddyPress site for a fraternity; brothers can log in to see private events, content, and the full roster but the general public can only see the public pages. There’s also a public roster page with basic information about each member (name, graduation year, major, etc.), but those are dynamically generated by listing all BuddyPress members (excluding my team’s accounts, of course). Out of the box, OneAll would create a new user account for anyone who tried to log in, resulting in my mug appearing in the roster right along all the registered fraternity members…yikes!

Continue reading→

Automatically Set a Poster Image for WordPress Video Embeds

I’m working on a client project right now that makes heavy use of embedded videos. It’s exciting because as someone who primarily develops themes and plugins for marketing sites (and whose personal blog is almost exclusively text and code) it’s rare that I really spend much time with the rich-media embeds that have been getting so much attention from the core team over the last few releases.

As I started playing with the video embeds I immediately noticed an issue – there was nothing in the media widget that allowed authors to set a poster frame (the static image that appears in the video player before the user clicks the play button). I checked the documentation for the


shortcode and found that the shortcode does accept an optional poster attribute, which allows authors to specify a poster image.

Continue reading→

Quick Tip: Restrict a WooCommerce Shipping Method to the Contiguous United States

Right now at work I’m working on moving a site from WP eCommerce to WooCommerce and encountered an interesting request: the site offers free shipping but only to the lower 48 United States. That means no free shipping for Alaska, Hawaii, Puerto Rico, etc.

Out of the box WooCommerce supports country-based filtering (e.g. allow free shipping to the United States but not Canada) but to get into more specific restrictions you’d have to start messing with shipping tables or buying the Advanced Shipping Rates plugin which, although I’ve heard good things, will set you back $200.

Fortunately I was able to put together a code snippet that will remove a shipping method (in this case, free shipping) for restricted states. It consists of two parts: a class that extends the WooCommerce core shipping class (WC_Shipping_Free_Shipping for this example) and a filter that tells WooCommerce to use our class rather than the core shipping class it extend Post has been updated to work with newer versions of WooCommerce.

Continue reading→

WordPress Security Basics

Each year thousands of websites are hacked. Sometimes it’s by way of a crafty social engineer (someone who tricks someone into giving up information without realizing it) conning some unsuspecting user out of his/her login. Other times it’s a backdoor in some code that grants a malcontent access to a site.

If your site is running on WordPress you can rest easy – WordPress core is considered to be a very secure application. The downside to WordPress core being secure is that if someone breaks into your site you likely have nobody but yourself to blame. Never fear: these tips will help keep your site safe and sound.

Continue reading→

Quick Tip: is_login_page() Function for WordPress

When building WordPress themes, I typically try to keep as much code as possible out of the head section of my template and instead rely on the wp_head() action hook. By putting all of my wp_register_script() and wp_register_style() calls in one function I have a single place to manage (theme) assets and their dependencies. At the bottom of the function I usually like to enqueue my global scripts and styles (ones that will always be present) but am careful to keep them from appearing in the WordPress administration area.

Continue reading→

Using WordPress Advanced Custom Fields Exports

I wrote about Elliot Condon’s Advanced Custom Fields plugin a while ago (see “Using Advanced Custom Fields for WordPress“), but I thought it might be helpful if I spent some time discussing how to overcome one of the most frustrating tasks related to the plugin: preserving custom field structures across WordPress environments.

The average WordPress developer may edit the custom fields in his or her development environment, write the code to display those fields, then manually re-edit the custom fields on production. Misspell a field name? Congratulations, you’re going to spend some time trying to figure out where you went wrong. The smart developer takes advantage of the Advanced Custom Fields export methods and doesn’t waste time doing the same thing over and over again.

Continue reading→

Quick Tip: Override WordPress Toolbar Styles

I’m working on a project right now that uses the WordPress Toolbar, that dark-colored bar at the top of the administration area (and optionally your site) since version 3.3, as part of the site template. Unfortunately the default styles didn’t quite cut it for this project, so I needed to come up with a way to override these styles with my own.

Continue reading→

Keeping WordPress Under [Version] Control with Git

Over the last year or so I’ve been deploying my sites and applications almost exclusively through Git. It took a while to get used to, but pushing all of my code through git has forced me to think through my code before committing (lest I get git blame’d), kept me concentrated on the task at hand, and has made collaborating with other developers so much easier. Deploying WordPress sites through Git require a little configuration; this article outlines my personal Wordpress-Git workflow.

Continue reading→

Quick Tip: Set the Default Display Name for WordPress Users

I started work on a new WordPress site this morning and, after creating a couple of users, quickly got bored manually setting each user’s nickname and display_name properties in order to display authors as “firstname lastname.” I found a few forum posts in the WordPress support forums for “how do I automatically set the display name for WordPress users?” that had partial answers but no real solutions. Then I stumbled on this article by Rares Cosma that had just what I needed.

Rares’ solution uses the user_register WordPress action hook, which gets triggered when a new user account is registered. I modified his original version, streamlined it a bit, and applied the ‘firstname lastname’ pattern to both the display name and the nickname attribute.

Continue reading→

Page 3 of 4

Be excellent to each other.