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

Conversation

QWp6t
Copy link
Member

@QWp6t QWp6t commented Jul 31, 2018

I haven't tested this yet. I'll leave that to someone else (@vpillinger?) because I'm lazy.

Closes #368

@@ -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
Copy link
Contributor

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"? 💋

Copy link
Contributor

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

@knowler
Copy link
Member

knowler commented Jul 31, 2018

Tested and it works. 👍

Changed notice to a warning instead of an error + added text domain. Ready to be squashed and merged.

@QWp6t QWp6t requested a review from swalkinshaw July 31, 2018 20:41
Copy link
Contributor

@aaemnnosttv aaemnnosttv left a 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);
Copy link
Contributor

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()

Copy link
Contributor

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 {
Copy link
Contributor

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?

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@knowler
Copy link
Member

knowler commented Jul 31, 2018

Maybe it could be helpful to append something about the current environment to the notice. It could help identify misteaks.

Search engine indexing is discouraged for the current environment: productoin. Why?

“Why?” would link to the plugin description in the repo, the site’s must-use plugin page, or somewhere else that’s more informative.

@QWp6t
Copy link
Member Author

QWp6t commented Aug 1, 2018

"Why?" could link to admin_url('plugins.php?s=disallow-indexing') or something similar imo.

knowler added 2 commits July 31, 2018 21:45
* Remove conditionals
* Change wording
* Display current environment
@knowler
Copy link
Member

knowler commented Aug 1, 2018

Bedrock: Search engine indexing has been discouraged because the current environment is productoin.

Based on the feedback above I removed the conditional, used inline vars (thanks @austinpray), and made the message read a bit better.

Search engine indexing is discouraged [for/by/in/with] the current environment

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:

  1. mu-plugins don't have pages, so admin_url('plugins.php?s=disallow-indexing') doesn't work.
  2. It felt redundant linking to a description that is not so much different than the message itself.
  3. The plugin is a part of the functionality that Bedrock provides.
  4. There is less to add code-wise. 😛

Unless anyone has any issues with this or wants to refine this more, we are ready to go (again).

Copy link
Member Author

@QWp6t QWp6t left a 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');
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 = __('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>";
Copy link
Member Author

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>";

@JulienMelissas
Copy link
Contributor

I'll weigh in @QWp6t... I liked the "Why?" - especially if it just leads to some documentation.

Copy link
Contributor

@austinpray austinpray left a 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') {
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

@austinpray
Copy link
Contributor

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)

@retlehs
Copy link
Member

retlehs commented May 20, 2020

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

@retlehs retlehs closed this May 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Undo #59 and never prevent indexing or move it to a separate config
8 participants