2011-12-17 22:11:20 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Plugin Name: Badged
|
2011-12-18 15:56:15 +01:00
|
|
|
* Plugin URI: http://www.kremalicious.com/2011/12/badged/
|
|
|
|
* Description: Transforms the standard WordPress update & comment notification badges into iOS-styled ones. Just activate and enjoy the red badges.
|
2011-12-17 22:11:20 +01:00
|
|
|
* Author: Matthias Kretschmann
|
|
|
|
* Author URI: http://matthiaskretschmann.com
|
2011-12-18 15:56:15 +01:00
|
|
|
* Version: 0.3.3
|
2011-12-17 22:11:20 +01:00
|
|
|
* License: GPL
|
|
|
|
*/
|
|
|
|
|
2011-12-17 22:13:07 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Make the plugin work if symlinked
|
|
|
|
*
|
|
|
|
* Thanks to:
|
|
|
|
* http://alexking.org/blog/2011/12/15/wordpress-plugins-and-symlinks
|
|
|
|
*
|
|
|
|
* @since 0.3.2
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
$badged_plugin_file = __FILE__;
|
|
|
|
|
|
|
|
if (isset($plugin)) {
|
|
|
|
$badged_plugin_file = $plugin;
|
|
|
|
}
|
|
|
|
else if (isset($mu_plugin)) {
|
|
|
|
$badged_plugin_file = $mu_plugin;
|
|
|
|
}
|
|
|
|
else if (isset($network_plugin)) {
|
|
|
|
$badged_plugin_file = $network_plugin;
|
|
|
|
}
|
|
|
|
|
|
|
|
define('BADGED_PLUGIN_FILE', $badged_plugin_file);
|
|
|
|
define('BADGED_PLUGIN_PATH', WP_PLUGIN_DIR.'/'.basename(dirname($badged_plugin_file)));
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load translation
|
|
|
|
*
|
|
|
|
*/
|
2011-12-17 22:11:20 +01:00
|
|
|
if (function_exists('load_plugin_textdomain')) {
|
2011-12-17 22:13:07 +01:00
|
|
|
load_plugin_textdomain('bdgd', false, BADGED_PLUGIN_PATH.'/languages' );
|
2011-12-17 22:11:20 +01:00
|
|
|
}
|
2011-12-17 22:13:07 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register the styles depending on options
|
|
|
|
*
|
|
|
|
*/
|
2011-12-17 22:11:20 +01:00
|
|
|
function badged_init() {
|
|
|
|
badged_register_settings();
|
|
|
|
if ( get_option('menu') == 'yes') {
|
2011-12-17 22:13:07 +01:00
|
|
|
wp_register_style('badged-menu-css', plugins_url('css/badged-menu.css', BADGED_PLUGIN_FILE), false, '9001');
|
2011-12-17 22:11:20 +01:00
|
|
|
wp_enqueue_style('badged-menu-css');
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( get_option('bar') == 'yes') {
|
2011-12-17 22:13:07 +01:00
|
|
|
wp_register_style('badged-bar-css', plugins_url('css/badged-bar.css', BADGED_PLUGIN_FILE), false, '9001');
|
2011-12-17 22:11:20 +01:00
|
|
|
wp_enqueue_style('badged-bar-css');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function badged_bar_only_init() {
|
|
|
|
if ( get_option('bar') == 'yes') {
|
2011-12-17 22:13:07 +01:00
|
|
|
wp_register_style('badged-bar-css', plugins_url('css/badged-bar.css', BADGED_PLUGIN_FILE), false, '9001');
|
2011-12-17 22:11:20 +01:00
|
|
|
wp_enqueue_style('badged-bar-css');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-17 22:13:07 +01:00
|
|
|
/**
|
|
|
|
* Create the options page with our settings
|
|
|
|
*
|
|
|
|
*/
|
2011-12-17 22:11:20 +01:00
|
|
|
function badged_settings() {
|
|
|
|
add_options_page('Badged Options', 'Badged', 'manage_options', 'badged_settings', 'badged_settings_page');
|
|
|
|
}
|
|
|
|
|
|
|
|
function badged_register_settings() {
|
|
|
|
register_setting('badged', 'menu');
|
|
|
|
register_setting('badged', 'bar');
|
|
|
|
}
|
|
|
|
|
|
|
|
function badged_settings_page() {
|
|
|
|
require_once('badged-settings.php');
|
|
|
|
}
|
|
|
|
|
2011-12-17 22:13:07 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set default options upon activation
|
|
|
|
*
|
|
|
|
*/
|
2011-12-17 22:11:20 +01:00
|
|
|
function badged_activation() {
|
|
|
|
badged_register_settings();
|
|
|
|
update_option('menu', 'yes');
|
|
|
|
update_option('bar', 'yes');
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( is_admin() ) {
|
|
|
|
add_action('admin_init', 'badged_init');
|
|
|
|
add_action('admin_menu', 'badged_settings');
|
|
|
|
} elseif ( !is_admin() && get_option('bar') == 'yes' ) {
|
|
|
|
add_action('admin_bar_init', 'badged_bar_only_init');
|
|
|
|
}
|
|
|
|
|
2011-12-17 22:13:07 +01:00
|
|
|
register_activation_hook(BADGED_PLUGIN_FILE, 'badged_activation');
|
2011-12-17 22:11:20 +01:00
|
|
|
|
|
|
|
|
2011-12-17 22:13:07 +01:00
|
|
|
/**
|
|
|
|
* Add settings link on plugin page
|
|
|
|
*
|
|
|
|
*/
|
2011-12-17 22:11:20 +01:00
|
|
|
function badged_settings_link($links) {
|
|
|
|
$settings_link = '<a href="options-general.php?page=badged_settings">'. __('Settings') .'</a>';
|
|
|
|
array_unshift($links, $settings_link);
|
|
|
|
return $links;
|
|
|
|
}
|
|
|
|
|
2011-12-17 22:13:07 +01:00
|
|
|
$plugin = plugin_basename(BADGED_PLUGIN_FILE);
|
2011-12-17 22:11:20 +01:00
|
|
|
add_filter('plugin_action_links_'.$plugin, 'badged_settings_link' );
|
|
|
|
|
|
|
|
?>
|