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.

Regarding Our Efforts at Pragmatic Programming

To me, one of the most frustrating aspects of programming comes in something as seemingly trivial as how to best name and organize files. And by that, I mean the process of figuring out what to name directories and files all the way down to how to best name classes, variables, and functions.

If it doesn’t sound trivial, then maybe it just sounds silly especially to those who are more experienced programmers.

Interestingly enough, this is a bit more of a challenge for some, but not so much for others. After all, isn’t this is where standards come in to play? That is to say, isn’t this where they help us make decisions on how to avoid problems just like this?

Sure, in some ways, but there are times in which standards may not cover all cases or certain aspects of what we’re trying to do.

So what then?

If I Knew Then What I Know Now (About Code Reviews)

When I draft posts, I normally don’t aim to write to any particular age group, demographic, or personality type – I generally just share my opinions on certain WordPress-related topics and/or development-related material.

But everyone mixes it up a little bit every now and then, right?

And so if I had to define a specific type person to whom this post is most relevant, it would be any one of the following:

  • Those who are just getting into software and/or web development,
  • Those who have been into development for a while but have yet to share code online,
  • And those who spend time critiquing others who are working to get better by publicly sharing code.

Maybe this is geared more towards the usual audience, but whatever the case: this is more of a retrospective post that I would have like to have read prior to where I am now.

Title Capitalization for WordPress

When it comes to drafting and editing posts, one of the things that I often have to refer to is how to properly capitalize certain headings. I’d figure after this long, I’d actually have all of the rules memorized, but apparently that’s not the case (no pun intended :).

Anyway, in order to help with this, I was using a third-party tool for double-checking proper capitalization of post titles and heading elements. But, over time, that became a bit tedious so I created a small plugin to automatically and properly capitalize post titles and the heading elements of post content.

Stretching myself as creatively as possible, I’ve opted to call the plugin Title Capitalization for WordPress.

Thoughts on WordPress Developers, Communities, and Products

For those of you who are involved in working with building things for WordPress- specifically, premium plugins and themes – then you’re likely plugged closely into what many refer to as “the WordPress community.”

Granted, I’m not saying it’s not a community – it is – but it’s just part of the community, right? I mean, the word encompasses people who use WordPress to blog, people who are fans of the software, those who have contributed to it, those who build things with it, and so on.

All that to say, the community has a variety of facets.

And the challenge to this is that when we spend so much time with our subset of the community, it’s easy to accidentally develop a degree of tunnel vision such that we become at least partially focused on writing things, designing things, or buildings things with our part of the community in mind rather than our customers.

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.

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.

Steps To Writing Clean WordPress Code

I’d like to think that one of the things that most good developers continually strive for is writing the cleanest, most maintainable code possible.

Personally, I don’t know if there is an actual point at which you reach it – it’s the whole journey-not-a-destination thing – but that doesn’t mean that we shouldn’t continually aim to get better at what we do. In our case, that’s writing clean WordPress code.

The thing is, there’s only so far you can get on your own. You can read a number of books, follow the advice of some high profile programmers, and read as much of the “academic” material that you can get your hands on – and I think all of the above is great – but, at the same time, it only goes so far.

To that end, I think it’s worth seeking out other people in your same field to help provide some level of mentorship on how it relates to writing clean code because here’s the thing:

As much material as we can read written by other people, nothing beats interacting with those who are writing code in the same language(s) for the same APIs under the same coding standards and who are farther along than you in experience.

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.

The Importance of Using Domain Language in WordPress

In building software – especially at the enterprise level – one phrase that’s used to describe the work that goes into understanding what all needs to make up an application is that of the “problem space” or the “problem domain.”

This is important because part of the process of understanding the problem domain is learning the language, the terminology, and the concepts that go into building an application.

For example, say you’re building a job board. You’re likely to have something like:

  • Job Posts
  • Resumes
  • Recruiters
  • Employers
  • Employees
  • Candidates
  • …and so on

These ideas are then taken and ultimately converted into code.

Sometimes, developers will use the terminology associated with the problem domain (and this is part of domain-driven design) in their code; other times, the problem may get solved but the code may not completely reflect the problem space at the code level.

At any rate, one of the things that I see – as designers and/or developers – doing is using terminology that is more frequently associated with how we view WordPress than how users do.