-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds environment type indicator to admin bar
- Loading branch information
Showing
5 changed files
with
125 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
71 changes: 71 additions & 0 deletions
71
includes/classes/AdminCustomizations/EnvironmentIndicator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |