123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- <?php
- if (!class_exists("plug_color_admin_posts")) {
- class plug_color_admin_posts {
- private $options = array(); // Set $options in array
- private $settings = array(); // Set $setting in array
- var $hasform = true;
- var $startet = false;
- function __construct() {
- $this->title = __("Color admin posts", "dagsopt");
- }
- function start() {
- $this->startet = true;
- add_action('admin_menu', array(&$this, 'add_submenu'));
- add_action('admin_init', array(&$this, 'settings_api_init'));
- $this->options = get_option('color_admin_posts');
- add_action('admin_print_styles-edit.php', array(&$this, 'load_color'));
- add_action('admin_head', array(&$this, 'load_farbtastic'));
- if (!is_array(get_option('color_admin_posts'))) {$this->activate();}
- }
- function activate() {
- $options = array(
- 'color_draft' => '#FFFF99',
- 'color_pending' => '#87C5D6',
- 'color_published' => '#',
- 'color_future' => '#CCFF99',
- 'color_private' => '#FFCC99',
- );
- add_option('color_admin_posts', $options);
- }
- function deactivate() {
- delete_option('color_admin_posts');
- }
- function load_color() {
- $options = $this->options;
- ?>
- <style>
- .status-draft {
- background-color: <?php echo $options['color_draft']; ?> !important;
- }
- .status-future {
- background-color: <?php echo $options['color_future']; ?> !important;
- }
- .status-publish {
- background-color: <?php echo $options['color_published']; ?> !important;
- }
- .status-pending {
- background-color: <?php echo $options['color_pending']; ?> !important;
- }
- .status-private {
- background-color: <?php echo $options['color_private']; ?> !important;
- }
- </style>
- <?php
- }
- function load_farbtastic() {
- global $current_screen;
- // if($current_screen->id == 'appearance_page_color-admin-post') {
- wp_enqueue_style('farbtastic');
- wp_enqueue_script('farbtastic');
- // }
- }
- function get_color_admin_post_settings() {
- $this->settings['color_draft'] = array(
- 'title' => __('Drafts Posts', 'dagsopt'),
- );
- $this->settings['color_pending'] = array(
- 'section' => 'general',
- 'title' => __('Pendings Posts', 'dagsopt'),
- );
- $this->settings['color_published'] = array(
- 'title' => __('Published Posts', 'dagsopt'),
- );
- $this->settings['color_future'] = array(
- 'title' => __('Futures Posts', 'dagsopt'),
- );
- $this->settings['color_private'] = array(
- 'title' => __('Privates Posts', 'dagsopt'),
- );
- }
- function create_settings($args = array()) {
- extract($args);
- $field_args = array(
- 'id' => $id,
- 'label_for' => $id,
- );
- add_settings_field($id, $title, array(
- $this,
- 'display_settings',
- ), __FILE__, 'general', $field_args);
- }
- public function display_settings($args = array()) {
- extract($args);
- $options = $this->options;
- echo '<input class="regular-text" type="text" maxlength="7" id="' . $id . '" name="color_admin_posts[' . $id . ']" value="' . esc_attr($options[$id]) . '" />
- <br /><span class="description">' . '</span>
- <div id="farbtastic-' . $id . '" class="farbtastic"></div>';
- }
- function settings_api_init() {
- register_setting('color_admin_posts', 'color_admin_posts', array(
- &$this,
- 'validate_settings',
- ));
- add_settings_section('general', '', array(
- &$this,
- 'general_section_callback',
- ), __FILE__);
- // Get the configuration of fields
- $this->get_color_admin_post_settings();
- // Generate fields
- foreach ($this->settings as $id => $setting) {
- $setting['id'] = $id;
- $this->create_settings($setting);
- }
- }
- function general_section_callback() {
- echo '<p>' . __('Leave "#" for the default color.', 'dagsopt') . '</p>';
- }
- function validate_settings($input) {
- $input['color_draft'] = (preg_match('/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/', $input['color_draft'])) ? $input['color_draft'] : '#';
- $input['color_pending'] = (preg_match('/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/', $input['color_pending'])) ? $input['color_pending'] : '#';
- $input['color_published'] = (preg_match('/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/', $input['color_published'])) ? $input['color_published'] : '#';
- $input['color_future'] = (preg_match('/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/', $input['color_future'])) ? $input['color_future'] : '#';
- $input['color_private'] = (preg_match('/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/', $input['color_private'])) ? $input['color_private'] : '#';
- return $input;
- }
- function add_submenu() {
- $page = add_submenu_page('xwpplugins', __("Color Admin Posts"), __("Color Admin Posts"), 'edit_theme_options', 'color-admin-post', array(&$this, 'display_page'));
- }
- function display_page() {
- // Check if user can access to the plugin
- if (!current_user_can('administrator')) {
- wp_die(__('You do not have sufficient permissions to access this page.', 'dagsopt'));
- }
- ?>
- <div class="wrap">
- <div id="icon-options-general" class="icon32"></div>
- <h2>Color Admin Posts</h2>
- <form id="form-color-admin-posts" method="post" action="options.php">
- <?php
- settings_fields('color_admin_posts');
- do_settings_sections(__FILE__);
- submit_button(__('Save Changes', 'dagsopt'));
- ?>
- </form>
- </div>
- <script type="text/javascript">
- jQuery(function(){
- jQuery(document).ready(function() {
- jQuery('.regular-text').each(function() {
- jQuery('#farbtastic-'+this.id).hide();
- jQuery('#farbtastic-'+this.id).farbtastic(this);
- jQuery(this).click(function(){
- jQuery('#farbtastic-'+this.id).fadeIn();
- });
- jQuery(this).keyup(function() {
- if( jQuery(this).val() == '' ) {
- jQuery(this).val('#');
- }
- });
- });
- jQuery(document).mousedown(function() {
- jQuery('.farbtastic').each(function() {
- var display = jQuery('#'+this.id).css('display');
- if ( display == 'block' ) {
- jQuery('#'+this.id).fadeOut();
- }
- });
- });
- });
- });
- </script>
- <?php
- }
- function help() {
- ?>
- <?php echo (__("Adds colors to", "dagsopt")) ?> <a href="/wp-admin/edit.php"><?php echo (__("Posts", "dagsopt")) ?></a> <?php echo (__("and", "dagsopt")) ?> <a href="/wp-admin/edit.php?post_type=page"><?php echo (__("Pages", "dagsopt")) ?></a><br>
- <?php echo ($this->startet ? __('See below', 'dagsopt') : ''); ?>
- <?php
- }
- function admin_line() {
- ?>
- <a href="/wp-admin/admin.php?page=color-admin-post"><?php echo (__("Settings", "dagsopt")) ?></a>
- <?php
- $this->display_page();
- ?>
- <?php
- }
- }
- // Start this plugin once all other plugins are fully loaded
- global $plug_color_admin_posts;
- $plug_color_admin_posts = new plug_color_admin_posts();
- $this->dagsopt['plug_color_admin_posts'] = $plug_color_admin_posts;
- }
|