WordPress

Articles, tips, and resources for WordPress-based development.

Pragmatism in WordPress: On Agility

Dave Thomas, for those who aren’t familiar, is a notable programmer for both co-authoring The Pragmatic Programmer and for running the The Pragmatic Bookshelf company. In my opinion, he’s a fantastic person to follow if you’re into programming of any kind.

A few months ago, I stumbled across an article that he had written (that many of you have read) entitled Agile is Dead (Long Live Agility). It’s a great read for anyone who’s interested, and though I’m not particularly interested in talking about all of the things his article hits on, there are two specific things that I found relevant to anyone who is just getting started writing WordPress code, or who has been writing WordPress code for sometime and may need a refresher.

Using Ajax in WordPress: Loading Pages

About a month ago, I wrote a post about single page tabbed navigation in WordPress. In the post, I made the following statement:

In some cases, it may be best to load pages via Ajax, in some cases, it’s better to load things up all in the first page load. This particular post is about the best strategies for that (that’s a debate for another post).

And I then I received the following comment:

I am also very interested and awaiting post regarding your take on when to use ajax and when to load it all.

Without context, this is a really broad question and it’s that I don’t think can be answered in a prescriptive way. When you’re trying to paint a solution for web development with broad strokes when each problem is a bit more unique, it’s not easy to provide advice that’s applicable across the board.

But this comment was about a very specific example and a very specific use case.

A Dilemma of the WordPress Customizer

In the past, I’ve talked quite a bit about the WordPress Customizer. I think it’s one of the best features for both developers, designers, and users because of how quickly it shows the user the result of changes s/he is making to their site by changing a few options.

On top of that, the Customizer has two ways in which the preview pane can load the content:

  1. Ajax
  2. Refresh

That is to say that once the user changes an option, the entire preview pane can be refreshed (or reloaded), or the changes can be performed via Ajax and the page never refreshes.

Generally speaking, I think Ajax is preferable to performing a refresh, but I’ve recently found myself working on a project where I’ve had to mix the two, and I’m not really liking it. Chalk it up to a personality quirk, but I have this “all or nothing” mentality when it comes to how the preview pane displays its changes.

Either all of the options should work via Ajax, or all of the options should trigger a refresh but mixing the two feels off.

Programmatically Add Multiple Post Terms in WordPress

A couple of weeks ago, I shared a simple gist for how to programmatically add post terms in WordPress. If you’ve read the series on importing CSV files into WordPress, then you’re likely to encounter something like the following scenario:

Given a CSV, apply multiple terms to a single post when the terms are delimited by another character.

So, for example, let’s say that you have a CSV and each value is, naturally, separated by a comma. Within one of the columns, words – or terms, in our case – are delimited by semicolons. Each value that precedes a semicolon represents a term (related to any given taxonomy in the system – this is irrelevant for this particular post).

Adding multiple terms to a post, or post type, is relatively simple and can be based off the functionality already shared.

WordPress and Small Team Source Control

Whenever I’m in the process of working on something for a client, my usual setup is something like this:

  • Work on the code on my local machine’s development environment
  • Keep the code in source control using GitHub
  • Use Dploy.io to deploy the latest commit to a staging server
  • Repeat until ready to launch

Straightforward enough, right?

But there have been a couple of times when I’m working with designers or front-end developers who need to work on, say, CSS files while I continue to do some of the backend work.

If they’re comfortable working with source control, then granting them access to the repository of the project and having them commit their changes to be part of the deployment process works fine.

But what about the case where the frontend developer is going to be working on various styles that you won’t personally be touching, and they aren’t using source control during the development phase of the project?

Importing CSV Files into WordPress: Clean Up

This is part three four a series for how to Import CSV Files into WordPress.

Over the past few posts, I’ve walked through a strategy that I’ve found to useful and effective when importing large CSV files into WordPress.

Specifically, I’ve broken the approach down into three other articles each of which covers a high-level overview of how to achieve a certain part of the process through a mix of PHP, JavaScript, and pseudo-code.

Up to this point, I’ve covered:

  1. How to setup the script to prevent timeouts
  2. Working to build a back end that supports visual cues on the front end
  3. How to display visual cues on the front use via Ajax

And the last part is by far the easiest: Clean up after yourself.

Importing CSV Files into WordPress: Visual Cues, Part 2

This is part three of a series for how to Import CSV Files into WordPress.

As mentioned in the previous post, one of the problems that comes with importing CSV files into WordPress – specifically large files – is giving the user feedback that something is happening while waiting for the process to complete.

But when your’e doing this within the context of a web application, it takes a little bit more work because everything happens in a single process. If you don’t show your users any feedback, then it looks as if the page is just sitting there.

Then again, because the process can take so long, you need to let the user know that something is happening.

Importing CSV Files into WordPress: Visual Cues

 

Within the context of web applications, you can do that by using client-side JavaScript to essentially poll the server and ask for status updates.

Importing CSV Files into WordPress: Visual Cues, Part 1

This is part two of a series for how to Import CSV Files into WordPress.

One of the problems that comes with importing CSV files into WordPress isn’t the process that comes with actually doing it but that comes with the work that happens while processing a large dataset.

That is, on staging and production servers, we are subjected to the constraints of the PHP environment which may end up resulting in PHP timeouts. In order to help combat this, there are a number of things that we can do the first of which is to split up our input file into smaller files (which I discussed in the previous post).

Importing CSV Files into WordPress: Visual Cues, Part 1

Obviously, the idea behind this particular strategy is to create smaller files that we can import one at a time that won’t result in a PHP timeout issue (since smaller files clearly result in less data to import). Though this comes with another challenge: giving the user visual cues that something happening while they wait for the import process to complete.

There are a few strategies for doing this, but I’ll cover the process that I’ve used at a high-level and at which I’ve found to work well given lots of information and constraints above.

Importing CSV Files into WordPress: Preventing Timeouts

This is part one of a series for how to Import CSV Files into WordPress.

This is one of set of posts that I hesitated writing because I don’t know how applicable it really is because it’s going to be dealing with talking about how to achieve something at an abstract level without using any real code examples.

And it’s not that I think talking about algorithms or procedures without code is bad (we all use pseudo-code, right?), I’m just not sure if it’s one of those series of articles that’ll help someone or not.

But I can’t be the only one who’s encountered these issues, so I’ll give it a shot. And this is going to be spread out over a few posts.

Importing CSV Files into WordPress: Preventing Timeouts

One of the more common tasks that you’ll see in web application development deals with importing data usually in some file type (often times which is CSV though other file formats are becoming more popular). A challenge, though, with importing data via CSV – especially a large data set – comes with giving the user visual feedback as to how the process is going.

And when it comes to importing CSV files into WordPress, the same rules apple. Importing large data sets and relying on the API to take care of, say, creating posts, associated taxonomies, and adding media can be a time consuming process.

But there are some strategies that we can employ that will help to ensure:

  1. There won’t be any PHP timeouts
  2. The importer gives visual cues without blocking the page load
  3. The functionality cleans up after itself when it’s done.

Though there are a number of ways to attack this particular problem, here’s how I’ve been doing it, as of late.

Include a WordPress Theme Style Guide

In a previous post, I questioned whether or not we should exclude a WordPress theme style guide from our themes when releasing them to our customers.

On the one hand, I think that a case can be made that we should exclude them. In short, I said that:

Offering up a style guide that helps users deviate in any way from the core design, the one that’s created from a level of expertise, is something I think isn’t worth creating.

But there’s another side to all of this. Specifically, what if the theme itself is just one component that’s part of an organizations overall brand?