Software Engineering in WordPress, PHP, and Backend Development

Category: Notes (Page 25 of 49)

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

Easily Install phpDocumentor Alongside MAMP Pro

In previous posts, I’ve talked about the WordPress Coding Standards, and the importance of documenting your code, but I’ve not actually spent a lot of time discussing how easy it is to actually generate documentation for your themes.

And by documentation, I mean an actual site that provides your DocBlocks such in a clean and organized fashion – you know, sites that are generated by tools like phpDocumentor.

phpDocumentor Example

An example of a site generated by phpDocumentor.

In other posts, I’ve mentioned that I use MAMP Pro for part of my development stack, so if you’re looking for steps to install phpDocumentor, it’s actually really easy to do.

Continue reading

Including a Template in a WordPress Plugin (Well, a Template Part)

Late last year, I wrote a post that provided a way on how to include a page template in a WordPress plugin. There’s an accompanying project on GitHub that’s been maintained and relatively-well updated since.

Although this post is similar in nature, it doesn’t exactly deal with templates, but parts of code that may be considered partials (or template parts, in WordPress).

Let’s say that you’ve got a single post and you want to append a template to the end of the content. The content can be a little more complicated that markup because that’s easy enough to do inline, isn’t it?

So, for all intents and purposes, let’s say that we have a partial that includes a form that can be used to submit some type of information.

Continue reading

Simplifying Code in WordPress: Option Arrays

Let’s say that you’re working on a plugin that has its own plugin settings page, and on that page there are options to determine what type of posts will support part of the functionality of the plugin.

For example, let’s say this plugin will be introducing a meta box for each post type that extends the type of information that the user can add to a post. The settings page allows you to control which post types will offer this information.

To give a concrete example, take a look at the following screenshot:

Simplifying Code: Options Arrays

Granted, it’s a small example but it makes the point: We have a plugin settings page that displays all of the post types that are in the current theme installation. If selected, we’ll save the values to an options array.

When it comes time to read the values, there are a couple of ways to go about doing it, but one that’s arguably simpler than all of the rest.

Continue reading

Adding Tabbed Navigation in WordPress for Custom Menus

One of the nicest features of the latter versions of WordPress includes the custom menu system. Although people can always introduce too many areas in which custom menus can be introduced, the core feature and customization options make it possible to do some really cool stuff with custom menus.

Case in point: With many of the popular front end frameworks that are now available, such as Foundation and Bootstrap, it’s really easy to add tabbed navigation in WordPress in templates, widgets, and so on.

Though there are a number ways of to do this, one flexible way that I’ve used multiple times requires two things:

  1. A function for retrieving the post IDs for the post types contained in a custom menu
  2. An instance of `WP_Query`

At that point, all you need is the name of the menu for which you want to retrieve the post IDs.

Continue reading

Adding Multiple Sections on WordPress Options Pages

One of the most confusing aspects of working with WordPress is the Settings API.

In an attempt to make a little bit easier to understand, I’ve written a series that takes a long look at the API as well as an example project that’s available for download for others to study (and to contribute to in order to improve).

But, as with most things in programming, there are still things that can crop up now and again that can leave you scratching your head. Case in point: Let’s say that you want to introduce two sections (or three or four, even) to a single options page.

Unless you do this correctly, you’re likely to notice that the ‘Save Changes’ button will only save the changes to the last group of options. Luckily, there’s an easy way to keep your options logically grouped while also maintaing serialization through a single ‘Save Changes’ button.

Continue reading

« Older posts Newer posts »

© 2025 Tom McFarlin

Theme by Anders NorenUp ↑