Monthly Archiv: January, 2019

How to Test Your WordPress Website for PHP 7.x Compatibility

There are a number of benefits to running your WordPress website on a recent version of PHP. Among the most noticeable perks is the massive increase in speed. PHP 7.3 runs about three times as many requests per second when compared with PHP 5.6.

While performance is important, there is something even more concerning. Both PHP 5.6 and 7.0 reached their end-of-life at the end of 2018. That means neither version is receiving crucial security fixes. Therefore, the longer you remain on one of these non-supported versions, the more potential there is for something bad to happen.

Also of note is that WordPress is currently recommending that your web server run PHP 7.3 and is making plans to drop support for anything lower than PHP 5.6. But in this case, running at the bare minimum isn’t good enough.

So, if you’re utilizing an outdated version of PHP, it’s time to get up-to-speed. But before you upgrade, it’s important to test your site to ensure that it will continue running smoothly afterwards.

Let’s have a look at some considerations and testing methods you can leverage to get your site ready for PHP 7.x.

Considerations and Potential Roadblocks

It stands to reason that, the older your site is, the more potentially problematic running on the latest versions of PHP will be. The code that makes up the themes and plugins we use evolves over time. As such, you’ll find that some methods that were acceptable a few years ago have since become either deprecated or removed altogether.

So, before you test anything related to a PHP upgrade, it’s important that your WordPress install is fully up-to-date. That means WordPress core, along with your theme and plugins are running at their latest versions.

But what if a theme or plugin hasn’t had a new version released in a few years? That could pose a problem when upgrading your version of PHP. If these items have unsupported code, they may display errors or stop your site from even loading (the dreaded White Screen of Death).

Testing, which we’ll get to in a moment, will give you a better picture of trouble spots. But it’s worth keeping in mind that some parts of your site may need fixed or replaced.

The other major consideration is your web host’s setup. Which PHP versions do they offer? Are you able to easily switch versions in case you run into problems? Do they have plans to abandon versions 5.6 and/or 7.0? Knowing the answers to these questions will help you create the best possible plan of attack.

PHP Code in a WordPress theme.

Testing Methods

Whether your site is large or small, it’s important to perform some tests before you attempt to use a newer version of PHP. It requires some extra effort, but could save you from some frustrating downtime.

How you test will depend on the resources you have available and, more generally, your working knowledge of PHP. Here, we’ll focus on a couple of more basic ways to test.

Use a Staging Server
Ideally, you’ll have access to a staging environment that is running the exact version of PHP you’ll be upgrading to. This will provide you with an accurate result and a view of what’s working (and what’s not).

But even if your web host can’t provide this for you, it’s still possible to put together a local server that can approximate the experience. Software such as Bitnami, WAMP and XAMPP can get you up and running fairly quickly.

Either way, having access to a cloned version of your site makes the testing process much easier. With debugging turned on, you can thoroughly check the front and back ends for any show-stopping issues.

Run a Compatibility Check
While not always 100% accurate, you can also use a compatibility checking tool to see how your WordPress install holds up on a specific version of PHP.

The free PHP Compatibility Checker plugin will search through your site’s theme and plugin code in an attempt to uncover some common issues. You can select the major version of PHP you want to test against (7.1 or 7.2, for example) and the plugin will do the rest. An itemized report is generated that will show any potential problems that have been found.

Report generated by PHP Compatibility Checker.

Finding and Fixing Errors

If your site is displaying errors, you’ll need to invest some time in finding their source and then repairing them. Sometimes, the errors themselves will lead you right to the culprit. For example, one that mentions the path of a specific plugin would be a pretty good indicator of where you should look for solutions. But it’s not always that easy.

If the error is a bit more vague, you’ll need to put on your detective’s hat and do some troubleshooting. The standard procedure in WordPress is to deactivate all plugins and switch to a default theme, such as Twenty Nineteen. This is another reason why you’ll want to use a staging environment if at all possible.

With all of your plugins deactivated and the default theme in place, load up the site on the front end. Notice any errors? Odds are that they will have been eliminated, since you’re running a completely stock install of WordPress.

Next, it’s time to start activating plugins and testing them, one-by-one. Turn on a plugin, and click around on the front end. No errors? Repeat the process until you’ve found the troublemaker. If none of your plugins are triggering an error, then move on to your theme.

Once you know which item(s) are problematic, you can look for solutions. In the case of a third-party plugin or theme, you’ll want to start with the support forums and see if you can find others who have had the same issue. Perhaps there’s a solution. Or, you can at least report the problem to the author.

If that doesn’t lead to a fix, some decisions have to be made. Software that has known compatibility issues that aren’t being fixed means that you’ll probably have to move on to something else. Hopefully, you can find a suitable alternative that you can test and implement.

Note that, while you can theoretically patch third-party software on your own, it’s a temporary band-aid at best. A future update could overwrite your work and lead to a broken site.

If the offending code is something you’ve written, dig through the PHP documentation and see how you can bring it up-to-standard. While it may be tedious, this is still better than having to rely on someone else to fix their product.

PHP Documentation

Better Speed and Security

After you’ve cleaned up any issues on your site and are running PHP 7.x, you can sit back and enjoy the benefits. Your site will process requests much faster, thus improving the user experience.

Even better is that you’ll have some piece of mind in knowing that, whenever any security holes are found in PHP, they’ll be patched. Then there is the satisfaction of knowing that your WordPress website is running on code that is compatible with the latest standards.

Upgrading PHP isn’t necessarily the must enjoyable or fun experience. In fact, it can be quite frustrating when trying to track down and fix errors. But the end result makes it truly worth the effort.

The post How to Test Your WordPress Website for PHP 7.x Compatibility appeared first on Speckyboy Web Design Magazine.

Weekly News for Designers № 472

snippet generator – A tiny React app that generates snippets for Visual Code Studio, Sublime Text and Atom.
snippet generator

The Use of Cursor Effects in Web Design – They may be small, but cursor manipulations can have a positive design impact.
The Use of Cursor Effects in Web Design

HTML5 Input Types: Where Are They Now? – A look at browser support for new form inputs that were introduced with HTML5.
HTML5 Input Types: Where Are They Now?

Dad Joke CLI – Get the latest dad jokes delivered to your command line!
Dad Joke CLI

Shiny – Add shiny, stimulating reflections to your mobile website.
Shiny

10 Examples of High-End Artwork Created with Code – The traditional and digital combining to create something beautiful.
10 Examples of High-End Artwork Created with Code

Professional Programming – A collection of full-stack resources for programmers.
Professional Programming

The 5 Major Motion Graphic Trends to Look Out For in 2019 – Explore trends in movement that will define the new year.
The 5 Major Motion Graphic Trends to Look Out For in 2019

Strategies to Improve Your Site’s Conversion Rate in 2019 – Boost your conversions with these helpful tips.
Strategies to Improve Your Site’s Conversion Rate in 2019

The mistake developers make when coding a hamburger menu – Ensuring your menu provides the best user experience.
The mistake developers make when coding a hamburger menu

Building Brand Loyalty and Reducing Anxiety with UI Animation – How to create an emotional bond with users through animation.
Building Brand Loyalty and Reducing Anxiety with UI Animation

Balancing Client Needs vs. Your Portfolio – Making design decisions for the right reasons.
Balancing Client Needs vs. Your Portfolio

Top Four Principles of Human-Centred Design – Learn how to design for people.
Top Four Principles of Human-Centred Design

Programming Fonts – Test drive over 50 free fonts for your code editor.
Programming Fonts

Web Page Usability Matters – A look at the loading experience of a web page and its impact on users.
Web Page Usability Matters

10 Year Challenge: How Popular Websites Have Changed – The latest social media fad, applied to the web!
10 Year Challenge: How Popular Websites Have Changed

Freebie: Cute Valentine’s Day Cards and Backgrounds – Create the perfect Valentine’s Day card with these AI & EPS design assets.
Freebie: Cute Valentine’s Day Cards and Backgrounds

SVG Filter Effects: Outline Text – Create interesting effects with the feMorphology filter.
SVG Filter Effects: Outline Text

LineIcons – A set of 450+ free icons handcrafted for modern UIs.
LineIcons

ArchitectUI HTML Dashboard – A free dashboard UI for building simple web applications.
ArchitectUI HTML Dashboard

Follow Speckyboy on Twitter, Facebook or Google+ for a daily does of web design resources and freebies.

The post Weekly News for Designers № 472 appeared first on Speckyboy Web Design Magazine.

PHP USPS API Zip Code (New)

Package:
PHP USPS API Zip Code
Summary:
Class for accessing the USPS API for ZIP CODE
Groups:
E-Commerce, PHP 5, Web services
Author:
Jason Olson
Description:
This class is used to access the USPS API to lookup the zip code based on a physical address in the United States (USA)...

Read more at https://www.phpclasses.org/package/11052-PHP-Class-for-accessing-the-USPS-API-for-ZIP-CODE.html

New Open Source Secure Shell (SSH) Software: access your website to update/maintain it from your Android phone

A Secure Shell (SSH) program for Android devices (including Android phones) has been added to the Free SSH (Secure Shell) and Telnet Clients page. If you have created a website and want to access the web server (ie, computer) containing its files from the command line (eg, to update it or do some maintenance), this program lets you do it directly from your phone, without having to fire up a computer.

Registering Module-Specific Routes in Expressive

In Expressive, we have standardized on a file named config/routes.php to contain all your route registrations. A typical file might look something like this:

declare(strict_types=1);

use Zend\Expressive\Csrf\CsrfMiddleware;
use Zend\Expressive\Session\SessionMiddleware;

return function (
    \Zend\Expressive\Application $app,
    \Zend\Expressive\MiddlewareFactory $factory,
    \Psr\Container\ContainerInterface $container
) : void {
    $app->get('/', App\HomePageHandler::class, 'home');

    $app->get('/contact', [
        SessionMiddleware::class,
        CsrfMiddleware::class,
        App\Contact\ContactPageHandler::class
    ], 'contact');
    $app->post('/contact', [
        SessionMiddleware::class,
        CsrfMiddleware::class,
        App\Contact\ProcessContactRequestHandler::class
    ]);
    $app->get(
        '/contact/thank-you',
        App\Contact\ThankYouHandler::class,
        'contact.done'
    );

    $app->get(
        '/blog[/]',
        App\Blog\Handler\LandingPageHandler::class,
        'blog'
    );
    $app->get('/blog/{id:[^/]+\.html', [
        SessionMiddleware::class,
        CsrfMiddleware::class,
        App\Blog\Handler\BlogPostHandler::class,
    ], 'blog.post');
    $app->post('/blog/comment/{id:[^/]+\.html', [
        SessionMiddleware::class,
        CsrfMiddleware::class,
        App\Blog\Handler\ProcessBlogCommentHandler::class,
    ], 'blog.comment');
}

and so on.

These files can get really long, and organizing them becomes imperative.

Using Delegator Factories

One way we have recommended to make these files simpler is to use delegator factories registered with the Zend\Expressive\Application class to add routes. That looks something like this:

namespace App\Blog;

use Psr\Container\ContainerInterface;
use Zend\Expressive\Application;
use Zend\Expressive\Csrf\CsrfMiddleware;
use Zend\Expressive\Session\SessionMiddleware;

class RoutesDelegator
{
    public function __invoke(
        ContainerInterface $container,
        string $serviceName,
        callable $callback
    ) : Application {
        /** @var Application $app */
        $app = $callback();

        $app->get(
            '/blog[/]',
            App\Blog\Handler\LandingPageHandler::class,
            'blog'
        );
        $app->get('/blog/{id:[^/]+\.html', [
            SessionMiddleware::class,
            CsrfMiddleware::class,
            Handler\BlogPostHandler::class,
        ], 'blog.post');
        $app->post('/blog/comment/{id:[^/]+\.html', [
            SessionMiddleware::class,
            CsrfMiddleware::class,
            Handler\ProcessBlogCommentHandler::class,
        ], 'blog.comment');

        return $app;
    }
}

You would then register this as a delegator factory somewhere in your configuration:

use App\Blog\RoutesDelegator;
use Zend\Expressive\Application;

return [
    'dependencies' => [
        'delegators' => [
            Application::class => [
                RoutesDelegator::class,
            ],
        ],
    ],
];

Delegator factories run after the service has been created for the first time, but before it has been returned by the container. They allow you to interact with the service before it's returned; you can configure it futher, add listeners, use it to configure other services, or even use them to replace the instance with an alternative. In this example, we're opting to configure the Application class further by registering routes with it.

We've even written this approach up in our documentation.

So far, so good. But it means discovering where routes are registered becomes more difficult. You now have to look in each of:

  • config/routes.php
  • Each file in config/autoload/:
    • looking for delegators attached to the Application class,
    • and then checking those to see if they register routes.
  • In config/config.php to identify ConfigProvider classes, and then:
    • looking for delegators attached to the Application class,
    • and then checking those to see if they register routes.

The larger your application gets, the more work this becomes. Your config/routes.php becomes way more readable, but it becomes far harder to find all your routes.

One-off Functions

In examining this problem for the upteenth time this week, I stumbled upon a solut

Truncated by Planet PHP, read more at the original (another 2999 bytes)

Site News: Blast from the Past – One Year Ago in PHP (01.24.2019)

Here's what was popular in the PHP community one year ago today:

Powered by Gewgley