Disable PHP 7 Deprecated Notices from WordPress Plugins


#1

Originally published at: https://roots.io/disable-php-7-deprecated-notices-from-wordpress-plugins/
If you’re running PHP 7 then you’ve probably ran into issues with deprecated notices from various WordPress plugins. Trellis was recently upgraded with PHP 7 support so unfortunately we’ve seen a lot of these notices. If it was your own code, you’d want to fix these deprecations. But since we’re dealing with plugins, that’s not…


Roots Example Project, PHP 7 error notices, and Composer
#2

Didn’t have any luck with this and could use some help.

Here’s part of my Bedrock composer.json file

 "require": {
    "php": ">=5.5",
    "composer/installers": "~1.0.12",
    "vlucas/phpdotenv": "^2.0.1",
    "johnpbloch/wordpress": "4.4.2",
    "oscarotero/env": "^1.0",
    "roots/wp-password-bcrypt": "1.0.0",
    "cweagans/composer-patches": "~1.0"
  },
  "extra": {
    "installer-paths": {
      "web/app/mu-plugins/{$name}/": ["type:wordpress-muplugin"],
      "web/app/plugins/{$name}/": ["type:wordpress-plugin"],
      "web/app/themes/{$name}/": ["type:wordpress-theme"]
    },
    "wordpress-install-dir": "web/wp",
    "patches": {
      "johnpbloch/wordpress": {
        "Prevent E_DEPRECATED error messages when debug is enabled": "wordpress.patch"
      }
    }
  }

When I run composer install I get

Gathering patches for root package.
Removing package johnpbloch/wordpress so that it can be re-installed and re-patched.
  - Removing johnpbloch/wordpress (4.4.2)
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Gathering patches for root package.
Gathering patches for dependencies. This might take a minute.
  - Installing johnpbloch/wordpress (4.4.2)
    Loading from cache

  - Applying patches for johnpbloch/wordpress
    wordpress.patch (Prevent E_DEPRECATED error messages when debug is enabled)
   Could not apply patch! Skipping.

Generating autoload files

#3

Same error for me:

Could not apply patch! Skipping.

Did a composer update before the composer install too, otherwise it just refers to the composer.lock file and doesn’t install anything new.


#4

Just ran into the same issue. Tried with the latest composer-patches version 1.4 and latest composer version
1.0-dev (134ce134a2a0c8c6b2c3b0ece2192a535875d42b) 2016-04-02 13:25:21


#5

@cclass @discopatrick @vdrnn seems like a line ending issue with the patch file you’re trying. Give this one a shot:

https://dl.dropboxusercontent.com/u/145404/wordpress.patch


#6

Another approach would be to use a custom error handler to ignore notices from specific plugins. That’s how Ostrichcize works.


#7

A much simpler fix is to add this to the Custom Settings section of site/config/application.php

define('WP_DEBUG_DISPLAY', false);


#8

But then you won’t see error messages on screen when you should be able to :slight_smile:

This blog post is hopefully irrelevant by now as PHP 7 adoption has increased.


#9

Hi, I’m trying the same thing and it’s giving me the same error.

I even tried modifying /site/config/application.php and add
define(‘WP_DEBUG_DISPLAY’, false);

but then It gives 502 nginx error.

Isn’t there any solution to this??


#10

Is anyone still using this tip? I struggled with this for a while before I realised that the patch should now be against johnpbloch/wordpress-core, not johnpbloch/wordpress as above.

In full, the patches section in composer.json should be:

     "patches": {
       "johnpbloch/wordpress-core": {
         "Prevent E_DEPRECATED error messages when debug is enabled": "wordpress.patch"
       }
     }

Note also that the patch linked in the article is not surprisingly also out of date. I find this works for me, instead:

--- wp-includes/load.php        2018-02-06 16:42:13.000000000 +0000
+++ wp-includes/load.php        2018-03-10 16:28:50.883310743 +0000
@@ -318,7 +318,7 @@
        }
 
        if ( WP_DEBUG ) {
-               error_reporting( E_ALL );
+               error_reporting( E_ALL & ~E_DEPRECATED );
 
                if ( WP_DEBUG_DISPLAY )
                        ini_set( 'display_errors', 1 );