Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show admin notice when indexing is discouraged #369

Closed
wants to merge 5 commits into from
Closed
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
18 changes: 15 additions & 3 deletions web/app/mu-plugins/disallow-indexing.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,24 @@
Plugin Name: Disallow Indexing
Plugin URI: https://roots.io/bedrock/
Description: Disallow indexing of your site on non-production environments.
Version: 1.0.0
Version: 2.0.0
Author: Roots
Author URI: https://roots.io/
Text Domain: roots
License: MIT License
*/

if (defined('WP_ENV') && WP_ENV !== 'production' && !is_admin()) {
add_action('pre_option_blog_public', '__return_zero');
if (!defined('WP_ENV') || WP_ENV === 'production') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we just did Config::define('DISALLOW_INDEXING', WP_ENV !== 'production'); in config/application.php

and then

if (!defined('DISALLOW_INDEXING') || DISALLOW_INDEXING !== true) {
}

It makes the code read a bunch better:

Currently:

If we are on prod don't disallow indexing

Proposed:

If we aren't on prod disallow indexing

Additionally this makes the functionality

  • super easy to trace via config/application.php
  • does not rely on magic string 'production'
  • ability to be overridden per environment with new config system

return;
}

add_action('pre_option_blog_public', '__return_zero');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure there needs to be !is_admin() check around this to prevent WordPress admin panel from always showing the option as enabled.


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>'
);
echo "<div class='notice notice-warning'><p>{$message}</p></div>";
});