Working with WordPress Transients and Authentication When working with membership-focused sites, it's important to also consider the use of transients and authentication.

In continuing with the content of the previous post, it’s important also to consider the use of transients and authentication.

Because there are scenarios where users are authenticated on a site (think of a members-only area of a site) and or aren’t authenticated on the site (such as site visitors).

These types of situations are present both on blogs and other sites and web applications across the board.

Continue readingWorking with WordPress Transients and Authentication When working with membership-focused sites, it’s important to also consider the use of transients and authentication.

Installing Multiple Coding Standards There's an interesting challenge that comes if you want to configure multiple coding standards with PHPCS.

I’ve talked about the importance of using coding standards (whatever standard you opt to use it up to you) and how to get PHP CodeSniffer (especially with Visual Studio Code) set up in several posts.

But there’s an interesting challenge that comes if you want to configure multiple coding standards with PHPCS. And this isn’t that strange a scenario, either.

Imagine you have several different projects on which you’re working – one uses WordPress’ coding standards, one uses PSR2, and one uses some other set of rules defined by the organization for which you work.

And you want to add them all as options to your configuration.

Continue readingInstalling Multiple Coding Standards There’s an interesting challenge that comes if you want to configure multiple coding standards with PHPCS.

Using cURL to Determine If the Specified URL Is a Valid Page Another useful feature of cURL: Determining if the specified URL takes you to a valid page.

Earlier this month, I wrote about finding the destination of a redirect using cURL in PHP. This can be a useful function to use whenever:

  • you know the URLs with which you’re dealing are going to redirect,
  • you know that the number of redirects will be limited to one.

Granted, in the latter case, it’s becoming more difficult because sites like, say, Twitter, have multiple redirects before you get to the destination.

But that’s a topic for another post (unless you just want to implement a recursive or iterative way of working through requests until you find the final destination).

Anyway, there’s another thing that can also be useful whenever you’re working with redirects and with cURL, and that’s determining if the specified URL takes you to a valid page.

Continue readingUsing cURL to Determine If the Specified URL Is a Valid Page Another useful feature of cURL: Determining if the specified URL takes you to a valid page.

How to Manipulate the DOM Using PHP Manipulating the DOM on the client-side isn’t always the best option. We can do so using built-in features of PHP.

When it comes to manipulating the DOM, the first thing many of us likely think of is using JavaScript to do whatever it is we need to do.

Not only does the language natively support functions for doing this, newer features of ES6 give us more powerful ways to build client-side scripts. And if you’re using jQuery with WordPress, then you have the same library of functions for, ahem, querying the DOM that we’ve had for years.

But manipulating the DOM on the client-side isn’t always the best option. Instead, you may want to do so on the server-side. And because of some of the features built into PHP, it’s not much different from how we do things using JavaScript.

Manipulate the DOM Using PHP: Manipulate the DOM Using PHP: DOmDocument

Other than, of course, we’re doing so on the server.

Continue readingHow to Manipulate the DOM Using PHP Manipulating the DOM on the client-side isn’t always the best option. We can do so using built-in features of PHP.

Finding the Destination of a Redirect with PHP This solution for finding the destination of a redirect with PHP is easy but it assumes a single redirect.

Recently, I was working on a project that was communicating with a third-party API that, like many APIs, sends back a lot of data part of which includes a URL for the product associated with the API.

The thing about the API that was being returned was not the proper destination URL. Instead, it was a URL that ultimately redirected to another URL.

So imagine hitting, say, acme.site-info.com and having it direct to acme.com. We do this manually all the time, but I needed to get the actual – or the final – destination of the direct from the URL.

And finding the destination of a redirect with PHP is easy; however, this does assume there’s only a single redirect.

Nonetheless, here’s how to do it.

Continue readingFinding the Destination of a Redirect with PHP This solution for finding the destination of a redirect with PHP is easy but it assumes a single redirect.