Skip to content

Instantly share code, notes, and snippets.

@mattrude
Created September 17, 2010 22:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattrude/585087 to your computer and use it in GitHub Desktop.
Save mattrude/585087 to your computer and use it in GitHub Desktop.
Category Excluder plugin for WordPress
<?php
/**
Plugin Name: Category Excluder
Plugin URI: http://github.com/mattrude/mdr-network
Description: Allows a user to select the categories they wish to exclude and where they would like to excluded the categories from (main page, feed, archives). See: Tools -> Webmaster Tools
Version: 1.0
Author: Matt Rude
Author URI: http://mattrude.com
*/
define('CATEGORY_EXCLUDER_TEXTDOMAIN', 'mdr-network');
if (function_exists('load_plugin_textdomain')) {
load_plugin_textdomain(CATEGORY_EXCLUDER_TEXTDOMAIN, false, dirname(__FILE__).'/languages' );
}
function add_category_excluder_page() {
global $category_excluder_hook;
$category_excluder_hook = add_submenu_page( 'tools.php', 'Category_Excluder', __('Category Excluder', CATEGORY_EXCLUDER_TEXTDOMAIN), 'administrator', 'category_excluder', 'category_excluder_admin_menu' );
}
function category_excluder_help($contextual_help, $screen_id, $screen) {
global $category_excluder_hook;
if ($screen_id == $category_excluder_hook) {
$contextual_help = '<h4>' . __('Category Excluder', CATEGORY_EXCLUDER_TEXTDOMAIN) . '</h4><p>' . __('On this screen you may disable any category from displaying on your main page, feeds, and/or archives. If a post is in more then one category, it will be excluded if it&rsquo;s in any exclued category.', CATEGORY_EXCLUDER_TEXTDOMAIN) . '</p>'; }
return $contextual_help;
}
add_action('contextual_help', 'category_excluder_help', 10, 3);
add_action('admin_menu', 'add_category_excluder_page');
add_filter('pre_get_posts','category_excluder_exclude_categories');
function category_excluder_process() {
if( !$_POST[ 'exclude_main' ] ) {
$_POST[ 'exclude_main' ] = array();
}
if( !$_POST[ 'exclude_feed' ] ) {
$_POST[ 'exclude_feed' ] = array();
}
if( !$_POST[ 'exclude_archives' ] ) {
$_POST[ 'exclude_archives' ] = array();
}
$options['exclude_main'] = $_POST[ 'exclude_main' ];
$options['exclude_feed'] = $_POST[ 'exclude_feed' ];
$options['exclude_archives'] = $_POST[ 'exclude_archives' ];
update_option('site_category_excluder', $options);
$message = "<div class='updated'><p>" . __('Excludes successfully updated', CATEGORY_EXCLUDER_TEXTDOMAIN) . "</p></div>";
return $message;
}
function category_excluder_get_options(){
$defaults = array();
$defaults['exclude_main'] = array();
$defaults['exclude_feed'] = array();
$defaults['exclude_archives'] = array();
$options = get_option('site_category_excluder');
if (!is_array($options)){
$options = $defaults;
update_option('site_category_excluder', $options);
}
return $options;
}
function category_excluder_exclude_categories($query) {
$options = category_excluder_get_options();
if ($query->is_home) {
$query->set('cat', implode( ', ', $options[ 'exclude_main' ] ) );
}
if ($query->is_feed) {
$query->set('cat', implode(', ', $options[ 'exclude_feed' ] ) );
}
if ($query->is_archive) {
$query->set('cat', implode(', ', $options[ 'exclude_archives' ] ) );
}
return $query;
}
function category_excluder_admin_menu() {
if( $_POST[ 'ce' ] ) {
$message = category_excluder_process();
}
$options = category_excluder_get_options();
?>
<div class="wrap">
<div id="icon-themes" class="icon32"><br></div>
<h2><?php _e('Category Excluder', CATEGORY_EXCLUDER_TEXTDOMAIN) ?></h2>
<?php echo $message ?>
<p><?php _e('This page will allow you to exclude or disable individual categories from displaying on the main page, in your feed, and/or in your archives.', CATEGORY_EXCLUDER_TEXTDOMAIN) ?></p>
<form action="tools.php?page=category_excluder" method="post">
<table class="widefat">
<thead>
<tr>
<th scope="col"><?php _e('Category', CATEGORY_EXCLUDER_TEXTDOMAIN) ?></th>
<th scope="col"><?php _e('Exclude from Main Page?', CATEGORY_EXCLUDER_TEXTDOMAIN) ?></th>
<th scope="col"><?php _e('Exclude from Feeds?', CATEGORY_EXCLUDER_TEXTDOMAIN) ?></th>
<th scope="col"><?php _e('Exclude from Archives?', CATEGORY_EXCLUDER_TEXTDOMAIN) ?></th>
</tr>
</thead>
<tbody id="the-list">
<?php
$cats = get_categories();
$alt = 0;
foreach( $cats as $cat ) {
?>
<tr<?php if ( $alt == 1 ) { echo ' class="alternate"'; $alt = 0; } else { $alt = 1; } ?>>
<th scope="row"><?php echo $cat->cat_name; //. ' (' . $cat->cat_ID . ')'; ?></th>
<td>
<input type="checkbox" name="exclude_main[]" value="-<?php echo $cat->cat_ID ?>" <?php if ( in_array( '-' . $cat->cat_ID, $options['exclude_main'] ) ) { echo 'checked="true" '; } ?>/>
</td>
<td><input type="checkbox" name="exclude_feed[]" value="-<?php echo $cat->cat_ID ?>" <?php if ( in_array( '-' . $cat->cat_ID, $options['exclude_feed'] ) ) { echo 'checked="true" '; } ?>/></td>
<td><input type="checkbox" name="exclude_archives[]" value="-<?php echo $cat->cat_ID ?>" <?php if ( in_array( '-' . $cat->cat_ID, $options['exclude_archives'] ) ) { echo 'checked="true" '; } ?>/></td>
</tr>
<?php
}
?>
</table>
<p><i><?php _e('Note: If a post is in more the one category, it will be excluded if it matches <strong>any</strong> of the excluded categories.', CATEGORY_EXCLUDER_TEXTDOMAIN) ?></i></p>
<p class="submit">
<input type="submit" name="submit" class="button-primary" value="<?php _e('Save Changes', CATEGORY_EXCLUDER_TEXTDOMAIN) ?>" />
<input type="hidden" name="ce" value="true" />
</p>
</form>
</div><?php
}
?>
<?php
/**
Plugin Name: Favicon
Plugin URI: http://github.com/mattrude/mdr-network
Description: Provides favicon support for WordPress network installs. If a user dosen't have a favicon.ico or favicon.png file in their files directory, it will use their Gravatar image, if they don't have that, it will use the site's default.
Version: 1.0
Author: Matt Rude
Author URI: http://mattrude.com
*/
function mdr_favicon() {
$upload_dir = wp_upload_dir();
if (file_exists($upload_dir['basedir'] . '/favicon.ico')) {
$favicon = $upload_dir['baseurl'] . '/favicon.ico';
echo "<link rel='shortcut icon' href='$favicon'>
";
} elseif (file_exists($upload_dir['basedir'] . '/favicon.png')) {
$favicon = $upload_dir['baseurl'] . '/favicon.png';
echo "<link rel='shortcut icon' href='$favicon'>
";
} else {
$default = urlencode('http://wordpress.org/favicon.ico');
$emailhash = md5(strtolower(trim(get_settings('admin_email'))));
$favicon = "http://www.gravatar.com/avatar/$emailhash?s=20&d=$default";
echo "<link rel='shortcut icon' href='$favicon'>
";
}
}
add_action('wp_head','mdr_favicon');
add_action('admin_head','mdr_favicon');
?>
<?php
/**
* XML Sitemap Feed Template for displaying XML Sitemap Posts feed.
*/
//header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
echo '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?'.'>'; ?>
<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"
>
<url>
<loc><?php bloginfo_rss('url') ?></loc>
<lastmod><?php echo mysql2date('Y-m-d\TH:i:s\Z', get_lastpostmodified('GMT'), false); ?></lastmod>
<changefreq>weekly</changefreq>
<priority>0.8</priority>
</url>
<?php
$args = array(
'post_type' => 'page',
'numberposts' => 100,
'status' => 'publish',
'orderby' => 'date',
'order' => 'DESC'
);
$post_ids = get_posts($args);
if ($post_ids) {
foreach ($post_ids as $post) { ?>
<url>
<loc><?php the_permalink_rss() ?></loc>
<lastmod><?php echo mysql2date('Y-m-d\TH:i:s\Z', get_post_time('Y-m-d H:i:s', true), false); ?></lastmod>
<changefreq>weekly</changefreq>
<priority>0.7</priority>
</url>
<?php } }
$args = array(
'post_type' => 'post',
'numberposts' => 100,
'post_status' => 'publish',
'orderby' => 'date',
'order' => 'DESC'
);
$post_ids = get_posts($args);
if ($post_ids) {
foreach ($post_ids as $post) { ?>
<url>
<loc><?php the_permalink_rss() ?></loc>
<?php
$args2 = array(
'post_type' => 'attachment',
'numberposts' => 100,
'post_parent' => $post->ID,
'post_mime_type' => 'image',
'orderby' => 'date',
'order' => 'DESC'
);
$images = get_posts($args2);
if ($images) {
foreach ($images as $post) { ?>
<image:image>
<image:loc><?php echo wp_get_attachment_url(); ?></image:loc>
<?php if ( !empty($post->post_excerpt) ) echo ' <image:caption>' . $post->post_excerpt . '</image:caption>
'; ?>
<image:title><?php echo $post->post_title ?></image:title>
</image:image>
<?php } } ?>
<lastmod><?php echo mysql2date('Y-m-d\TH:i:s\Z', get_post_time('Y-m-d H:i:s', true), false); ?></lastmod>
<changefreq>weekly</changefreq>
<priority>0.5</priority>
</url>
<?php } } ?>
</urlset>
<?php
/**
Plugin Name: Feedburner
Plugin URI: http://github.com/mattrude/mdr-network
Description: Redirects all sites feeds to the entred Feedburner feed. See: Settings -> Reading
Author: Matt Rude
Author URI: http://mattrude.com/
Version: 1.0
*/
define('FEEDBURNER_TEXTDOMAIN', 'mdr-network');
if (function_exists('load_plugin_textdomain')) {
load_plugin_textdomain(FEEDBURNER_TEXTDOMAIN, false, dirname(plugin_basename(__FILE__)).'/languages' );
}
add_action('admin_init', 'feedburner_config_page');
function feedburner_config_page() {
add_settings_section( 'feedburner_section', __('Feedburner Service', FEEDBURNER_TEXTDOMAIN), 'feedburner_head_config', 'reading', 'feedburner_config' );
add_settings_field( 'feedburner_url', __('Feedburner URL', FEEDBURNER_TEXTDOMAIN), 'feedburner_url_conf', 'reading', 'feedburner_section' );
add_settings_field( 'feedburner_comment_url', __('Feedburner Comment URL', FEEDBURNER_TEXTDOMAIN), 'feedburner_comment_url_conf', 'reading', 'feedburner_section' );
add_settings_field( 'feedburner_append_cats', __('Append category/tag to URL', FEEDBURNER_TEXTDOMAIN), 'feedburner_append_cats_conf', 'reading', 'feedburner_section' );
add_settings_field( 'feedburner_no_cats', __('Do not redirect category or tag feeds', FEEDBURNER_TEXTDOMAIN), 'feedburner_no_cats_conf', 'reading', 'feedburner_section' );
add_settings_field( 'feedburner_no_search', __('Do not redirect search result feeds', FEEDBURNER_TEXTDOMAIN), 'feedburner_no_search_conf', 'reading', 'feedburner_section' );
register_setting( 'reading', 'feedburner_url' );
register_setting( 'reading', 'feedburner_comment_url' );
register_setting( 'reading', 'feedburner_append_cats' );
register_setting( 'reading', 'feedburner_no_cats' );
register_setting( 'reading', 'feedburner_no_search' );
}
function feedburner_head_config() {
echo '<p>' . __('<strong>Feedburner</strong> is a free feed management service, providing custom <a href="http://en.wikipedia.org/wiki/RSS" target="_blank">RSS</a> feeds and management tools such as traffic analysis and an optional advertising system.', FEEDBURNER_TEXTDOMAIN) . '</p>';
echo '<p>' . __('First go to <a href="http://feedburner.com/" target="_blank" >Feedburner.com</a> and burn your feed. Enter the URL Feedburner created for you. You may optionally redirect your comments feed using the same procedure. To disable redirection, disable the plugin or erase the URLs.', FEEDBURNER_TEXTDOMAIN) . '</p>';
echo '<p>' . __('Once you enter URLs your feeds will be redirected automatically and you do not need to take any further action. Note that your feeds may not appear to redirect to Feedburner until you add a new post.', FEEDBURNER_TEXTDOMAIN) . '</p>';
}
function feedburner_url_conf() {
$options = get_option('site_feedburner');
if (!isset($options['feedburner_url'])) $options['feedburner_url'] = null;
echo "<input id='feedburner_url' name='feedburner_url' type='text' maxlength='200' size='60px' value='" . get_option('feedburner_url') . "' />";
}
function feedburner_comment_url_conf() {
$options = get_option('site_feedburner');
if (!isset($options['feedburner_comment_url'])) $options['feedburner_comment_url'] = null;
echo "<input id='feedburner_comment_url' name='feedburner_comment_url' type='text' maxlength='200' size='60px' value='" . $options['feedburner_comment_url'] . "' />";
}
function feedburner_append_cats_conf() {
$checked = "";
if (get_option('feedburner_append_cats'))
$checked = " checked='checked' ";
echo "<input {$checked} name='feedburner_append_cats' type='checkbox' value='eg_setting_name' />";
}
function feedburner_no_cats_conf() {
$checked = "";
if (get_option('feedburner_no_cats'))
$checked = " checked='checked' ";
echo "<input {$checked} name='feedburner_no_cats' type='checkbox' value='eg_setting_name' />";
}
function feedburner_no_search_conf() {
$checked = "";
if (get_option('feedburner_no_search'))
$checked = " checked='checked' ";
echo "<input {$checked} name='feedburner_no_search' type='checkbox' value='eg_setting_name' />";
}
function feedburner_redirect() {
global $feed, $withcomments, $wp, $wpdb, $wp_version, $wp_db_version;
// Do nothing if not a feed
if (!is_feed()) return;
// Do nothing if feedburner is the user-agent
if (preg_match('/feedburner/i', $_SERVER['HTTP_USER_AGENT'])) return;
// Do nothing if not configured
$options = get_option('site_feedburner');
if (!isset($options['feedburner_url'])) $options['feedburner_url'] = null;
if (!isset($options['feedburner_comment_url'])) $options['feedburner_comment_url'] = null;
if (!isset($options['feedburner_append_cats'])) $options['feedburner_append_cats'] = 0;
if (!isset($options['feedburner_no_cats'])) $options['feedburner_no_cats'] = 0;
if (!isset($options['feedburner_no_search'])) $options['feedburner_no_search'] = 0;
$feed_url = $options['feedburner_url'];
$comment_url = $options['feedburner_comment_url'];
if ($feed_url == null && $comment_url == null) return;
// Get category
$cat = null;
if ($wp->query_vars['category_name'] != null) {
$cat = $wp->query_vars['category_name'];
}
if ($wp->query_vars['cat'] != null) {
if ($wp_db_version >= 6124) {
// 6124 = WP 2.3
$cat = $wpdb->get_var("SELECT slug FROM $wpdb->terms WHERE term_id = '".$wp->query_vars['cat']."' LIMIT 1");
} else {
$cat = $wpdb->get_var("SELECT category_nicename FROM $wpdb->categories WHERE cat_ID = '".$wp->query_vars['cat']."' LIMIT 1");
}
}
if ($options['feedburner_append_cats'] == 1 && $cat) {
$feed_url .= '_'.$cat;
}
// Get tag
$tag = null;
if ($wp->query_vars['tag'] != null) {
$tag = $wp->query_vars['tag'];
}
if ($options['feedburner_append_cats'] == 1 && $tag) {
$feed_url .= '_'.$tag;
}
// Get search terms
$search = null;
if ($wp->query_vars['s'] != null) {
$search = $wp->query_vars['s'];
}
// Redirect comment feed
if ($feed == 'comments-rss2' || is_single() || $withcomments) {
if ($comment_url != null) {
header("Location: ".$comment_url);
die;
}
} else {
// Other feeds
switch($feed) {
case 'feed':
case 'rdf':
case 'rss':
case 'rss2':
case 'atom':
if (($cat || $tag) && $options['feedburner_no_cats'] == 1) {
// If this is a category/tag feed and redirect is disabled, do nothing
} else if ($search && $options['feedburner_no_search'] == 1) {
// If this is a search result feed and redirect is disabled, do nothing
} else {
if ($feed_url != null) {
// Redirect the feed
header("Location: ".$feed_url);
die;
}
}
}
}
}
add_action('template_redirect', 'feedburner_redirect');
?>
<?php
/**
Plugin Name: Sitemap Generator
Plugin URI: http://github.com/mattrude/mdr-network
Description: Automatic generate standard XML sitemap (http://example.com/sitemap.xml) that supports the protocol including Google, Yahoo, MSN, Ask.com, and others. No files stored on your disk, the sitemap.xml file is generate as needed, like your feeds.
Version: 1.0
Author: Matt Rude
Author URI: http://mattrude.com/
*/
function sitemap_flush_rules() {
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
add_action('init', 'sitemap_flush_rules');
function xml_feed_rewrite($wp_rewrite) {
$feed_rules = array(
'.*sitemap.xml$' => 'index.php?feed=sitemap'
);
$wp_rewrite->rules = $feed_rules + $wp_rewrite->rules;
}
add_filter('generate_rewrite_rules', 'xml_feed_rewrite');
function do_feed_sitemap() {
remove_filter('pre_get_posts','category_excluder_exclude_categories');
$template_dir = dirname(__FILE__) . '/templates';
load_template( $template_dir . '/feed-sitemap.php' );
}
add_action('do_feed_sitemap', 'do_feed_sitemap', 10, 1);
?>
<?php
/**
Plugin Name: Time Since
Plugin URI: http://github.com/mattrude/mdr-network
Description: Adds a Time Since shotcode "[ts date'1980-06-19']" that will display the years since the date provided.
Version: 1.1
Author: Matt Rude
Author URI: http://mattrude.com
*/
/*
Matt Rude <matt@mattrude.com> - 1 Nov 2009
This shortcode displays the years since the date provided.
To use this shortcode, add some text to a post or page simmiler to:
[ts date='1983-09-02']
The date format is YYYY-MM-DD
*/
if ( !function_exists('mdr_timesince') ) {
function mdr_timesince($atts, $content = null) {
extract(shortcode_atts(array("date" => ''), $atts));
if(empty($date)) {
return "<br /><br />************No date provided************<br /><br />";
}
$mdr_unix_date = strtotime($date);
$mdr_time_difference = time() - $mdr_unix_date ;
$years = floor($mdr_time_difference / 31556926 );
$num_years_since = $years;
return $num_years_since;
}
add_shortcode('ts', 'mdr_timesince');
}
?>
<?php
/**
Plugin Name: Typekit Fonts
Plugin URI: http://github.com/mattrude/mdr-network
Description: Provides Typekit fonts to a website by adding the needed java code to the pages. See Appearance -> Fonts
Version: 1.0
Author: Matt Rude
Author URI: http://mattrude.com
*/
define('TYPEKITFONTS_TEXTDOMAIN', 'mdr-network');
if (function_exists('load_plugin_textdomain')) {
load_plugin_textdomain(TYPEKITFONTS_TEXTDOMAIN, false, dirname(__FILE__).'/languages' );
}
function add_fonts_page() {
global $typekit_font_hook;
$typekit_font_hook = add_submenu_page( 'themes.php', 'Typekit Fonts Options', __('Fonts', TYPEKITFONTS_TEXTDOMAIN), 'administrator', 'typekitfonts', 'fonts_page' );
}
function register_typekit() {
add_option('typekit_id');
}
function typekit_font_help($contextual_help, $screen_id, $screen) {
global $typekit_font_hook;
if ($screen_id == $typekit_font_hook) {
$contextual_help = '<p>' . __('Typekit&rsquo;s fonts isn&rsquo;t the easist thing to setup. It will require that you know something about the way your page is displayed to the public. See the following resources for a overview of what your trying to do.', TYPEKITFONTS_TEXTDOMAIN) . '</p><ul>
<li><a href="http://typekit.zendesk.com/entries/130054-using-typekit-the-basics" target="_blank">' . __('Using Typekit – The Basics', TYPEKITFONTS_TEXTDOMAIN) . '</a></li>
<li><a href="http://typekit.zendesk.com/entries/121731-using-typekit-with-wordpress" target="_blank">' . __('Using Typekit with WordPress', TYPEKITFONTS_TEXTDOMAIN) . '</a></li>
<li><a href="http://typekit.zendesk.com/entries/130283-finding-and-using-selectors" target="_blank">' . __('Finding and Using Selectors', TYPEKITFONTS_TEXTDOMAIN) . '</a></li>
</ul>'; }
return $contextual_help;
}
add_action( 'contextual_help', 'typekit_font_help', 10, 3 );
add_action( 'admin_menu', 'add_fonts_page' );
add_action( 'admin_init', 'register_typekit' );
function fonts_page() {
settings_fields( TYPEKITFONTS_TEXTDOMAIN );
// Update Settings
if ( isset($_POST['submit']) ) {
if (!current_user_can('manage_options')) die(__('You cannot edit this screen.', TYPEKITFONTS_TEXTDOMAIN));
$typekit_id = $_POST['typekit_id'];
update_option("typekit_id", $typekit_id);
}
?>
<style type="text/css">
div.typekit_box_one {border: 1px solid #CCC;clear: left;float: left;height: 220px;margin-right: 25px;padding: 0px 20px;width: 260px;}
div.typekit_box_two {border: 1px solid #CCC;float: left;height: 220px;margin-right: 25px;padding: 0px 20px;width: 260px;}
</style>
<div class="wrap">
<div id="icon-themes" class="icon32"><br></div>
<h2><?php _e('Typekit Fonts', TYPEKITFONTS_TEXTDOMAIN) ?></h2>
<p><a href="http://typekit.com/"><strong><?php _e('Typekit', TYPEKITFONTS_TEXTDOMAIN); ?></strong></a> <?php _e('is the easiest way to use real fonts on the web. It&rsquo;s a subscription-based service for linking to high-quality Open Type fonts from some of the worlds best type foundries. Typekit fonts are served from a global network on redundant servers, offering bulletproof service and incredible speed. And it couldn&rsquo;t be easier to use.', TYPEKITFONTS_TEXTDOMAIN); ?></p>
<div class="typekit_box_one">
<form action="themes.php?page=typekitfonts" method="post">
<h3><?php _e('Your Typekit ID', TYPEKITFONTS_TEXTDOMAIN); ?></h3>
<p><?php _e('You can find your Typekit ID on typekit.com under Kit Editor -> Embed Code.', TYPEKITFONTS_TEXTDOMAIN); ?></p>
<?php $typekit_id = get_option( 'typekit_id' );?>
<p><input type="text" size="25" name="typekit_id" value="<?php echo $typekit_id; ?>" /></p>
<p class="submit"><input type="submit" name="submit" value="<?php _e('Update ID', TYPEKITFONTS_TEXTDOMAIN); ?>" /></p>
</form>
</div>
<div class="typekit_box_two">
<form action="http://typekit.com/ref/wordpress" method="post">
<h3><?php _e('Sign up for Typekit', TYPEKITFONTS_TEXTDOMAIN); ?></h3>
<p><?php _e('If you don&#8217;t have a Typekit ID yet you can sign up on their site for free and enable it on your site with just a few clicks.', TYPEKITFONTS_TEXTDOMAIN); ?></p>
<p class="submit">
<input type="submit" name="submit" value="<?php _e('Sign up in seconds', TYPEKITFONTS_TEXTDOMAIN); ?>" />
</p>
</form>
</div> <?php
}
function typekit_header() {
$typekit_id = get_option( 'typekit_id' );
if ( $typekit_id != NULL ) {
echo ' <!-- Start Typekit Font download script -->
<script type="text/javascript" src="http://use.typekit.com/'. $typekit_id .'.js"></script>
<script type="text/javascript">try{Typekit.load();}catch(e){}</script>
<!-- End Typekit Font download script -->';
}
}
add_action('wp_head','typekit_header');
?>
<?php
/**
Plugin Name: Webmaster Tools
Plugin URI: http://github.com/mattrude/mdr-network
Description: Provides Webmaster site verification scripts for Google, Yahoo, & Bing. Plugin also provides Google Analytics Tracking Script for registered sites. See Tools -> Webmaster Tools
Version: 1.0
Author: Matt Rude
Author URI: http://mattrude.com
*/
define(WEBMASTER_TOOLS_TEXTDOMAIN, 'mdr-network');
$currentLocale = get_locale();
if(!empty($currentLocale)) {
$moFile = "/var/www/therudes.com/wp-content/mu-plugins/languages/" . $currentLocale . ".mo";
if(@file_exists($moFile) && is_readable($moFile)) load_textdomain('mdr-network', $moFile);
}
//if (function_exists('load_plugin_textdomain')) {
// load_plugin_textdomain(WEBMASTER_TOOLS_TEXTDOMAIN, false, dirname(__FILE__).'/languages' );
//}
function add_mdr_webmaster_tools() {
global $mdr_webmaster_tools_hook;
$mdr_webmaster_tools_hook = add_submenu_page( 'tools.php', 'Site Verification Sittings', __('Webmaster Tools', WEBMASTER_TOOLS_TEXTDOMAIN), 'administrator', 'site_webmaster_tools', 'mdr_webmaster_tools_page' );
}
function register_mdr_webmaster_tools() {
add_option('site_verification_google_id');
add_option('site_verification_yahoo_id');
add_option('site_verification_bing_id');
add_option('site_robots_txt');
add_default_robots_txt();
}
function my_plugin_help($contextual_help, $screen_id, $screen) {
global $mdr_webmaster_tools_hook;
if ($screen_id == $mdr_webmaster_tools_hook) {
$contextual_help = '<p>'.__('Here\'s how you optain and setup each search engines key\'s', WEBMASTER_TOOLS_TEXTDOMAIN).':</p>
<h4>' . __('Google Webmaster Tools', WEBMASTER_TOOLS_TEXTDOMAIN) . '</h4>
<ol>
<li>'.__('Log in to ', WEBMASTER_TOOLS_TEXTDOMAIN).'<a href="https://www.google.com/webmasters/tools/">https://www.google.com/webmasters/tools/</a> '.__('with your Google account.', WEBMASTER_TOOLS_TEXTDOMAIN).'</li>
<li>'.__('Enter your blog URL and click <code>Add Site</code>.', WEBMASTER_TOOLS_TEXTDOMAIN).'</li>
<li>'.__('You will be presented with several verification methods. Choose <code>Meta Tag</code>.', WEBMASTER_TOOLS_TEXTDOMAIN).'</li>
<li>'.__('Copy the meta tag, which looks something like', WEBMASTER_TOOLS_TEXTDOMAIN).':<br />
<code>&lt;meta name="google-site-verification" content="dBw5CvburAxi537Rp9qi5uG2174Vb6JwHwIRwPSLIK8"&gt;</code></li>
<li>'.__('Leave the verification page open and go to your blog dashboard.', WEBMASTER_TOOLS_TEXTDOMAIN).'</li>
<li>'.__('Open the Tools Page and paste the code in the appropriate field.', WEBMASTER_TOOLS_TEXTDOMAIN).'</li>
<li>'.__('Click on <code>Save Changes</code>.', WEBMASTER_TOOLS_TEXTDOMAIN).'</li>
<li>'.__('Go back to the verification page and click <code>Verify</code>.', WEBMASTER_TOOLS_TEXTDOMAIN).'</li>
</ol>
<h4>'.__('Yahoo Site Explorer', WEBMASTER_TOOLS_TEXTDOMAIN).'</h4>
<ol>
<li>'.__('Log in to', WEBMASTER_TOOLS_TEXTDOMAIN).' <a href="https://siteexplorer.search.yahoo.com/">https://siteexplorer.search.yahoo.com/</a> '.__('with your Yahoo account.', WEBMASTER_TOOLS_TEXTDOMAIN).'</li>
<li>'.__('Enter your blog URL and click <code>Add My Site</code>.', WEBMASTER_TOOLS_TEXTDOMAIN).'</li>
<li>'.__('You will be presented with several authentication methods. Choose <code>By adding a META tag to my home page.</code>.', WEBMASTER_TOOLS_TEXTDOMAIN).'</li>
<li>'.__('Copy the meta tag, which looks something like', WEBMASTER_TOOLS_TEXTDOMAIN).'<br />
<code>&lt;meta name="y_key" content="3236dee82aabe064"&gt;</code></li>
<li>'.__('Leave the verification page open and go to your blog dashboard.', WEBMASTER_TOOLS_TEXTDOMAIN).'</li>
<li>'.__('Open the Tools Page and paste the code in the appropriate field.', WEBMASTER_TOOLS_TEXTDOMAIN).'</li>
<li>'.__('Click on <code>Save Changes</code>.', WEBMASTER_TOOLS_TEXTDOMAIN).'</li>
<li>'.__('Go back to the verification page and click <code>Ready to Authenticate</code>.', WEBMASTER_TOOLS_TEXTDOMAIN).'</li>
</ol>
<p><i>'.__('Note: It may take up to 24 hours for your site to be authenticated.', WEBMASTER_TOOLS_TEXTDOMAIN).'</i></p>
<h4>'.__('Bing Webmaster Center', WEBMASTER_TOOLS_TEXTDOMAIN).'</h4>
<ol>
<li>'.__('Log in to', WEBMASTER_TOOLS_TEXTDOMAIN).' <a href="http://www.bing.com/webmaster">http://www.bing.com/webmaster</a> '.__('with your Live! account.', WEBMASTER_TOOLS_TEXTDOMAIN).'</li>
<li>'.__('Click <code>Add a Site</code>.', WEBMASTER_TOOLS_TEXTDOMAIN).'</li>
<li>'.__('Enter your blog URL and click <code>Submit</code>.', WEBMASTER_TOOLS_TEXTDOMAIN).'</li>
<li>'.__('Copy the meta tag from the text area at the bottom. It looks something like', WEBMASTER_TOOLS_TEXTDOMAIN).'<br />
<code>&lt;meta name="msvalidate.01" content="12C1203B5086AECE94EB3A3D9830B2E"&gt;</code></li>
<li>'.__('Leave the verification page open and go to your blog dashboard.', WEBMASTER_TOOLS_TEXTDOMAIN).'</li>
<li>'.__('Open the Tools Page and paste the code in the appropriate field.', WEBMASTER_TOOLS_TEXTDOMAIN).'</li>
<li>'.__('Click on <code>Save Changes</code>.', WEBMASTER_TOOLS_TEXTDOMAIN).'</li>
<li>'.__('Go back to the verification page and click <code>Return to the Site list</code>.', WEBMASTER_TOOLS_TEXTDOMAIN).'</li>
</ol>
<h3>'.__('The Robots.txt File', WEBMASTER_TOOLS_TEXTDOMAIN).'</h3>
<p>'.__('The <strong>robots.txt</strong> file is a way to prevent cooperating web spiders and other web robots from accessing all or part of a website which is otherwise publicly viewable. Robots are often used by search engines to categorize and archive web sites, or by webmasters to proofread source code.', WEBMASTER_TOOLS_TEXTDOMAIN).'</p>
<h4>'.__('To Allow all robots', WEBMASTER_TOOLS_TEXTDOMAIN).'</h4>
<p>'.__('To allow any robot to access your entire site, you can simply leave the robots.txt file blank, or you could use this', WEBMASTER_TOOLS_TEXTDOMAIN).':</p>
<blockquote><pre>User-agent: *<br />Disallow:</pre></blockquote>
<h4'.__('>To Ban all robots', WEBMASTER_TOOLS_TEXTDOMAIN).'</h4>
<blockquote><pre>User-agent: *<br />Disallow: /</pre></blockquote>
<h4>'.__('To Ban all crawlers from four directories of a website', WEBMASTER_TOOLS_TEXTDOMAIN).'</h4>
<blockquote><pre>User-agent: *<br />Disallow: /cgi-bin/<br />Disallow: /images/<br />Disallow: /tmp/<br />Disallow: /private/</pre></blockquote>';
}
return $contextual_help;
}
add_action( 'contextual_help', 'my_plugin_help', 10, 3 );
add_action( 'admin_menu', 'add_mdr_webmaster_tools' );
add_action( 'admin_init', 'register_mdr_webmaster_tools' );
add_action( 'wp_head', 'head_mdr_webmaster_tools' );
function head_mdr_webmaster_tools() {
$site_verification_google_id = get_option( 'site_verification_google_id' );
$site_verification_yahoo_id = get_option( 'site_verification_yahoo_id' );
$site_verification_bing_id = get_option( 'site_verification_bing_id' );
$site_google_analytics_id = get_option( 'site_google_analytics_id' );
echo "
<!-- Start Website Verification scripts -->";
if ( $site_verification_google_id != NULL ) {
echo "
<meta name='google-site-verification' content='$site_verification_google_id' />
";
}
if ( $site_verification_yahoo_id != NULL ) {
echo "<meta name='y_key' content='$site_verification_yahoo_id'>
";
}
if ( $site_verification_bing_id != NULL ) {
echo "<meta name='msvalidate.01' content='$site_verification_bing_id'>
";
}
echo "<!-- End Website Verification scripts -->
";
echo "<!-- Start Google Analytics tracking script -->
";
if ( is_user_logged_in() ) {
echo "<!-- User is logged in, so this request will NOT be tracked by Google Analytics -->
";
} else {
if ( $site_google_analytics_id != NULL ) { ?>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '<?php echo $site_google_analytics_id; ?>']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);
})();
</script>
<?php } else {
echo "<!-- User is NOT logged in, but Google Analytics is not configured, so will not be displayed -->
";
}
}
echo "<!-- End Google Analytics tracking script -->
";
}
function add_default_robots_txt() {
// Adds default robots.txt file
$site_url = get_option('siteurl');
$site_robots_txt_out = get_option('site_robots_txt');
if (!$site_robots_txt_out) {
$site_robots_txt_default = "# This is the default robots.txt file
User-agent: *
Disallow:";
update_option('site_robots_txt', $site_robots_txt_default);
}
}
$request = str_replace( get_bloginfo('url'), '', 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'] );
if ( (get_bloginfo('url').'/robots.txt' != 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']) && ('/robots.txt' != $_SERVER['REQUEST_URI']) && ('robots.txt' != $_SERVER['REQUEST_URI']) )
return; // checking whether they're requesting robots.txt
$blog_public = get_option('blog_public');
if ( $blog_public == 1 ) {
$site_robots_txt_out = get_option('site_robots_txt');
if ( !$site_robots_txt_out) { return; }
$site_url = 'http://' . $_SERVER['HTTP_HOST'];
header('Content-type: text/plain');
print $site_robots_txt_out;
echo "
";
echo "Sitemap: $site_url/sitemap.xml";
} else {
return;
}
die;
function mdr_webmaster_tools_page() {
// Update Settings
if ( isset($_POST['submit']) ) {
if (!current_user_can('manage_options')) die(__('You cannot edit this screen.', WEBMASTER_TOOLS_TEXTDOMAIN));
update_option( 'site_verification_google_id', $_POST['site_verification_google_id'] );
update_option( 'site_verification_yahoo_id', $_POST['site_verification_yahoo_id'] );
update_option( 'site_verification_bing_id', $_POST['site_verification_bing_id'] );
update_option( 'site_google_analytics_id', $_POST['site_google_analytics_id'] );
update_option( 'site_robots_txt', $_POST['site_robots_txt'] );
}
// The is the robots.txt reset button
if ( isset($_POST['reset_robots']) ) {
if (!current_user_can('manage_options')) die(__('You cannot edit this screen.', WEBMASTER_TOOLS_TEXTDOMAIN));
delete_option( 'site_robots_txt');
add_default_robots_txt();
}
// Set Current Options after updating
$site_verification_google_id = get_option( 'site_verification_google_id' );
$site_verification_yahoo_id = get_option( 'site_verification_yahoo_id' );
$site_verification_bing_id = get_option( 'site_verification_bing_id' );
$site_google_analytics_id = get_option( 'site_google_analytics_id' );
$site_robots_txt_out = get_option('site_robots_txt');
// And Display the Admin Page ?>
<style type="text/css">
div.robots_txt_in {border: 1px solid #CCC;clear: left;float: left;height: 220px;margin-right: 25px;margin: 0px 5px 10px;padding: 10px;width: 45%;}
div.robots_txt_out {border: 1px solid #CCC;float: left;height: 220px;margin-right: 25px;margin: 0px 5px 10px;padding: 10px;width: 45%;}
div.robots_txt_in_lable {clear: left;float: left;margin-right: 25px;margin: 0px 5px;width: 45%;}
div.robots_txt_out_lable {float: left;margin-right: 25px;margin: 0px 10px;padding: 0 20px;width: 45%;}
</style>
<div class="wrap">
<div id="icon-themes" class="icon32"><br></div>
<h2><?php _e('Webmaster Tools', WEBMASTER_TOOLS_TEXTDOMAIN); ?></h2>
<h3><?php _e('Site Verification', WEBMASTER_TOOLS_TEXTDOMAIN); ?></h3>
<p><?php _e('All three major search engines provide webmaster tools that give you detailed information and statistics about how they see and crawl your website. In order to access most of the features, you will have to verify your sites.', WEBMASTER_TOOLS_TEXTDOMAIN); ?></p>
<p><?php _e('Enter your meta key "content" value to verify your blog with', WEBMASTER_TOOLS_TEXTDOMAIN); ?>
<a href="https://www.google.com/webmasters/tools/" target="_blank" ><?php _e('Google Webmaster Tools', WEBMASTER_TOOLS_TEXTDOMAIN); ?></a>,
<a href="https://siteexplorer.search.yahoo.com/" target="_blank" ><?php _e('Yahoo! Site Explorer', WEBMASTER_TOOLS_TEXTDOMAIN); ?></a>,
<?php _e('and', WEBMASTER_TOOLS_TEXTDOMAIN); ?>
<a href="http://www.bing.com/webmaster" target="_blank" ><?php _e('Bing Webmaster Center', WEBMASTER_TOOLS_TEXTDOMAIN); ?></a>
</p>
<form method="post" action="tools.php?page=site_webmaster_tools">
<table class="form-table">
<tr valign='top'>
<th scope='row'><?php _e('Google Webmaster Tools', WEBMASTER_TOOLS_TEXTDOMAIN); ?>:</th>
<td>
<input value='<?php echo $site_verification_google_id ?>' size='70' name='site_verification_google_id' type='text' />
<?php if ( $site_verification_google_id == NULL ) { echo "<span style='color: red'><strong>" . __('Disabled', WEBMASTER_TOOLS_TEXTDOMAIN) . "</strong></span>"; } else { echo "<span style='color: green'><strong>" . __('Enabled', WEBMASTER_TOOLS_TEXTDOMAIN) . "</strong></span>"; }?>
</td>
</tr><tr>
<td colspan='2'>
<label for='site_verification_google'><?php _e('Example', WEBMASTER_TOOLS_TEXTDOMAIN); ?>: <code>&lt;meta name='google-site-verification' content='<strong>dBw5CvburAxi537Rp9qi5uG2174Vb6JwHwIRwPSLIK8</strong>'&gt;</code></label>
</td>
</tr><tr valign='top'>
<th scope='row'><?php _e('Yahoo! Site Explorer', WEBMASTER_TOOLS_TEXTDOMAIN); ?>:</th>
<td>
<input value='<?php echo $site_verification_yahoo_id ?>' size='50' name='site_verification_yahoo_id' type='text' />
<?php if ( $site_verification_yahoo_id == NULL ) { echo "<span style='color: red'><strong>" . __('Disabled', WEBMASTER_TOOLS_TEXTDOMAIN) . "</strong></span>"; } else { echo "<span style='color: green'><strong>" . __('Enabled', WEBMASTER_TOOLS_TEXTDOMAIN) . "</strong></span>"; }?>
</td>
</tr><tr>
<td colspan='2'>
<label for='site_verification_yahoo'><?php _e('Example', WEBMASTER_TOOLS_TEXTDOMAIN); ?>: <code>&lt;meta name='y_key' content='<strong>3236dee82aabe064</strong>'&gt;</code></label>
</td>
</tr><tr valign='top'>
<th scope='row'><?php _e('Bing Webmaster Center', WEBMASTER_TOOLS_TEXTDOMAIN); ?>:</th>
<td>
<input value='<?php echo $site_verification_bing_id ?>' size='50' name='site_verification_bing_id' type='text' />
<?php if ( $site_verification_bing_id == NULL ) { echo "<span style='color: red'><strong>" . __('Disabled', WEBMASTER_TOOLS_TEXTDOMAIN) . "</strong></span>"; } else { echo "<span style='color: green'><strong>" . __('Enabled', WEBMASTER_TOOLS_TEXTDOMAIN) . "</strong></span>"; }?>
</td>
</tr><tr>
<td colspan='2'>
<label for='site_verification_bing'><?php _e('Example', WEBMASTER_TOOLS_TEXTDOMAIN); ?>: <code>&lt;meta name='msvalidate.01' content='<strong>12C1203B5086AECE94EB3A3D9830B2E</strong>'&gt;</code></label>
</td>
</tr>
</table>
<br />
<h3><?php _e('Google Analytics Tracking Script', WEBMASTER_TOOLS_TEXTDOMAIN); ?></h3>
<p><a href="http://www.google.com/analytics/" target="_blank" ><?php _e('Google Analytics', WEBMASTER_TOOLS_TEXTDOMAIN); ?></a> <?php _e('is a web analytics solution that gives you rich insights into your website traffic and marketing effectiveness. Powerful, flexible and easy-to-use features now let you see and analyze your traffic data in an entirely new way. With Google Analytics, you\'re more prepared to write better-targeted ads, strengthen your marketing initiatives and create higher converting websites.', WEBMASTER_TOOLS_TEXTDOMAIN); ?></p>
<p><?php _e('Enter your', WEBMASTER_TOOLS_TEXTDOMAIN); ?> "<strong><?php _e('Account ID', WEBMASTER_TOOLS_TEXTDOMAIN); ?></strong>" <?php _e('for this site, to allow', WEBMASTER_TOOLS_TEXTDOMAIN); ?> <a href="http://www.google.com/analytics/" target="_blank" ><?php _e('Google Analytics', WEBMASTER_TOOLS_TEXTDOMAIN); ?></a> <?php _e('to track you page views.', WEBMASTER_TOOLS_TEXTDOMAIN); ?></p>
<table class="form-table">
<tr valign='top'>
<th scope='row'><?php _e('Google Analytics Tracking ID', WEBMASTER_TOOLS_TEXTDOMAIN); ?>:</th>
<td>
<input value='<?php echo $site_google_analytics_id ?>' size='20' name='site_google_analytics_id' type='text' />
<?php if ( $site_google_analytics_id == NULL ) { echo "<span style='color: red'><strong>" . __('Disabled', WEBMASTER_TOOLS_TEXTDOMAIN) . "</strong></span>"; } else { echo "<span style='color: green'><strong>" . __('Enabled', WEBMASTER_TOOLS_TEXTDOMAIN) . "</strong></span>"; }?>
</td>
</tr><tr>
<td colspan='2'>
<label for='site_google_analytics_id'><?php _e('Example', WEBMASTER_TOOLS_TEXTDOMAIN); ?>: <code><strong>UA-9527634-1</strong></code></label>
</td>
</tr>
</table>
<br />
<h3><?php _e('Robots.txt File', WEBMASTER_TOOLS_TEXTDOMAIN); ?></h3>
<div class="inside">
<div class="wrap">
<?php $blog_public = get_option('blog_public');
if ( $blog_public == 1 ) {
$private_url = 'http://' . $_SERVER['HTTP_HOST'] . '/wp-admin/options-privacy.php'; ?>
<p><?php _e('You may edit your robots.txt file in the space below. Lines beginning with <code>#</code> are treated as comments. If you don\'t understand what your doing, most likly you don\'t need to do anything.', WEBMASTER_TOOLS_TEXTDOMAIN); ?></p>
<p><?php _e('Using your robots.txt file, you can ban specific robots, ban all robots, or block robot access to specific pages or areas of your site. If you are not sure what to type, look at the bottom of this page for examples.', WEBMASTER_TOOLS_TEXTDOMAIN); ?></p>
<p><?php _e('To Disable all search engines from browsing your site, see the ', WEBMASTER_TOOLS_TEXTDOMAIN); ?><a href="<?php echo $private_url; ?>"><?php _e('Privacy Settings', WEBMASTER_TOOLS_TEXTDOMAIN); ?></a> <?php _e('page.', WEBMASTER_TOOLS_TEXTDOMAIN); ?></p>
<div class="robots_txt_in_lable"><strong><?php _e('Modify Your Robots.txt file', WEBMASTER_TOOLS_TEXTDOMAIN); ?>:</strong</div>
<div class="robots_txt_out_lable"><strong><?php _e('Your Current Robots.txt file', WEBMASTER_TOOLS_TEXTDOMAIN); ?>:</strong></div>
<div class="robots_txt_in">
<form method="post" action="http:// <?php echo $_SERVER['HTTP_HOST']; echo $_SERVER['REQUEST_URI']; ?>">
<textarea id="site_robots_txt" name="site_robots_txt" rows="10" cols="45" class="widefat"><?php echo $site_robots_txt_out; ?></textarea>
</form>
<div style="float: right;padding: 10px;">
<input type="submit" name="reset_robots" class="reset" value="<?php _e('reset robots.txt', WEBMASTER_TOOLS_TEXTDOMAIN); ?>" />
</div>
</div>
<div class="robots_txt_out">
<pre><?php echo $site_robots_txt_out;
$site_url = 'http://' . $_SERVER['HTTP_HOST'];
?> </pre>
</div>
</div>
</div>
<?php } else {
$private_url = 'http://' . $_SERVER['HTTP_HOST'] . '/wp-admin/options-privacy.php'; ?>
<p><?php _e('Privacy Settings are curently <strong>Blocking</strong> all search engines. Enable search engine browsing on the ', WEBMASTER_TOOLS_TEXTDOMAIN); ?><a href="<?php echo $private_url; ?>"><?php _e('Privacy Settings', WEBMASTER_TOOLS_TEXTDOMAIN); ?></a> <?php _e('page to be able to modify the robots.txt file.', WEBMASTER_TOOLS_TEXTDOMAIN); ?></p>
<?php } ?>
<br />
<p class="submit">
<input type="submit" name="submit" class="button-primary" value="<?php _e('Save Changes', WEBMASTER_TOOLS_TEXTDOMAIN); ?>" />
</p>
</form>
</div>
</div>
<?php
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment