Skip to content

Commit 0cb83bd

Browse files
committed
Add support for WP_ENVIRONMENT_TYPE
New behaviour: 1. Resolve the environment type: 1. Use the value of the `WP_ENV` constant if defined and palpable. 2. Otherwise, use the value of the `wp_get_environment_type()` function if defined (introduced in WordPress 5.0.0). 3. Otherwise, use `NULL`. 2. Filter the environment type with the following hook: * `roots/bedrock/disallow_indexing_environment_type` 3. Display the notice: 1. If the environment type is palpable, display the notice with the filtered environment type. 2. Otherwise, display a shorter notice that does not reference the environment type.
1 parent b9af3f0 commit 0cb83bd

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@
2828

2929
## Overview
3030

31-
This plugin will prevent indexing of a site when `WP_ENV` is not set to `production`.
31+
This plugin will prevent indexing of a site when [`WP_ENV`](https://docs.roots.io/bedrock/master/environment-variables/#wp-env) or [`wp_get_environment_type()`](https://developer.wordpress.org/reference/functions/wp_get_environment_type/) is not set to `production`.

bedrock-disallow-indexing.php

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,28 @@
2222
}
2323

2424
add_action('admin_notices', function () {
25-
$message = sprintf(
26-
__('%1$s Search engine indexing has been discouraged because the current environment is %2$s.', 'roots'),
27-
'<strong>Bedrock:</strong>',
28-
'<code>'.WP_ENV.'</code>'
29-
);
25+
if (defined('WP_ENV') && WP_ENV) {
26+
$wp_env = WP_ENV;
27+
} else if (function_exists('wp_get_environment_type')) {
28+
$wp_env = wp_get_environment_type();
29+
} else {
30+
$wp_env = null;
31+
}
32+
33+
$wp_env = apply_filters('roots/bedrock/disallow_indexing_environment_type', $wp_env);
34+
if ($wp_env) {
35+
$message = sprintf(
36+
__('%1$s Search engine indexing has been discouraged because the current environment is %2$s.', 'roots'),
37+
'<strong>Bedrock:</strong>',
38+
'<code>'.$wp_env.'</code>'
39+
);
40+
} else {
41+
$message = sprintf(
42+
__('%1$s Search engine indexing has been discouraged.', 'roots'),
43+
'<strong>Bedrock:</strong>'
44+
);
45+
}
46+
3047
echo "<div class='notice notice-warning'><p>{$message}</p></div>";
3148
});
3249
});

0 commit comments

Comments
 (0)