Skip to content

Commit

Permalink
adds environment type indicator to admin bar
Browse files Browse the repository at this point in the history
  • Loading branch information
psorensen committed Jul 25, 2024
1 parent c010d61 commit 586cf00
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 2 deletions.
1 change: 1 addition & 0 deletions 10up-experience.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ function ( $class_name ) {
AdminCustomizations\Customizations::instance();
}

AdminCustomizations\EnvironmentIndicator::instance();
API\API::instance();
Authentication\Usernames::instance();
Authors\Authors::instance();
Expand Down
51 changes: 51 additions & 0 deletions assets/css/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,54 @@
height: 32px;
width: 20px;
}

/* Environment Indicator Styling */
#wpadminbar ul li#wp-admin-bar-tenup-experience-environment-indicator {
color: #fff;
pointer-events: none;
}

#wpadminbar ul li#wp-admin-bar-tenup-experience-environment-indicator.tenup-production {
background-color: #b92a2a;
color: #fff;
pointer-events: none;
}

#wpadminbar ul li#wp-admin-bar-tenup-experience-environment-indicator.tenup-staging {
background-color: #d79d00;
color: #fff;
pointer-events: none;
}

#wpadminbar ul li#wp-admin-bar-tenup-experience-environment-indicator.tenup-local,
#wpadminbar ul li#wp-admin-bar-tenup-experience-environment-indicator.tenup-development {
background-color: #34863b;
color: #fff;
pointer-events: none;
}

.tenup-experience-environment-indicator__icon {
position: absolute;
top: 10px;
}

#wp-admin-bar-tenup-experience-environment-indicator > div > .ab-icon::before {
content: "\f174";
top: 3px;
}

#wp-admin-bar-tenup-experience-environment-indicator.tenup-production > div > .ab-icon::before {
content: "\f319";
top: 3px;
}

#wp-admin-bar-tenup-experience-environment-indicator.tenup-staging > div > .ab-icon::before {
content: "\f111";
top: 3px;
}

#wp-admin-bar-tenup-experience-environment-indicator.tenup-development > div > .ab-icon::before,
#wp-admin-bar-tenup-experience-environment-indicator.tenup-local > div > .ab-icon::before {
content: "\f107";
top: 3px;
}
2 changes: 1 addition & 1 deletion dist/css/admin.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array(), 'version' => '9c247eb8cd54451023c8');
<?php return array('dependencies' => array(), 'version' => '91a3e176ae42648634dd');
2 changes: 1 addition & 1 deletion dist/css/admin.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

71 changes: 71 additions & 0 deletions includes/classes/AdminCustomizations/EnvironmentIndicator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php
/**
* Admin customizations
*
* @package 10up-experience
*/

namespace TenUpExperience\AdminCustomizations;

use TenUpExperience\Singleton;

/**
* Admin Customizations class
*/
class EnvironmentIndicator {

use Singleton;

/**
* Setup module
*
* @since 1.7
*/
public function setup() {
// Add an admin bar item if in wp-admin.
add_action( 'admin_bar_menu', [ $this, 'add_toolbar_item' ], 7 );
}

/**
* Add environment indicator to admin bar
*
* @param WP_Admin_Bar $admin_bar Admin bar instance
*/
public function add_toolbar_item( $admin_bar ) {
$environment = wp_get_environment_type();

$admin_bar->add_menu(
[
'id' => 'tenup-experience-environment-indicator',
'parent' => 'top-secondary',
'title' => '<span class="ab-icon" aria-hidden="true"></span><span class="ab-label">' . esc_html( $this->get_environment_label( $environment ) ) . '</span>',
'meta' => [
'class' => "tenup-$environment",
],
]
);
}

/**
* Get human readable label for environment
*
* @param string $environment Environment type
* @return string
*/
public function get_environment_label( $environment ) {
switch ( $environment ) {
case 'development':
case 'local':
$label = __( 'Development', 'tenup' );
break;
case 'staging':
$label = __( 'Staging', 'tenup' );
break;
default:
$label = __( 'Production', 'tenup' );
break;
}

return $label;
}
}

0 comments on commit 586cf00

Please sign in to comment.