Friday, 30 June 2023

Prevent PHP Deprecated Messages in Wordpress PHP error logs

WordPress ignores the PHP error level so to set your own you need to use a must-use plugin, these reside in a "mu-plugins" directory next to the "plugins" one.  

A must-use plugin does not need activating and can be seen in WordPress in the "Plugins" section under a tab called "Must-Use".

To use the following code put in into a PHP file, add "<?php" to the start and use FTP or CPANEL to upload the file into the WordPress "mu-plugins" directory.


/*
 *  Plugin Name: Prevent PHP Deprecated Messages in PHP ERROR Logs
 *  Description: Wordpress stuffs up the PHP error level with it's own "error_reporting" levels so you can't rely on setting it in the "wp-config.php" configuration file for PHP!  This Must Use plugin removes almost all of the unwanted messages that can otherwise flood the error log.  It sets: error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED)
 *  Version: 2023.06.30
 *  Author: Dennis Bareis
 */


    error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);  //Doesn't work in wp-config.php

No comments: