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…
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
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.
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
@cclass @discopatrick @vdrnn seems like a line ending issue with the patch file you’re trying. Give this one a shot:
Another approach would be to use a custom error handler to ignore notices from specific plugins. That’s how Ostrichcize works.
A much simpler fix is to add this to the Custom Settings section of site/config/application.php
define('WP_DEBUG_DISPLAY', false);
But then you won’t see error messages on screen when you should be able to
This blog post is hopefully irrelevant by now as PHP 7 adoption has increased.
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??
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 );
Sorry for dragging this ancient thread back to life, but it seems pretty relevant again with PHP 8 becoming standard (and all the plugin deprecation notices that go with it )
Managed to find the original guide on wayback machine (still good after 6yrs!):
Here’s a short version:
-
Copy this patch into:
./site/wp-mute-plugin-notices.patch
--- web/wp/wp-includes/load.php +++ web/wp/wp-includes/load.php @@ -457,7 +457,7 @@ function wp_debug_mode() { } if ( WP_DEBUG ) { - error_reporting( E_ALL ); + error_reporting( E_ALL & ~E_DEPRECATED ); if ( WP_DEBUG_DISPLAY ) { ini_set( 'display_errors', 1 );
-
Add patch to composer.yml:
./site/composer.yml ... "wordpress-install-dir": "web/wp", + "patches": { + "roots/wordpress": { + "Prevent E_DEPRECATED error messages when debug is enabled": "wp-mute-plugin-notices.patch" + } }
-
Add patch package:
composer require "cweagans/composer-patches"
-
composer update
+ celebrate the the lack of plugin deprecation noise!
Also, If there’s a better way to do this, I’d really like to know.
Update for WP 6, make sure you use the correct package name, stumped me for a bit!
ie. for no-content (now the default) use:
+ "patches": {
+ "roots/wordpress-no-content": {
@ben Just an FYI that after upgrading to PHP 8.1 I’m getting these deprecation notices from Soil 4.0.5:
WP 6.3.1 & 6.4.1 (possibly lower versions) have different line numbers for the patch than mentioned above, also added a comment in the original gist for future.
--- web/wp/wp-includes/load.php
+++ web/wp/wp-includes/load.php
@@ -569,7 +569,7 @@ function wp_debug_mode() {
}
if ( WP_DEBUG ) {
- error_reporting( E_ALL );
+ error_reporting( E_ALL & ~E_DEPRECATED );
if ( WP_DEBUG_DISPLAY ) {
ini_set( 'display_errors', 1 );
Curious if anyone is still using this patch successfully?
After upgrading to PHP 8.1 recently I started seeing deprecation notices cropping up and reached for this handy patch that has worked well for me in the past.
However, I can’t seem to get it to apply cleanly. The most recent gist entry looks to be no longer aligned with the latest WordPress. I tried modifying the patch to target line 582 (instead of 569) to match up with the current WordPress core load.php, but both the gist version and my edited version fail to apply (timeout error).
I have tried using cweagans/composer-patches 1.7.3 (stable), as well as the 2.0.0-beta2 pre-release, but in both cases the patch fails. I’m guessing there’s an issue with the patch itself, but I can’t figure out what.
Failing patch (with updated line numbers):
--- web/wp/wp-includes/load.php
+++ web/wp/wp-includes/load.php
@@ -582,7 +582,7 @@ function wp_debug_mode() {
}
if ( WP_DEBUG ) {
- error_reporting( E_ALL );
+ error_reporting( E_ALL & ~E_DEPRECATED );
if ( WP_DEBUG_DISPLAY ) {
ini_set( 'display_errors', 1 );
My composer.json has this entry under “extras”:
"wordpress-install-dir": "web/wp",
"patches": {
"roots/wordpress-no-content": {
"Prevent E_DEPRECATED error messages when debug is enabled": "wordpress.patch"
}
}
What happens if you run composer update --verbose
, does that give you any more information on why the patch isn’t applying?
Running composer update --verbose
results in the following:
> post-package-install: cweagans\Composer\Patches->postInstall
- Applying patches for roots/wordpress-no-content
wordpress.patch (Prevent E_DEPRECATED error messages when debug is enabled)
patch '-p1' --no-backup-if-mismatch -d 'web/wp' < '/Users/me/projects/website/site/wordpress.patch'
File to patch:
Could not apply patch! Skipping. The error was: The process "patch '-p1' --no-backup-if-mismatch -d 'web/wp' < '/Users/me/projects/website/site/wordpress.patch'" exceeded the timeout of 300 seconds.
To me this seems to indicate a problem with the patch itself, but it’s not clear what, exactly.
Strange. Nothing looks amiss to me. You could probably drop web/
from the file location in the patch so the path would be wp/wp-includes/load.php
so that the patch is picked up on the -p1
flag (the default) but I don’t think that’ll solve your issue.
You mention this only happened after a PHP 8.1 update. Where did you update PHP and where are you running your composer update
command from? To sanity check, are you SSH’ing into your local box (vagrant ssh
, trellis ssh
or trellis vm shell
depending on your setup) and running it from there?
Dropping web/
from the path did the trick!
I wasn’t aware of the -p<n>
argument at play, but for some reason the patch goes through on -p1
when it doesn’t have to cycle through patch levels.
Thank you for the tip! I see you also updated the gist with the latest info - cheers for that as well.