a8cteam51 / safety-net

Scrub options, deactivate denylisted plugins, and delete user data on development sites.
17 stars 1 forks source link

Prevent search engine indexation #52

Closed bernattorras closed 1 year ago

bernattorras commented 1 year ago

Related to #30

Issue

As suggested in Slack here, it would be a good idea to auto-check the "Discourage search engines" checkbox in the WordPress Settings > Reading section to make sure that sites with the "Safety Net" plugin active aren't indexed by the search engines.

Suggested fix

I suggest to use the option_blog_public filter to change the value of that option on-the-fly. This would have the same practical results as changing that option in the database, but would avoid the unnecessary DB update.

I also think that it would be a good idea to modify the robots.txt file (using the robots_txt hook) to make sure that the entire site is disallowed from search agents.

These are the contents that would appear in the robots.txt file once Safety Net is active:

User-agent: *
Disallow: /wp-admin/
Allow: /wp-admin/admin-ajax.php

Note

I've added these lines of code to the SafetyNet\Common file since it seems the proper place to add this generic and small functionality. If you think that it should be added somewhere else (or create a new file for these features), just let me know!