<?php
/*
Plugin Name: Soupgiant robot.txt extension
Plugin URI: http://www.soupgiant.com/
Description: This plugin will exclude crawlers from additionan directories.
Version: 0.1
Author: Peter Wilson
Author URI: http://www.soupgiant.com/
*/
function soup_do_robots(){
if( !defined('WP_CONTENT_URL') )
define( 'WP_CONTENT_URL', get_option('siteurl') . '/wp-content');
if ( !defined('WP_PLUGIN_URL') )
define( 'WP_PLUGIN_URL', WP_CONTENT_URL . '/plugins' ); // full url, no trailing slash
if ( !defined('WPMU_PLUGIN_URL') )
define( 'WPMU_PLUGIN_URL', WP_CONTENT_URL . '/mu-plugins' ); // full url, no trailing slash
header( 'Content-Type: text/plain; charset=utf-8' );
do_action( 'do_robotstxt' );
if ( '0' == get_option( 'blog_public' ) ) {
echo "User-agent: *\n";
echo "Disallow: /\n";
} else {
echo "User-agent: *\n";
echo "Disallow: /wp-admin/\n";
echo "Disallow: /wp-includes/\n";
echo "Disallow: /wp-login.php\n";
echo "Disallow: /wp-register.php\n";
//Disallow plugin directories, can't just disallow /wp-content/ as uploads and theme images are stored there
echo "Disallow: ";
echo parse_url(WP_PLUGIN_URL, PHP_URL_PATH) . "/\n";
echo "Disallow: ";
echo parse_url(WPMU_PLUGIN_URL, PHP_URL_PATH) . "/\n";
//Block the cache directories if supercache installed.
if( function_exists( 'wp_super_cache_text_domain' ) ) {
echo "Disallow: ";
echo parse_url(WP_PLUGIN_URL, PHP_URL_PATH) . "/cache/\n";
}
//Block blogs.dir if WPMU (rewritten to /files/)
if( function_exists( 'is_site_admin' ) ) {
echo "Disallow: ";
echo parse_url(WP_PLUGIN_URL, PHP_URL_PATH) . "/blogs.dir/\n";
}
}
}
function soup_remove_wp_do_robots(){
remove_action( 'do_robots','do_robots');
}
add_action('init', 'soup_remove_wp_do_robots'); //remove default do robots function
add_action('do_robots', 'soup_do_robots'); //get it into the disallow block
?>