On $matches in preg_match functions

I’ve seen many people define an empty $matches variable before using it in preg_match and preg_match_all functions in PHP. I’ve done it myself, and I was quite surprised to learn that you don’t really have to — even if there’s no match, you will not get an undefined variable notice.

The Great Firewall of Russia

It’s a shame that the Russian “consumer watchdog” Rospotrebnadzor, the Ministry of Justice, and the Federal Service for Supervision in the Sphere of Telecom, Information Technologies and Mass Communications (or Roskomnadzor) were “smart” enough to block access to over 20 million blogs hosted on WordPress.com because three of them contained suicide, drugs, and terrorism related content, which apparently has to be censored in Russia.

Looks like somebody’s building the Great Firewall of Russia. I hoped we were better than that. Oh well…

Github’s Asking for my Password

“Why is Github asking me to input my username and password when I try to push changes to a repository I own?” I asked this myself a couple of times before I figured out I had cloned it the wrong way:

git clone https://github.com/kovshenin/publish.git .

As opposed to:

git clone git@github.com:kovshenin/publish.git .

Where the former will use the HTTP protocol, and thus require basic authentication (username and password), and the latter will use the SSH protocol, and will try to use my SSH key instead, for password-less authentication. The former will work, but you’ll have to keep entering your username and password every time. The latter is more secure.

Simple, but tricky. No, I don’t use a GUI for version control, and neither should you, trust me :)

Tip: get_posts will suppress_filters by default

I was wondering why my posts_where filter was not being executed on my WordPress query and after a bit of poking around, I figured out that get_posts sets suppress_filters to true, unless specified otherwise, making WP_Query skip a bunch of SQL filters, including the posts_where I was trying to set. So learn the easy way — get_posts will suppress filters by default.

Hopefully this won’t be such a problem when when date_query makes it into core, since one of the most popular uses for posts_where is better date filtering.