-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Conversation
@@ -3,12 +3,21 @@ | |||
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/ | |||
License: MIT License |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to add the text domain for "roots"? 💋
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this feature is becoming a beast
Tested and it works. 👍 Changed notice to a warning instead of an error + added text domain. Ready to be squashed and merged. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One suggestion and one question, otherwise looks good!
} else { | ||
add_action('admin_notices', function () { | ||
$message = __('Search engine indexing is currently discouraged.', 'roots'); | ||
echo sprintf('<div class="notice notice-warning"><p>%s</p></div>', $message); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use printf()
instead of echo sprintf()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why use either? why not just inline the var?
add_action('pre_option_blog_public', '__return_zero'); | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The else
is not really necessary as there's no harm in hooking onto an admin hook for a non-admin request. I would personally omit it and save the extra braces + indentation; is this a WP/Roots style convention?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Maybe it could be helpful to append something about the current environment to the notice. It could help identify misteaks. “Why?” would link to the plugin description in the repo, the site’s must-use plugin page, or somewhere else that’s more informative. |
"Why?" could link to |
* Remove conditionals * Change wording * Display current environment
Based on the feedback above I removed the conditional, used inline vars (thanks @austinpray), and made the message read a bit better.
could be read as a suggestion, when what we are actually doing is informing the user of what is happening. Also, I decided against the "Why?" link and replaced it with Bedrock because:
Unless anyone has any issues with this or wants to refine this more, we are ready to go (again). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a fan of the "Why?" link that you had. Anyone else wanna weigh in on that?
} | ||
|
||
add_action('pre_option_blog_public', '__return_zero'); |
There was a problem hiding this comment.
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 = __('Search engine indexing has been discouraged because the current environment is', 'roots'); | ||
echo "<div class='notice notice-warning'><p><strong>Bedrock:</strong> {$message} <code>".WP_ENV."</code>.</p></div>"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$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>";
I'll weigh in @QWp6t... I liked the "Why?" - especially if it just leads to some documentation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So in light of #380
Why not make this behavior explicit in the configuration? I added my comments inline.
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') { |
There was a problem hiding this comment.
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
Since we are definitely doing extracting out the plugin autoloader (#299) we should probably extract this guy out as well and then implement my suggestions here #369 (comment) |
picking this up again - i've made https://github.com/roots/bedrock-disallow-indexing and pushed some initial code with @austinpray's suggestion i also added a filter to prevent the notice from showing see #521 |
I haven't tested this yet. I'll leave that to someone else (@vpillinger?) because I'm lazy.
Closes #368