Archives For Tips

Various articles covering anything from how to programmatically achieve a certain task to useful ways that I’ve found to manage my time.

One of the things that Pippin, Norcross, and I have been talking about during the course of building Comments Not Replied to is the best practices for instantiating WordPress Plugins.

Specifically, we’ve gone from simply creating an instance of the plugin, to storing it within the PHP $GLOBALS variable, as well and then debating whether or not to implement the plugin as a singleton.

Screen Shot 2013-02-19 at 10.27.46 AM

There’s more to this that I’ll cover in a follow-up post, but the most significant thing worth sharing in this post is why we’re discussing how to instantiate our plugin.

Continue Reading…

In a previous post, I’ve mentioned that GitBox is my git client of choice. In short, I think it’s UI is simple and it’s extremely easy to manage all of the standard git tasks.

GitBox

And, of course, if you find yourself needing to issue some commands from the command line, it’s really easy to install git for the command line.

But for anyone that’s done an any amount of work with source control, you know that a portion of your time is resolving merge conflicts and sifting through code using a diff tool to help manage the merging.

Though there’s a lot of good options available, the latest version of Kaleidoscope has become my favorite application for managing code diffs. After installing it, here’s how you can configure it for your environment.

Continue Reading…

For those of you who have read my previous blog posts, you know that my local development environment consistents of using MAMP for Apache, PHP, and MySQL.

Though I’m not particularly hardcore about any given IDE, I’ve been using Coda 2 since it was released and have enjoyed it especially because of its integrated database environment.

But with the need to work with several other remote databases outside the context of an IDE, and the recent release of Sequel Pro 1.0, I thought it may be useful to share how I’ve also been using Sequel Pro with MAMP.

Continue Reading…

Thanks to a number of open source contributors, I released WP Audio Player 1.3 to the WordPress plugin repository. For one of the pull requests, I mentioned the following:

I always terminate my blocks with a closing comment. Please keep this in the file.

Travis Northcutt also asked me about it via Twitter:

When it comes to writing code, I try hard to make sure that anything I do that’s outside of the normal coding conventions for a given platform has a rationale behind it.

Case in point: Ending my terminating braces with code comments.

Continue Reading…

Although Automattic uses Subversion for source control both for its themes and plugins, I keep a number of my plugins in Git repositories during development.

Additionally, 8BIT uses GitHub to keep track of all of our source code, issues, milestones, and so on. When it’s time to make a commit, we usually sync the Git repository with its Subversion equivalent.

I’ve used a number of different source control systems during my career – some distributed, some not – and I’ve never been someone who fights a so-called religious war over which is better. Each source control system has its advantages, disadvantages, and each one fits differently within the context of how a person or a team operates.

Currently, I really like Git but a lot of that has to do with how GitHub, the site, fits into my workflow. Sure, there are things about Git that I like, but it’s GitHub’s organization that fits how I do work.

Anyway, overtime I figured I’d discuss my thoughts on WordPress source control. In this post: commit messages.

Continue Reading…

One of the nicest and most flexible aspects of the WordPress API is the ability to associate meta data with certain models – for lack of a better term – in the database.

That is, we can assign meta value to Users, Posts, Authors, and so on.

Retrieving the data is typically trivially easy. Simply supply the ID of the model in question and then pass the key value for said post meta.

But what if you need to get the post ID or post meta key by the meta value instead?

Continue Reading…

When it comes to WordPress development, there typically tends to be two camps (with a third that’s on the rise):

  1. There are theme developers
  2. There are plugin developers
  3. Then there is the growing field of application developers

Personally, I’m a fan of building plugins. Obviously, it’s not because I have anything against building themes, but I’m a programmer – not a designer – by nature, so I add to the WordPress experience through functionality rather than functionality and design.

In fact, I think if I had to design, it’d probably take away from the experience :) .

But plugins are software and there are problems that have existed as long as software has existed. In fact, entire markets have been created around said problem: filing bug reports.

I’m not here to provide the ultimate solution for how to provide a WordPress plugin bug report – if that existed, it would have been solved long before today; however, I do want to share a couple of things that I’ve noticed.

Continue Reading…

If you're an experienced developer, you may wish to skip to the code.

If you’ve ever done any work with building a plugin or building a feature of a theme that includes a custom meta box or that includes functionality that is fired on the save_post action, then you’ve likely seen WordPress save_post called twice.

The thing is, this is expected behavior, but because of how it’s used, you may not always want your code to execute until the user actually clicks on the save button.

So here’s a quick tip on how to properly manage the case when save_post is called twice.

Continue Reading…

If you're an advanced developer, then you may want to skip directly to the code.

As soon as you begin working on an advanced plugin or an application in which you try to maintain some form of solid cohesion (or even an API), then you end finding that there’s a function you need that isn’t available in the Codex.

This isn’t unique to WordPress. Any programming language that has a rich API ultimately has a set of solid features that allow you to build upon them to write more power functions.

For me, I try to publish most of my helper functions here on the site. It makes things searchable, available, and even available for code review for the more critical readers :) .

Case in point: In a recent project, I needed to find the permalink by slug in WordPress and there wasn’t a function available to do exactly that, so here’s what I ended up doing.

Continue Reading…

Personally, I’m a big fan of implementing coding standards and/or style guides for each of our various languages. Ultimately, I think that it helps to make a team’s code more readable and maintainable.

On one hand, some developers are better at adopting said standards than others, whereas other developers enjoying helping to write the documentation, books, and pull requests to make sure code is up to the given standard.

Although I’m personally a big fan of coding standards, there’s always room for small improvements in each language that help optimize a developer’s work flow.

As such, I thought I’d share two things that I do as part of my HTML code styles that help make code more readable and improve the workflow in my IDE.

Continue Reading…