WordPress Function to Quickly Determine Server & Environment Details

Quickly Determine Server & Environment Details

If you have multiple servers and multiple environments such as development, QA, and production environments, this can be very useful.

For my systems, environment is determined by the first 3 letters of the hostname, but this could easily be changed to whatever suits your needs.

add_action( 'admin_notices', 'report_environment_status', 3 );

// Report on which server and environment details
function report_environment_status() {
    $server = php_uname('n');
    switch (strtolower(substr($server,0,3))) {
        case 'pXX':
            $msg = "PRODUCTION";
        case 'qXX':
            $msg = "QA";
        case 'dXX':
            $msg = "DEVELOPMENT";
        default :
            $msg = 'UNKNOWN';
    echo "<div id='update-nag'>";
    echo "<b>You are in the $msg environment. (Server: $server)</b>";
    echo "</div>";

This has saved me many times from making updates to the wrong environment.

You can also turn this into a plugin and network activate it so all sites get the notification.

You may also like...

Leave a Reply

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