| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package Admin Bar |
| 4 |
*/ |
| 5 |
/* |
| 6 |
Plugin Name: Admin Bar |
| 7 |
Plugin URI: http://tsvang.net.ua |
| 8 |
Description: Enable or disable Frontend Admin Bar in wordpress 3.1 |
| 9 |
Version: 1.0 |
| 10 |
Author: Vladimir Tsvang |
| 11 |
Author URI: http://tsvang.net.ua |
| 12 |
License: GPLv2 or later |
| 13 |
*/ |
| 14 |
class AdminBar { |
| 15 |
var $pluginUrl; |
| 16 |
|
| 17 |
function AdminBar() { |
| 18 |
if(! is_admin()) { |
| 19 |
if(! (bool) get_option('show-ab')) { |
| 20 |
add_action('show_admin_bar', '__return_false'); |
| 21 |
} |
| 22 |
} else { |
| 23 |
$this->pluginUrl = WP_PLUGIN_URL.'/'.dirname(plugin_basename(__FILE__)); |
| 24 |
$this->LoadTextDomain(); |
| 25 |
add_action('wp_ajax_update_form', array(&$this, 'UpdateForm')); |
| 26 |
add_action('admin_menu', array(&$this,'MenuPagesInit')); |
| 27 |
add_action('admin_init',array(&$this,'Attachments')); |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
function MenuPagesInit() { |
| 32 |
add_submenu_page('themes.php', __('Admin Bar','ab'), __('Admin Bar','ab'), 'administrator', 'admin-bar', array(&$this,'AdminPage')); |
| 33 |
} |
| 34 |
|
| 35 |
function Attachments() { |
| 36 |
wp_register_script('admin-bar-plugin', $this->pluginUrl.'/js/admin-bar.js', array('jquery-form')); |
| 37 |
wp_enqueue_script('admin-bar-plugin'); |
| 38 |
|
| 39 |
wp_register_style('admin-bar-plugin', $this->pluginUrl.'/css/admin-bar.css'); |
| 40 |
wp_enqueue_style('admin-bar-plugin'); |
| 41 |
} |
| 42 |
function AdminPage() { |
| 43 |
$option = get_option('show-ab'); |
| 44 |
?> |
| 45 |
<div class="wrap"> |
| 46 |
<div class="updated" id="ab-update"></div> |
| 47 |
<div id="icon-tools" class="icon32"><br /></div> |
| 48 |
<h2><?php _e('Admin Bar','ab'); ?></h2> |
| 49 |
<div class="ab-content"> |
| 50 |
<form id="ab-form" action="" method="post"> |
| 51 |
<ul class="ab-form-controlls"> |
| 52 |
<li> |
| 53 |
<label for="ab-show" class="ab-control-title"><?php _e('Show Admin Bar in frontend'); ?></label> |
| 54 |
<input value="1" class="checkbox" type="checkbox" name="ab-show" <?php echo (( (bool) $option===true)? 'checked' : null); ?> /> |
| 55 |
</li> |
| 56 |
</ul> |
| 57 |
<input type="hidden" name="action" value="update_form" /> |
| 58 |
<input type="submit" class="button-primary alignleft" value="Save" /> |
| 59 |
</form> |
| 60 |
</div> |
| 61 |
</div> |
| 62 |
<?php |
| 63 |
} |
| 64 |
|
| 65 |
function UpdateForm() { |
| 66 |
if(isset($_POST['ab-show']) && $_POST['ab-show']==1) { |
| 67 |
update_option('show-ab', true); |
| 68 |
} else { |
| 69 |
update_option('show-ab', false); |
| 70 |
} |
| 71 |
_e('Option saved!','ab'); |
| 72 |
die(); |
| 73 |
} |
| 74 |
|
| 75 |
function LoadTextDomain() { |
| 76 |
$currentLocale = get_locale(); |
| 77 |
if(!empty($currentLocale)) { |
| 78 |
$moFile = $this->pluginUrl."/lang/".$currentLocale.".mo"; |
| 79 |
if(@file_exists($moFile) && is_readable($moFile)) |
| 80 |
load_textdomain('ab', $moFile); |
| 81 |
} |
| 82 |
} |
| 83 |
} |
| 84 |
$GLOBALS['admin-bar'] = new AdminBar(); |