Verily, verily, I say unto you, He that believeth on me, the works that I do shall he do also; and greater works than these shall he do; because I go unto my Father.
John 14:12
On the surface, debugging WordPress page or any other PHP page can be super-duper intimidating. But don’t worry mate! This simple solution will help you to cope with the work much easier. Adding this to any page will turn on PHP errors that were previously hidden and display them in a manner you can actually read.
Find errors in WordPress PHP pages
The default user roles in WordPress:
- Subscriber
- Contributor
- Author
- Editor
- Administrator
Naturally, the Administrator has the rights over the entire system. We will make a script that allows the Administrator to review each page for errors without affecting other users. You can test the simple solution by passing it inside the functions.php file of your theme, put it to the header, and print errors, warnings and notices:
add_action('wp_head', 'debug_current_page');
function debug_current_page() {
if (is_user_logged_in()) {
$user = wp_get_current_user();
$roles = (array) $user->roles;
if (in_array('administrator', $roles)) {
print_r($roles);
ini_set("display_errors", true);
ini_set("html_errors", true);
error_reporting(E_ALL);
}
}
}

Debug function
Once the function added, visit any website page and check for the roles and debug messages.
Find errors in any PHP page
Diagnosing a particular PHP page is even easier if it resides outside of a content management system like WordPress. Place the code at the top of the page to show the errors.
<?php
ini_set("display_errors", true);
ini_set("html_errors", true);
error_reporting(E_ALL);
/* Your PHP code below. */
?>
Comments