Created
September 30, 2010 22:45
-
-
Save vinhboy/605461 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: TwentyTen Adwords Plugin | |
Description: An easy way to add an Adwords to the TwentyTen theme without modifying it. | |
Author: vinhboy | |
Author URI: http://vinhboy.com | |
*/ | |
if (!class_exists("twentytenadwordsClass")) { | |
class twentytenAdwordsClass { | |
function __construct() { | |
global $wpdb; | |
// Worpress hooks | |
add_action('admin_menu',array(&$this, 'create_menu')); | |
add_action('admin_init',array(&$this, 'register_mysettings')); | |
add_action('get_header',array(&$this, 'get_header')); | |
add_action('wp_head',array(&$this, 'wp_head')); | |
} | |
function register_mysettings() { | |
register_setting( 'twentytenadwords-group', 'twentytenadwords_hide_header' ); | |
register_setting( 'twentytenadwords-group', 'twentytenadwords_show_dates' ); | |
register_setting( 'twentytenadwords-group', 'twentytenadwords_google_analytics' ); | |
register_setting( 'twentytenadwords-group', 'twentytenadwords_below_main_menu' ); | |
} | |
function create_menu() { | |
add_options_page( 'TwentyTen Adwords', 'TwentyTen Adwords', 'administrator', 'settings_page', array(&$this, 'settings_page')); | |
} | |
function settings_page() { | |
global $wpdb; | |
if (!current_user_can('manage_options')) { | |
wp_die( __('You do not have sufficient permissions to access this page.') ); | |
} | |
?> | |
<div class="wrap"> | |
<h2>TwentyTen Adwords Plugin</h2> | |
<form method="post" action="options.php"> | |
<?php settings_fields('twentytenadwords-group'); ?> | |
<ul> | |
<li> | |
<input name="twentytenadwords_hide_header" type="checkbox" value="1" <?php checked('1', get_option('twentytenadwords_hide_header')); ?> /> | |
<label for="twentytenadwords_hide_header">Hide header</label> | |
</li> | |
<li> | |
<input name="twentytenadwords_show_dates" type="checkbox" value="1" <?php checked('1', get_option('twentytenadwords_show_dates')); ?> /> | |
<label for="twentytenadwords_show_dates">Show dates</label> | |
</li> | |
<li> | |
<label>Google Analytics ID:</label><br /> | |
<input name="twentytenadwords_google_analytics" value="<?php echo get_option('twentytenadwords_google_analytics'); ?>" type="input" /> | |
</li> | |
<li> | |
<label>Below Main Menu:</label><br /> | |
<textarea name="twentytenadwords_below_main_menu" cols="60" rows="7"><?php echo get_option('twentytenadwords_below_main_menu'); ?></textarea> | |
</li> | |
</ul> | |
<p class="submit"> | |
<input type="submit" name="submit" class="button-primary" value="Save Changes"> | |
</p> | |
</form> | |
</div> | |
<?php | |
} | |
function get_header() { | |
require_once(STYLESHEETPATH . '/' . 'header.php'); | |
if (get_option('twentytenadwords_below_main_menu')): ?> | |
<div style='width: 728px;margin: auto; padding-bottom: 40px;'> | |
<?php echo get_option('twentytenadwords_below_main_menu'); ?> | |
</div> | |
<?php endif; | |
} | |
function wp_head() { | |
?> | |
<style type='text/css'> | |
<?php if (get_option('twentytenadwords_hide_header')): ?> | |
#branding img{display:none !important;} | |
<?php endif; ?> | |
<?php if (!get_option('twentytenadwords_show_dates')): ?> | |
.entry-meta{display:none !important;} | |
<?php endif; ?> | |
#wrapper { | |
-moz-border-radius: 10px; | |
border-radius: 10px; | |
} | |
</style> | |
<!-- GOOGLE ANALYTICS --> | |
<script type="text/javascript"> | |
window.google_analytics_uacct = "<?php echo get_option('twentytenadwords_google_analytics'); ?>"; | |
var _gaq = _gaq || []; | |
_gaq.push(['_setAccount', '<?php echo get_option('twentytenadwords_google_analytics'); ?>']); | |
_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'; | |
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); | |
})(); | |
</script> | |
<!-- GOOGLE ANALYTICS --> | |
<?php | |
} | |
} | |
} | |
$twentytenadwordsClass = new twentytenadwordsClass(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment