Software Engineering in WordPress, PHP, and Backend Development

Author: Tom (Page 373 of 424)

How To Use WP_User_Query For WordPress User Queries

Earlier this week, I published a post on how to find users in WordPress by using meta data. In short, I have a collection of users each of which have unique meta data and I needed to locate a user based on said meta data.

In the comments, Curtis of @WPThemeTut recommended I check out WP_User_Query as opposed to way that I was doing it (which I’ll cover momentarily).

Because the WordPress API has a tendency to introduce new functions for querying specific data in later releases, and because I try to be a proponent of using the newer methods, I wanted to cover WP_User_Query in a bit more detail.

Continue reading

How To Find a User By Meta Data in WordPress

Thanks to Curtis for giving a heads up to WP_User_Query - it's a nicer alternative to the original post.

One of my favorite things about the WordPress API is the ability to store custom meta data with objects such as pages and users. I’ve been working on an application where this scenario has presented itself:

  • The end user is able to create a company
  • Each company can have an administrator based on users in the system

To do this, I’m creating a relationship between the company and user by associating the company’s ID as part of the user’s meta data.

Later in the application, I need to retrieve each administrator for each company which has required the use of a helper function to get a user by meta data.

The details of how I’m doing this are aren’t exactly interesting for this post, but I figured that this was a common enough issue and easy enough to generalize that I’d share how to programmatically get a user by meta data in WordPress:

Continue reading

Writing WordPress Code – Clean, But Not Clever

I think of one the biggest challenges that programmers face as we become more comfortable and well-versed in our programming language(s) of choice, is that we become intimately aware of some of the more clever things we can do with the code.

For example, one feature of dynamic programming languages is that they offer anonymous functions. They’re really powerful and you can do some really cool stuff with them, especially in JavaScript; however, this always introduces a tension:

Are we writing code to be clever or are we writing code for others to understand?

Since I spend the majority of my time working with and writing about WordPress, I thought I’d share my thoughts on writing WordPress code.

Continue reading

What’s The Best Way To Manage WordPress Assets?

When it comes to developing web sites and web applications, there are two things that developers always consider as it relates to the project’s assets and its performance:

  • The number of HTTP requests a page requires
  • Loading all of the assets versus only what we need for a page (also known as YAGNI or You ain’t gonna need it.)

This is an obvious problem as we have tools like Head.js and Sprockets for managing this issue, and then we have customizers for larger utilities like Bootstrap that allow us to customize our builds.

Managing WordPress assets is becoming incredibly more relevant especially as frameworks, themes, and plugins become more powerful, and as people begin to build full applications on top of WordPress.

Continue reading

« Older posts Newer posts »

© 2024 Tom McFarlin

Theme by Anders NorenUp ↑