Software Engineering in WordPress, PHP, and Backend Development

Tag: WordPress (Page 168 of 219)

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

A Practical Example of The WordPress Heartbeat API

The WordPress Heartbeat API is not exactly a new feature. That is, it was first released in WordPress 3.6. Maybe I’ve just done a poor job of keeping up with what others are doing with the API, or maybe I’ve just not paid attention to some of the stuff that people are doing with the API, but I haven’t seen that many examples other than how to get started with it.

On top of that, the Heartbeat API codex is lacking in documentation (though this is an open source project, so if anyone’s to blame, it’s all of us), so perhaps that’s a reason that few people have begun to implement it into their projects.

Whatever the reason, I thought it may be worth showing a practical example of how I recently implemented it within a theme I’m working on, and how I’m using it within conjunction with the Theme Customizer so that when an administrator makes a change to the theme using the Theme Customizer, the visitor will automatically (or is it automagically?) see the changes.

Continue reading

Should There Be Developer Documentation for WordPress Themes?

For anyone who has been involved with building and/or supporting WordPress themes, then it can’t be understated how important documentation for WordPress themes can be for customers.

Generally speaking, this type of documentation refers to a manual that walks users through how to use a theme, it’s various features, and so on. I think it’s hard to argue that this is something that should be made available for everyone, or, at the very least, for those who have purchased the theme (of course, having a freely available manual can also serve as a marketing resource, but I digress).

But one thing that I don’t think talked about very often is if there should be developer documentation for WordPress themes.

Continue reading

The Beginner’s Guide to Object-Oriented Programming in WordPress

Comments are closed on this post. Please keep the discussion on each article in the series.

When it comes to writing code for WordPress, I’ve been told that I come off as someone who espouses object-oriented programming as the way to write code for WordPress.

Within theme development, that definitely isn’t true, and when it comes to plugins, it’s true only when the plugin has more than than a few functions or few moving parts that are needed to get work to done.

But one of the things that I’ve noticed in speaking with other developers is that people those who aim to start out writing object-oriented code with WordPress are kind of figuring it out as they go.

Though doing this can yield some positive results, it may also end up preventing you from learning some more of that basic techniques – or even some of the more advanced techniques – that object-oriented developers users in their day to day work.

So in my latest series on Envato, I’m working on series targeting the absolute beginner who wishes to learn object-oriented programming, and to do so within the context of WordPress.

Continue reading

How to Sort an Array by Locale in PHP

As easy as it is to translate content within WordPress, there are  times in which some of the content in the database may be different than the original locale of the site.

Say, for example, you’re running a site that includes a list of names in a flavor German when your server (or even perhaps your site) is based on an English locale. The goal is to read the names into a collection – rather, an array – and then sort them alphabetically.

Obviously, different locales have different alphabets so what works in, say, the United States won’t necessarily work in Germany.

There are a couple of ways to go about handling this, but the easiest way that I’ve found is to use PHP’s Collator class.

Continue reading

Passing Variables in WordPress: Loops

Check out the first post on passing variables in WordPress using WP_Query.

In the previous post, I shared how I used to use the following rule of them when passing variables in WordPress (and other programming languages, really):

“Only if I need to use this value more than once, then I will store it in a variable.”

And though I still think it’s a fair rule to follow, there are exceptions.

The more time I’ve spent writing code and having to maintain codebases from both myself and others, the more I’ve appreciated having variables defined – even if they are used only once – that hold more complex information for the sake of readability, clarity, and maintainability.

In the last post, I looked at an example as it relates to `WP_Query` since it’s one of the more powerful aspects of the WordPress API, but I’ve found that the same is true in simpler complex such as loops.

Continue reading

« Older posts Newer posts »

© 2025 Tom McFarlin

Theme by Anders NorenUp ↑