Software Engineering in WordPress, PHP, and Backend Development

Category: Notes (Page 26 of 49)

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

Updating a WordPress Post in the Save Post Action

For those who have worked with WordPress long enough, you’re likely familiar and comfortable with how hooks works – that is, you’re familiar and comfortable with the event-driven design pattern.

Sure, it’s a bit different than many other frameworks and foundations that use MVC, MVVM, and some other remix of the model-view paradigm, but I don’t think that’s really here nor there in terms of which is better. This is what WordPress uses and it’s easy enough – and powerful enough – to work with once you’ve got it.

But that’s not to say it’s not without it’s nuances.

For example, one of the challenges of working with event-driven design is understanding how hooks work throughout the page lifecycle, how it’s possible to actually get stuck in an infinite loop if you’re not careful, and how to work with the various hooks to prevent this from happening.

Continue reading

Two Solutions for “JavaScript Reference Error Is Not Defined”

If you’re working on any type of web site or web application that has any other dependencies either for its front-end framework – such as Bootstrap and Foundation – or from the site’s foundation – such as Rails or WordPress – there’s a chance that your own JavaScript sources may result in the following:

Reference Error [variable] is not defined.

In some cases, this can be simply referring to a variable that isn’t defined (perhaps the most popular is when jQuery’s $ function has been dereferenced and you’re trying to use $) and simply needs a definition.

But, in other cases, there are times where it may not be as simple.

Continue reading

A Dilemma: Hiding Elements with The WordPress Theme Customizer

When it comes to working with the WordPress Theme Customizer, one of the options that you’re likely to see in other themes (or that you’re likely to introduce in your own themes) is an option that is responsible for toggling the visibility of an element.

For example, if a text box is empty, you may want to hide an element. Or, more simply, perhaps a user will need to click on an checkbox to toggle whether or not to display an element.

But this presents a dilemma: Either we can send all of the information to the browser and control its visibility using a class name, or we can send less code to the browser but lose a smooth user experience when using the Theme Customizer.

Continue reading

How To Define a New WordPress Cron Schedule

Last year, I shared how to properly setup a WordPress cron job in which I walked through the process of defining a cron job in the operating system so that a job fires as a true scheduled task (rather than the faux tasks that WordPress provides).

This isn’t to say that the native WordPress scheduled tasks are bad – they just may not work as expected for those who are used to native cron jobs.

Another limitation of the the WordPress scheduling system is that it defines only a handful of intervals in which your tasks may run. These include:

  • `hourly`
  • `daily`
  • `twicedaily`

And these are fine for a lot of tasks, but if you’re looking to define a new WordPress cron schedule, you’ll need to define a custom filter.

Continue reading

How to Set an SMTP Server in WordPress

When it comes to sending emails in WordPress, the wp_mail function and its related filters such as wp_mail_content_type, wp_mail_from, and wp_mail_from_name are usually enough to accomplish the majority of what we need.

But there are times where it’s not enough. Specifically, there are times where we may need to define the details for using a custom SMTP server in WordPress.

Fortunately, WordPress provides a hook that makes this really easy to do.

Continue reading

« Older posts Newer posts »

© 2025 Tom McFarlin

Theme by Anders NorenUp ↑