PHP Info Screen for Administrators
Adds a Tools > PHP Info screen showing the full phpinfo() report (extensions, limits, configuration), handy when a host's control panel does not show it.
Opens WPIDE on
Code
add_action( 'admin_menu', function () {
add_management_page( 'PHP Info', 'PHP Info', 'manage_options', 'wpide-phpinfo', function () {
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
ob_start();
phpinfo(); // phpcs:ignore WordPress.PHP.DevelopmentFunctions
$info = (string) ob_get_clean();
// Keep only the body and scope the table styles to this screen.
if ( preg_match( '#<body[^>]*>(.*)</body>#is', $info, $match ) ) {
$info = $match[1];
}
echo '<div class="wrap"><h1>PHP Info</h1><style>#wpide-phpinfo table{border-collapse:collapse;width:100%;margin-bottom:1em;background:#fff;}#wpide-phpinfo td,#wpide-phpinfo th{border:1px solid #dcdcde;padding:4px 8px;font-size:12px;vertical-align:top;word-break:break-word;}#wpide-phpinfo .e{background:#f6f7f7;font-weight:600;width:30%;}#wpide-phpinfo h2{margin-top:1.5em;}</style><div id="wpide-phpinfo">';
echo wp_kses_post( $info );
echo '</div></div>';
} );
} );
Notes
The report reveals server details; it is limited to administrators. Remove the snippet when you no longer need it.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.