Software Engineering in WordPress, PHP, and Backend Development

Category: Notes (Page 36 of 50)

Notes on programming-related problems that I’ve encountered while working on various projects.

What’s The Proper Way To Instantiate a WordPress Plugin?

When it comes to plugin development – be it either widgets or plugins – there are several different ways in which we can instantiate a WordPress plugin.

Unfortunately, you’re likely to get a different answer depending on who you ask, or what you read.

Case in point: According to the WordPress Codex, instantiating a WordPress widget is done like this:

add_action( 'widgets_init', create_function( '', 'register_widget( "foo_widget" );' ) );

But I know several people who are adamantly against using create_function.

Though I personally don’t have a problem with it, I’m always interested in hearing others’ approach to how they do it and why.

So in this post, I thought I’d lay out the various ways to instantiate a WordPress plugin, pros and cons of each, but also ask each of you what your favorite method is and why.

Continue reading

Resolving WordPress jQuery Errors

One of the biggest problems with writing and maintaining themes and/or plugins in WordPress is the frustration that comes with having to track down JavaScript errors.

Pippin Williamson has discussed this extensively on his blog, we’ve covered it on WP Daily, and I’ve talked about this once before here.

But since I’ve seen this issue crop up several times since, I wanted to offer some additional thoughts on this particular topic that has stemmed from the recent discussions.

Continue reading

Quick Tip: Delete a Git Tag

As much as I love GitBox, it doesn’t actually provide the ability to delete tags from within the interface:

GitBox and The WordPress Plugin Boilerplate

GitBox and The WordPress Plugin Boilerplate

Sad, right?

Occasionally, there are times in which I need to remove a tag because I need to go back and make some final adjustments to a commit prior to pushing to my current branch (which is usually just `master` anyway).

This means that I need to hop over into Terminal to issue a few git commands in order to delete a Git tag from the command line.

Continue reading

WordPress Refactoring: Refining Plugin Functions

Whenever it comes to writing code – be it starting a new project or working with an existing system – there are a lot of developers that aim to write clean, maintainable code.

It’s a challenge for sure, but it’s not impossible. Even if you’re responsible for simply introducing a new function into an existing system, there’s an opportunity to leave the place a little better than you found it.

Granted, trying to refactor a larger system too much can have serious unintended consequences, so I don’t necessarily advocate doing that, but if you have the opportunity to break a one larger function into several smaller, more focused functions, then I think the opportunity should be taken.

I recently had a chance to do a bit of WordPress refactoring in the context of a commissioned plugin I am working on, and wanted to share the process that I followed for doing so.

Continue reading

Finding Functions in WordPress (Those Not in The API)

As significant as the WordPress API is in building plugins, themes, and applications, there are often times where we may find ourselves needing to write custom functions to achieve something that we know WordPress already does.

Case in point: With Page Template Dashboard, I wanted to be able to show the name of the template rather than the filename. I knew WordPress was doing it, but I couldn’t find an actual API function for it.

So what’s the best thing to do in this particular situation?

Continue reading

« Older posts Newer posts »

© 2025 Tom McFarlin

Theme by Anders NorenUp ↑