Categories
WordPress

WP Gotcha #1: Passing an empty array as a WP_Query parameter

With this article, I would like to start a series called WP Gotchas. In it, I will describe some problems you might and probably will run into as a WordPress plugin developer – if you haven’t already.

At one point I was caught off-guard by them. Maybe this post will help you if you ever run into one of these issues.

This article is split into the following sections:

  1. Problem description
  2. Why does this happen?
  3. How to solve it in my code?
  4. Takeaways from this issue
  5. Further reading
Categories
Software

Adding a photo to custom email addresses in Gmail

It is not immediately obvious how to add a photo to be displayed in Gmail for a custom, non-Gmail email address. Here is how you can do it as of January 2019:

Categories
PHP

Count total number of items in nested arrays in PHP

Today I was working on some code that had arrays structured like this:

$foo = [
	'a' => [ 1, 2, 3, 4 ],
	'b' => [ 5, 6, 7 ],
];

I needed to calculate the total number of items in the nested arrays. I didn’t find a PHP function to help me with that but I came up with this idea:

Categories
WordPress

Programmatically checking WordPress plugin dependencies

Sometimes a WordPress plugin you are writing extends the functionality of another plugin or simply relies on it to work. In these cases, you need to make sure the plugins your plugin depends on are installed and active to be sure you can use their functionality.

There are some existing libraries that you can use to make sure that a plugin is running – one such library is TGM Plugin Activation. Checking if another plugin is running, however, is fairly simple and you can implement it yourself if you don’t want to pull an external library into your project for the purpose.

UPDATE (April 2020): Since publishing this article in October 2018, I have updated the plugin code and moved the entirety of it to a GitHub repository for ease of access and improved readability. I have also updated this article to only include the key points of the implementation, leaving housing the rest of it to the repository.