From 586cf0083c6b64a6de2c470323d96c9447160536 Mon Sep 17 00:00:00 2001 From: Peter Sorensen Date: Thu, 25 Jul 2024 13:16:13 -0700 Subject: [PATCH] adds environment type indicator to admin bar --- 10up-experience.php | 1 + assets/css/admin.css | 51 +++++++++++++ dist/css/admin.asset.php | 2 +- dist/css/admin.css | 2 +- .../EnvironmentIndicator.php | 71 +++++++++++++++++++ 5 files changed, 125 insertions(+), 2 deletions(-) create mode 100644 includes/classes/AdminCustomizations/EnvironmentIndicator.php diff --git a/10up-experience.php b/10up-experience.php index 0681978..f1b11b2 100644 --- a/10up-experience.php +++ b/10up-experience.php @@ -70,6 +70,7 @@ function ( $class_name ) { AdminCustomizations\Customizations::instance(); } +AdminCustomizations\EnvironmentIndicator::instance(); API\API::instance(); Authentication\Usernames::instance(); Authors\Authors::instance(); diff --git a/assets/css/admin.css b/assets/css/admin.css index 67ff825..229d103 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -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; +} diff --git a/dist/css/admin.asset.php b/dist/css/admin.asset.php index 037d6d1..5cefd3c 100644 --- a/dist/css/admin.asset.php +++ b/dist/css/admin.asset.php @@ -1 +1 @@ - array(), 'version' => '9c247eb8cd54451023c8'); + array(), 'version' => '91a3e176ae42648634dd'); diff --git a/dist/css/admin.css b/dist/css/admin.css index f4293d8..3e0c18a 100644 --- a/dist/css/admin.css +++ b/dist/css/admin.css @@ -1 +1 @@ -.tenup-company-photo{text-align:center}#wpadminbar .tenup-icon{background-image:url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMzIgNTEyIDUxMiI+PHBhdGggZmlsbD0iIzlFQTNBOCIgZD0iTTI1NS45OTQgMzJDMTE0LjU4OSAzMi4wMTQgMCAxNDYuNjEgMCAyODcuOTkxIDAgMzI3LjAzMSA5LjAxMSAzNjMuOTE1IDI0LjYxMyAzOTdsMi42ODMgMi43NzIgMTU4LjE1LTE1OC4xNDctNDkuNzMxLTQ5LjczNWgyMTYuNDA4djIxNi4zOTNsLTQ5LjczMS00OS43MzgtMTU5LjA1NSAxNTkuMDY0YzM0LjAzMiAxNi43MTYgNzIuMTg5IDI2LjM5IDExMi42NzUgMjYuMzkgMTQxLjM3OSAwIDI1Ni4wMDMtMTE0LjYwNiAyNTYuMDAzLTI1Ni4wMDktLjAwMy0xNDEuMzgxLTExNC42MjUtMjU1Ljk5MS0yNTYuMDE5LTI1NS45OTF6Ii8+PC9zdmc+")!important;background-position:50%;background-repeat:no-repeat;background-size:20px;height:32px;width:20px} +.tenup-company-photo{text-align:center}#wpadminbar .tenup-icon{background-image:url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMzIgNTEyIDUxMiI+PHBhdGggZmlsbD0iIzlFQTNBOCIgZD0iTTI1NS45OTQgMzJDMTE0LjU4OSAzMi4wMTQgMCAxNDYuNjEgMCAyODcuOTkxIDAgMzI3LjAzMSA5LjAxMSAzNjMuOTE1IDI0LjYxMyAzOTdsMi42ODMgMi43NzIgMTU4LjE1LTE1OC4xNDctNDkuNzMxLTQ5LjczNWgyMTYuNDA4djIxNi4zOTNsLTQ5LjczMS00OS43MzgtMTU5LjA1NSAxNTkuMDY0YzM0LjAzMiAxNi43MTYgNzIuMTg5IDI2LjM5IDExMi42NzUgMjYuMzkgMTQxLjM3OSAwIDI1Ni4wMDMtMTE0LjYwNiAyNTYuMDAzLTI1Ni4wMDktLjAwMy0xNDEuMzgxLTExNC42MjUtMjU1Ljk5MS0yNTYuMDE5LTI1NS45OTF6Ii8+PC9zdmc+")!important;background-position:50%;background-repeat:no-repeat;background-size:20px;height:32px;width:20px}#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-development,#wpadminbar ul li#wp-admin-bar-tenup-experience-environment-indicator.tenup-local{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} diff --git a/includes/classes/AdminCustomizations/EnvironmentIndicator.php b/includes/classes/AdminCustomizations/EnvironmentIndicator.php new file mode 100644 index 0000000..a9204b6 --- /dev/null +++ b/includes/classes/AdminCustomizations/EnvironmentIndicator.php @@ -0,0 +1,71 @@ +add_menu( + [ + 'id' => 'tenup-experience-environment-indicator', + 'parent' => 'top-secondary', + 'title' => '' . esc_html( $this->get_environment_label( $environment ) ) . '', + '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; + } +}