Add ‘phpinfo()‘ to Your WordPress Site

From time to time, you may find it nec­es­sary to check out phpinfo() in order to see your server’s capa­bil­i­ties, lim­i­ta­tions, or what­ev­er. While it’s tempt­ing to upload a file to your serve con­tain­ing only <?php phpinfo(); ?>, it’s not a good idea to leave that file there for the world to see; like­wise, it’s a pain to delete it and upload it repeat­ed­ly, as it’s needed.

You can add phpinfo() capa­bil­i­ties right to Word­Press by adding the fol­low­ing code to your The­sis custom_functions.php file, appro­pri­ate theme cus­tom file, or site cus­tomiza­tion plu­g­in. The code will allow you to access phpinfo() by append­ing ?phpinfo=1 (or &phpinfo=1 if there are already para­me­ters present) to any address on your site, front or backend.

There will also be a link to the phpinfo() added to the Tools sec­tion of the Word­Press admin pan­el menu for your convenience.

And you can eas­i­ly con­trol which of your reg­is­tered users by mod­i­fy­ing the PHPINFO_ACCESS vari­able near the top of the code; pos­si­ble val­ues for it are avail­able on the Word­Press Codex.

/**
 * Enable phpinfo() viewing from within WordPress
 */
function custom_do_phpinfo_page() {
	# Define access level
	define( 'PHPINFO_ACCESS', 'remove_users' );

	if ( current_user_can( PHPINFO_ACCESS ) && isset( $_GET['phpinfo'] ) &&  true == $_GET['phpinfo'] ) {
		phpinfo();
		exit;
	}
}
add_action( 'init', 'custom_do_phpinfo_page' );

/**
 * Add phpinfo() link to WordPress admin menu
 */
function custom_add_phpinfo_menu_item() {
	global $submenu;

	$submenu[ 'tools.php' ][ 500 ] = array( 'phpinfo()', PHPINFO_ACCESS , get_home_url() . '/?phpinfo=1' ); 
}  
add_action( 'admin_menu', 'custom_add_phpinfo_menu_item' );

Did you know you can add arbi­trary links to the Word­sPress admin menu? Sure can!

4 thoughts on “Add ‘phpinfo()‘ to Your WordPress Site”

    1. Try it out. It reveals a TON of infor­ma­tion about your serv­er set up, use­ful if you find a plu­g­in that says it requires this or that serv­er extension.

  1. David, none that I can see. Even if any­one else thinks to vis­it your info page, it won’t do any­thing spe­cial for them unless they are logged in to your blog with the abil­i­ty to delete users.

Leave a Comment

Your email address will not be published. Required fields are marked *

Use your Gravatar-enabled email address while commenting to automatically enhance your comment with some of Gravatar's open profile data.

Comments must be made in accordance with the comment policy. This site uses Akismet to reduce spam; learn how your comment data is processed.

You may use Markdown to format your comments; additionally, these HTML tags and attributes may be used: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Rick Beckman