Software Engineering in WordPress, PHP, and Backend Development

Category: Notes (Page 21 of 49)

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

How To Remove TinyMCE Buttons From WordPress

Depending on the level of customization or the level of formatting your customer wants or you want to give your users as it relates to the WordPress post editor, you may need to remove TinyMCE buttons from the WordPress editor.

Although it’s relatively easy to remove all of the buttons and, say, focus only on the HTML view, it’s also possible to remove individual buttons from the post editor so that the user only has a subset of the options that are typically available.

TinyMCE Buttons

TinyMCE Buttons

Say, for example, you want to remove everything from the second row exception the formatting drop-down that let’s you select the heading size, paragraph, or pre elements. It’s easy to do this using one of the hooks that WordPress provides.

Continue reading

Organizing WordPress Meta Box Code

When working with themes or public-facing views for a website, WordPress components can generally be thought of in three distinct areas:

  1. Templates are used for rendering the view (that is, the markup and the styles) of data.
  2. Partials are reusable fragments of templates.
  3. Helper Functions are used to help process, format, and generally work with data.

As far as templates and partials are concerned, these are relatively common with themes or working with anything on the front-end, but we don’t see it as much as we do when talking about the context of the Dashboard.

But when it comes to working with the back-end, all of these things are still applicable. Sometimes you’ll see them in isolation – like with helper functions – other times, all three things can work together such as in the case of meta boxes.

That is, you have a function for defining the meta box, a function for rendering the meta box (which can include a template), and then the template may have multiple parts – or partials – such as the contents for various tabs.

Continue reading

Display Post Meta Data Error Messages in WordPress

One of the things that’s nice bout working with post types – custom or standard – in WordPress is that it’s really easy to hook into the serialization process in order to handle the data. This means that we have the ability to sanitize, format, read, access, modify, verify, etc. all of the data with the post type and with the post type’s meta data before it’s written to the database.

WordPress has a pretty consistent way of displaying error messages throughout the application. Really, it’s pretty consistent in how it displays all types of messages – success, updates, and errors – throughout the  system.

Let’s say that you’re working with a WordPress meta box, several of its fields are required, and you want to:

  • verify the input has been specified
  • either display an error message if it’s not specified
  • or write the data to the database if it checks out

The serialization process is pretty standard stuff, but if you’re looking to make sure required fields aren’t empty and that a error message is displayed whenever they’re not entered, then you’ll need to do some additional work.

Continue reading

Programmatically Deactivate WordPress Widgets

If you’re in the business of building themes for fun, for clients, or for purchase within a marketplace or your own store, then there’s a chance that there’s some type of functionality that’s unique to your theme that should be activated whenever the theme is activated.

In my experience, this is something that’s typically unique to niché WordPress themes because they tend to have specific features, customizations, and so on that are relevant to their theme.

Case in point: Let’s say that you’re working on a niché theme that has a number of widgetized areas, but also has very specific widgets for said areas. That is, upon theme activation, you want to make sure that each widgetized area is clear so not to bust up the layout.

In other words, you need to programmatically deactivate WordPress widgets whenever the theme is activated so that the layout of the theme looks as it should when the user activates it.

Continue reading

One Way To Add Multiple Meta Boxes

One of the things that I like about open source the most is having discussions not only about how a person goes about doing something, but why they’ve chosen a particular route over an alternative.

Yes, reading books, articles, and other material from prolific, well-known, and respected programmers matters – I’m definitely not saying that we should throw that out – but there’s a lot that can be learned from peers who are sitting a couple of tweets, emails, or gists away from you.

Though I generally enjoy seeing how other people have approached their work and understanding the rationale behind it, I’m also pretty open about how I approach certain problems if for no other reason that the garner feedback from those of you who take the time to update gists, add comments, and so on.

Continue reading

« Older posts Newer posts »

© 2025 Tom McFarlin

Theme by Anders NorenUp ↑