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 an option.


( ! ) Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; CoAuthorsIterator has a deprecated constructor in /app/plugins/co-authors-plus/template-tags.php on line 66

If you’re using PHP 7 and Xdebug then you can’t easily disable these errors. A solution in the meantime is to update WordPress core’s wp_debug_mode function to suppress E_DEPRECATED error messages.

Since you never want to modify WordPress core directly, we can use cweagans/composer-patches to apply a patch file with Composer to WordPress core.

Add cweagans/composer-patches to your composer.json file and place wordpress.patch in the same directory as your composer.json file.

Example composer.json file that will apply the patch:

  "require": {
    "php": ">=5.5",
    "composer/installers": "~1.0.12",
    "vlucas/phpdotenv": "^2.0.1",
    "cweagans/composer-patches": "~1.0",
    "johnpbloch/wordpress": "4.4.2",
    "oscarotero/env": "^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-core": {
        "Prevent E_DEPRECATED error messages when debug is enabled": "wordpress.patch"

After making these changes to your composer.json file, run composer install for the patch to be applied:

vagrant@example:/srv/www/example.com/current$ composer install
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)

Now you can go back to developing without the notices. Have you run into any plugins that caused this issue for you? It wouldn’t hurt to report the issue upstream or even submit a PR.

Thanks to Craig for contributing this workflow and the patch file!

Join the discussion on Roots Discourse

Help support our open-source development efforts

Help grow Roots

Join over 6,000 subscribers on our newsletter to get the latest Roots updates, along with occasional tips on building better WordPress sites.

Looking for WordPress plugin recommendations, the newest modern WordPress projects, and general web development tips and articles?

“Easily the best WordPress email I get.” Colin OBrien

Follow us on Twitter @rootswp

Ready to checkout?