| Server IP : 65.108.144.40 / Your IP : 216.73.217.165 Web Server : Apache/2.4.52 (Ubuntu) System : Linux ubuntu-8gb-hel1-1 5.15.0-173-generic #183-Ubuntu SMP Fri Mar 6 13:29:34 UTC 2026 x86_64 User : dev ( 1000) PHP Version : 8.2.30 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/html/coopermain/wp-content/plugins/enviromon/ |
Upload File : |
<?php
/*
Plugin Name: Enviromon
Plugin URI: https://lambagency.com.au/wordpress/plugins
Description: Select and showcase your current environment.
Author: Lamb Agency <dev@lambagency.com.au>
Version: 0.7
Author URI: https://lambagency.com.au
*/
namespace LambAgency\Plugins;
class Enviromon
{
private $name;
private $output;
protected $colours = [
'local' => '#2874CC',
'staging' => '#69D6E7',
'production' => '#FF9859',
'default' => '#E5E5E5'
];
protected $knownNames = [
'local',
'staging',
'production'
];
private $colour;
public function __construct()
{
$this->setName();
$this->setColour();
$this->setOutput();
add_action('init', [$this, 'onInit']);
add_action('admin_bar_menu', [$this, 'getArgs'], 10000);
}
/**
* Run on wordpress initialisation
*/
public function onInit()
{
if (is_admin()) {
add_action('admin_enqueue_scripts', [$this, 'enqueueStyles']);
} elseif (is_admin_bar_showing()) {
add_action('wp_enqueue_scripts', [$this, 'enqueueStyles']);
}
}
/*
* Fetches environment name from .env file
*/
private function setName()
{
$name = "production";
if (!empty($_ENV['APP_ENV'])) {
$name = $_ENV['APP_ENV'];
} else {
// Infers environment name from other common settings
if (WP_DEBUG && WP_DEBUG_DISPLAY) {
$name = "local";
}
if (WP_DEBUG && !WP_DEBUG_DISPLAY) {
$name = "staging";
}
if (!WP_DEBUG) {
$name = "production";
}
}
$this->name = strtolower($name);
}
public function getName()
{
return $this->name;
}
/*
* Sets a colour for the indicator bubble based on the name of the environment
*/
private function setColour()
{
$colour = $this->colours['default'];
if (in_array($this->getName(), $this->knownNames)) {
$colour = $this->colours[$this->getName()];
}
$this->colour = $colour;
}
public function getColour()
{
return $this->colour;
}
/*
* Creates the output variable from the colour bubble and name
*/
private function setOutput()
{
$name = $this->getName();
$colour = $this->getColour();
$this->output = "<div class='enviromon-wrapper' title='Current Environment: " . esc_attr($name) . "'><span class='enviromon-bubble' style='background-color:" . esc_attr($colour) . "' role='presentation' aria-hidden='true'></span><span class='enviromon-name'>" . esc_html($name) . "</span></div>";
}
public function getOutput()
{
return $this->output;
}
public function getArgs($wp_admin_bar)
{
if (!current_user_can('manage_options')) {
return;
}
$args = [
'id' => 'enviromon',
'title' => $this->getOutput(),
'meta' => ['class' => 'enviromon'],
'parent' => 'top-secondary'
];
$wp_admin_bar->add_node($args);
}
public function enqueueStyles()
{
wp_enqueue_style('enviromon_styles', plugin_dir_url(__FILE__) . 'enviromon.css');
}
}
new Enviromon();