Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save brandonjp/ac3e04ad1703d991df9d0e2ec8e8b1a5 to your computer and use it in GitHub Desktop.
Save brandonjp/ac3e04ad1703d991df9d0e2ec8e8b1a5 to your computer and use it in GitHub Desktop.
SITE: Add Env Notice to Admin Screens - WP / Code Snippets Pro
<? // <- remove this line if you copy/paste into Code Snippets Pro
/**
* SITE: Add Env Notice to Admin Screens
*
* For admins only, display an admin notice with the current domain environment, such as: [STAGING] or [LOCAL] or [PRODUCTION]
* /* Requires Env555 */
*/
/* Requires Env555 */
namespace LdiE6PD0;
// display warning if not on production site
function display_admin_notice() {
$siteType = 'production';
$onProduction = true;
if (\function_exists('\Env555\this_is_a_production_site')) {
$onProduction = \Env555\this_is_a_production_site();
$siteType = \Env555\get_site_type();
}
// get the current domain name
$current_url = "$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$noticeClass = ($onProduction) ? 'error' : 'warning';
$noticeColor = ($onProduction) ? 'rgba(214,54,56,0.2)' : 'rgba(220,166,24,0.1)';
$firstLine = ($onProduction) ? '<b>Notice:</b> You are editing the live site. Your changes will be publicly visible immediately.<br>' : '';
echo '<div class="notice notice-'.$noticeClass.'" style="background-color:'.$noticeColor.';"><p style="font: normal 12px/20px sans-serif;">'.$firstLine.'<b>['.strtoupper($siteType).']</b> Current URL is: <em><b>'.$current_url.'</b></em></p></div>';
}
\add_action('admin_notices', '\LdiE6PD0\display_admin_notice', 1);
@brandonjp
Copy link
Author

SITE: Add Env Notice to Admin Screens
PHP snippet for Code Snippets Pro
For admins only, display an admin notice with the current domain environment, such as: [STAGING] or [LOCAL] or [PRODUCTION]
/* Uses Env555 if Available */
CleanShot 2023-01-21 at 16 15 08@2x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment