Skip to content

Instantly share code, notes, and snippets.

@daggerhart
Created April 12, 2017 22:05
Show Gist options
  • Save daggerhart/1c51214608d7ab2f5eb1d9dcd6915e64 to your computer and use it in GitHub Desktop.
Save daggerhart/1c51214608d7ab2f5eb1d9dcd6915e64 to your computer and use it in GitHub Desktop.
Very simple WordPress plugin that warns a user if their blog can not be indexed by search engines.
<?php
/*
* Plugin Name: Blog not public admin notice
* Description: Because this checkbox costs real people real money
* Version: 1.0.0
* Author: daggerhart
*/
add_action( 'wp_ajax_dismiss_blog_not_public_notice', function(){
update_option('blog_not_public_notice_dismissed', 1);
if ( !$_GET['is_ajax'] ){
wp_redirect( wp_get_referer() );
}
exit;
});
add_action( 'admin_notices', function(){
$public = get_option( 'blog_public', 0 );
$notice_dismissed = get_option( 'blog_not_public_notice_dismissed', 0 );
if ( !$public && !$notice_dismissed )
{
?>
<style>
#blog_not_public_notice {
float: right;
margin: 6px;
}
</style>
<script type="text/javascript">
(function($){
$(document).ready(function(){
$('#blog_not_public_notice').click(function(event){
event.preventDefault();
var $btn = $(this);
$.get( $btn.attr('href'), { is_ajax: true }, function(){
$btn.closest('.error').fadeOut();
} );
})
});
})(jQuery);
</script>
<div class="error">
<a id="blog_not_public_notice" href="<?php echo esc_attr( admin_url('admin-ajax.php?action=dismiss_blog_not_public_notice') ) ?>"><?php _e( 'dismiss' ); ?></a>
<p>
<strong><?php _e('Site hidden from search engines') ?></strong>
<?php _e('This website is not able to be indexed by Google or other search engines. To fix this problem click on the following link and un-check the "Search Engine Visibility" checkbox.') ?>
<a class="button" href="<?php esc_attr( admin_url('options-reading.php') ) ?>"><?php _e('Click here to fix') ?></a>
</p>
</div>
<?php
}
} );
@daggerhart
Copy link
Author

Screenshot:
blog-not-public-notice

Inspiration:
blog-not-public-tweet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment