remove_menu( $menu_id );
} );
// DISPLAY ENVIRONMENT ON ADMIN BAR ITEMS
add_action( 'admin_bar_menu', function ( WP_Admin_Bar $admin_bar ) {
if ( !current_user_can( 'manage_options' ) ) {
return;
}
$admin_bar->add_menu( array(
'id' => 'staging-environment-indicator',
'parent' => null,
'group' => null,
'title' => esc_html__( 'Staging', 'agency-toolkit' ), // Escape the title
'href' => admin_url( 'admin.php?page=inspry-agency-toolkit' ),
'meta' => [
'title' => esc_html__( 'Staging', 'agency-toolkit' ), // Escape the title
]
) );
}, 9999 );
if ( in_array( 'red', $getAlertColor ) ) {
$environment_indicator_css .= "#wpadminbar:before {
width: 100%;
height: 4px;
background: url( " . esc_url( plugin_dir_url( __DIR__ ) ) . "assets/images/dev-mode-red.svg ) 25px 0px repeat-x;
content: '';
display: block;
}
#wp-admin-bar-staging-environment-indicator {
background-color: #ce3333 !important;
}";
} elseif ( in_array( 'yellow', $getAlertColor ) ) {
$environment_indicator_css .= "#wpadminbar:before {
width: 100%;
height: 4px;
background: url( " . esc_url( plugin_dir_url( __DIR__ ) ) . "assets/images/dev-mode-yellow.svg ) 25px 0px repeat-x;
content: '';
display: block;
}
#wp-admin-bar-staging-environment-indicator {
background-color: #bb9a18 !important;
height: 28px !important;
line-height: 28px !important;
}";
}
} else {
$environment_indicator_css .= "#wp-admin-bar-production-environment-indicator {
background-color: #008000 !important;
height: 32px !important;
line-height: 32px !important;
}";
}
// set hite for indicator ( Staging / Production )
$environment_indicator_css .= "
#adminmenu li.current .wp-menu-image img{
opacity: 1 !important;
}";
if ( $environment_indicator_css ) {
add_action( 'admin_head', function () use ( $environment_indicator_css ) {
echo '';
} );
add_action( 'wp_head', function () use ( $environment_indicator_css ) {
echo '';
} );
}
}
}
add_action( 'init', 'inspry_toolkit_manage_environment_indicator' );
if ( !function_exists( 'inspry_toolkit_check_server_is_development_or_user_selected' ) ) {
function inspry_toolkit_check_server_is_development_or_user_selected( $hostName, $selectedUserList ) {
$currentUserID = get_current_user_id();
if ( !$selectedUserList || ( !empty( $selectedUserList ) && !in_array( $currentUserID, $selectedUserList ) ) ) {
return false;
}
if ( wp_get_environment_type() === 'development' ) {
return true;
}
if ( isset( $_SERVER['HTTP_HOST'] ) ) {
$currentHost = sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) );
} elseif ( isset( $_SERVER['SERVER_NAME'] ) ) {
$currentHost = sanitize_text_field( wp_unslash( $_SERVER['SERVER_NAME'] ) );
} elseif ( isset( $_SERVER['VIRTUAL_HOST'] ) ) {
$currentHost = sanitize_text_field( wp_unslash( $_SERVER['VIRTUAL_HOST'] ) );
} else {
// No host available (WP-CLI, cron). Fall back to the environment type check above.
$currentHost = '';
}
if ( $hostName != '' ){
$modifyHostName = str_replace( "*", "", $hostName );
if ( ( strpos( $hostName, '*' ) === FALSE && $currentHost === $hostName )
|| ( strpos( $hostName, '*' ) !== FALSE && strpos( $currentHost, $modifyHostName ) !== FALSE )
) {
return true;
}
}
if ( $currentHost == 'localhost'
|| strpos( $currentHost, '.dev' )
|| strpos( $currentHost, '.wpengine.com' )
|| strpos( $currentHost, '.local' )
|| ( strpos( $currentHost, 'dev.' ) !== FALSE )
|| ( strpos( $currentHost, 'staging.' ) !== FALSE )
|| ( strpos( $currentHost, 'staging-' ) !== FALSE )
|| $currentHost == '10.0.0.0'
|| $currentHost == '172.16.0.0'
|| $currentHost == '192.168.0.0'
|| in_array( wp_get_environment_type(), ['local', 'development', 'staging'] )
) {
return true;
}
return false;
}
}