Enable WP_DEBUG to get detailed PHP error data to define solutions

The default setup in core WordPress installation for PHP error notice is set to False just so non-fatal messages are not constantly shown to a page visitor. However there are times you need to enable the notices to define a potential source that is causing an error.

Steps To Enable PHP Error Notices

Edit the file wp-config.php in the WordPress root

define('WP_DEBUG', false);

Change to

define('WP_DEBUG', true);

Save and reload the page where there is a dysfunction. It may be valuable to browse through the site while debug is on, just to confirm that all third-party extensions are behaving well. Once satisfied that all is well, reset the debug to off.

 

Other Method Via Theme

To avoid messing with the core wp-config.php, the following coding can be placed in a theme's functions.php file, via Appearance > Theme Editor therefore creating a settings field that can easily be changed as needed.

set-custom-debug-option.jpg

// add setting
add_action('admin_init', function() 
{
	// create database option name and set serialize
	if( get_option('my_options') === false ) {
		add_option('my_options', []);
	}
	
	$opts = get_option('my_options');
	
	// create a sections in the core General page
	add_settings_section('mysettings','Set Debugger','','general');
	
	// add the field to the new section
	add_settings_field(
		'debugid',
		'Enable Error Reporting',
		function($args) use ($opts) 
		{
			$on = (isset($opts['debugid']) && $opts['debugid'] == 1 ? ' selected="selected"':'');
			$off = (isset($opts['debugid']) && $opts['debugid'] == 0 ? ' selected="selected"':'');
				
			$set = '
			<select name="debugid" id="debugid">
				<option value="1"'.$on.'>On</option>
				<option value="0"'.$off.'>Off</option>
			</select>
			';
			echo $set;
		},
		'general',
		'mysettings'
	); 
	
	// save value
	if( array_key_exists('debugid', $_POST) ) {
		update_option('my_options', ['debugid' => $_POST['debugid']]);
	}
});

// retrieve options and enable error reporting if set
$opts = (object)get_option('my_options');

if( !empty($opts->debugid) && $opts->debugid == 1 && !WP_DEBUG ) {
	error_reporting(E_ALL);
}

 

The reported files will provide a guide to what could be the error source. It's unlikely that any reported core files would be causing an error, so focus on third-party sources in the list.

 




Copyright © 2021 CMSEnergizer.com. All Rights Reserved.
File download and article manager component by CMSE Custom Fields | Website hosting and development by WebsiteDons

CMSEnergizer.com is owned and operated by Emuzement Net Inc, Tampa, Florida USA