Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,7 @@

## Overview

This plugin will prevent indexing of a site when `WP_ENV` is not set to `production`.
This plugin will prevent indexing of a site when `DISALLOW_INDEXING` is set to `true`
and display a notice in the WordPress dashboard with a reference to the value of
[`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/).
33 changes: 28 additions & 5 deletions bedrock-disallow-indexing.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,34 @@
}

add_action('admin_notices', function () {
$message = sprintf(
__('%1$s Search engine indexing has been discouraged because the current environment is %2$s.', 'roots'),
'<strong>Bedrock:</strong>',
'<code>'.WP_ENV.'</code>'
$env = defined('WP_ENV') && WP_ENV ? WP_ENV : null;

if (!$env && function_exists('wp_get_environment_type')) {
$env = wp_get_environment_type();
}

$env = apply_filters('roots/bedrock/disallow_indexing_environment_type', $env);

if (!$env) {
printf(
'<div class="notice notice-warning"><p>%s</p></div>',
sprintf(
/* translators: %s: Bedrock prefix. */
__('%s Search engine indexing has been discouraged.', 'roots'),
'<strong>Bedrock:</strong>'
)
);
return;
}

printf(
'<div class="notice notice-warning"><p>%s</p></div>',
sprintf(
/* translators: 1: Bedrock prefix, 2: Environment type. */
__('%1$s Search engine indexing has been discouraged because the current environment is %2$s.', 'roots'),
'<strong>Bedrock:</strong>',
'<code>' . $env . '</code>'
)
);
echo "<div class='notice notice-warning'><p>{$message}</p></div>";
});
});