=== Webknit Environment Indicator ===
Contributors: webknitdigital
Tags: environment, staging, development, badge, indicator
Requires at least: 6.0
Requires PHP: 7.4
Tested up to: 7.1
Stable tag: 1.0.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Never mistake a staging, development or local copy for your live site. Shows a badge in wp-admin, on the login page and on the public front end.

== Description ==

Webknit Environment Indicator puts a clear, colored badge on every copy of your site that isn't production:

* **Dashboard badge** on every wp-admin screen, with the same style as the front-end badge and its own position setting, below the admin bar. Has its own on/off switch.
* **Public front-end badge** on the live site that shifts clockwise around the edges of the screen so it can't go unnoticed (or stays in one corner of your choice), visible to logged-out visitors too, so clients you share a staging link with can see it.
* **Login page badge** and a faint watermark of the environment name across the login screen, so you know which copy you're signing in to. Has its own on/off switch.
* **Per-environment label and color** for Production, Staging, Development and Local.
* **No badge on production** unless you ask for one.
* **Search engine warnings**, both ways. "Search engine visibility" is copied along with the database, so it warns when a staging, development or local copy is open to search engines, and when your production site is hidden from them after a push from staging.
* **No JavaScript at all**: the badges, the shifting animation and the settings page are plain HTML and CSS, and the front end loads no extra files.

= How the environment is decided =

1. The environment you choose on the settings page for this site URL.
2. Otherwise, WordPress's own `WP_ENVIRONMENT_TYPE` setting.
3. Otherwise, **Local** if the site runs on a local-only address: `localhost`, `127.0.0.1`, or a domain ending in `.local`, `.test`, `.localhost`, `.example` or `.invalid`.
4. Otherwise, production (no badge).

Developers can override the result with the `webknit_environment_indicator_environment` filter.

= Settings are saved per site URL =

When you clone a site, its database (and this plugin's settings) goes with it. To stop a "Staging" setting from ending up on your live site after a push to production, settings are stored separately for each site URL. Settings saved for a different URL are never applied; the settings page shows a URL mismatch warning and asks you to configure the site again.

== Installation ==

1. Upload the plugin files to `/wp-content/plugins/webknit-environment-indicator`, or install through the WordPress plugins screen directly.
2. Activate the plugin through the "Plugins" screen in WordPress.
3. Go to Settings → Environment Indicator and choose the environment for this site, or define `WP_ENVIRONMENT_TYPE` in `wp-config.php`.

== Frequently Asked Questions ==

= Why doesn't it guess "staging" from my site's address? =

Guessing from names like `staging.` or `dev.`, or from the `.dev` domain, can be wrong, and a wrong guess would put a "Staging" badge on a live site. That's exactly the mistake this plugin exists to prevent, so it only acts on addresses that can never be a public site (such as `localhost`, `.local` and `.test`). For everything else, choose the environment in the settings or set `WP_ENVIRONMENT_TYPE`.

= I copied my site and the settings page says "URL mismatch". =

The settings in the database were saved on a different site URL, so they are not applied here. Choose the environment for this URL and save. Settings left behind for other URLs are never used here, and are deleted if you uninstall the plugin.

= Can I hide the front-end badge from visitors? =

Yes. Set "Show badge on front end" to No. The badge still shows in wp-admin and on the login page.

= How do I set the environment in code? =

Define it in `wp-config.php`:

`define( 'WP_ENVIRONMENT_TYPE', 'staging' );`

Or use the filter:

`add_filter( 'webknit_environment_indicator_environment', function () { return 'staging'; } );`

= Does it stop search engines indexing my staging site? =

No, it warns you. If the site isn't production and "Discourage search engines from indexing this site" (Settings → Reading) is off, you'll see a warning on the plugin's settings page and on the Dashboard, Plugins and Reading screens. It also warns the other way round: when the site is set as production but search engines are discouraged, which often happens after a staging site is pushed live. The plugin never changes that setting itself. For real protection, put staging sites behind a password.

= Is this an official WordPress feature? =

No. It's a Webknit Digital plugin that reads WordPress's own `WP_ENVIRONMENT_TYPE` setting when you have one.

== Screenshots ==

1. The login page: the badge plus a faint watermark of the environment name, so you know which copy you're signing in to.
2. Settings page: the environment for this site URL, where the badge shows, the wp-admin and front-end badge positions, and the label and color for each environment.
3. The front-end badge, shown to visitors who aren't logged in too, since staging links are often shared with clients.

== Changelog ==

= 1.0.0 =
* Initial release.
