Plugin Directory

Changeset 1865996


Ignore:
Timestamp:
04/29/2018 12:15:34 PM (8 years ago)
Author:
johnalarcon
Message:

Refactoring labels/ids, rework style/script enqueuing, reorder preset colors.

Location:
admin-bar-styler
Files:
12 added
4 edited

Legend:

Unmodified
Added
Removed
  • admin-bar-styler/trunk/alar-admin-bar-styler.php

    r1865958 r1865996  
    33 * Plugin Name: Admin Bar Styler
    44 * Description: Colorize the admin bar to match your site style, or make a visual distinction between different environments such as DEV, QA, UAT, PROD.
    5  * Version: 1.0.0
     5 * Version: 1.1.0
    66 * Author: John Alarcon
    77 * Author URI: https://johnalarcon.com
     
    4242     */
    4343    public function init() {
     44        // Add a Settings link to the core plugin admin page.
     45        add_filter('plugin_action_links_'.plugin_basename(__FILE__), array($this, 'add_action_link'));
     46        // Register settings and admin menu.
    4447        add_action('admin_init',            array($this, 'register_settings'));
    4548        add_action('admin_menu',            array($this, 'register_admin_menu'));
    46         add_action('admin_bar_menu',        array($this, 'add_label_to_admin_bar'), 1);
     49        // Enqueued styles (and script for admin).
    4750        add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts_and_styles'));
     51        add_action('wp_enqueue_scripts',    array($this, 'enqueue_scripts_and_styles'));
     52        // Inlined styles.
    4853        add_action('admin_enqueue_scripts', array($this, 'inline_styles'));
    4954        add_action('wp_enqueue_scripts',    array($this, 'inline_styles'));
    50         add_filter('plugin_action_links_'.plugin_basename(__FILE__), array($this, 'add_action_link'));
     55        // Settings link in core plugin view.
     56        add_action('admin_bar_menu',        array($this, 'add_label_to_admin_bar'), 1);
    5157    }
    5258
     
    9298
    9399        $options = get_option('admin_bar_styler', array());
    94         // Open content wrapper and print title.
    95100        echo '<div class="wrap">';
    96101        echo '<h1>'.__('Admin Bar Styler', 'alar-admin-bar-styler').'</h1>';
     
    100105        wp_nonce_field('admin_bar_styler_nonce');
    101106        echo '<table class="form-table">'."\n";
    102 
    103         echo '<tr valign="top">'."\n";
    104         echo '<th scope="row"><label for="enviro_label">'.__('Text Label', 'alar-environment-indicator').'</label></th>'."\n";
    105         echo '<td>';
    106         echo '<input type="text" name="admin_bar_styler[label]" id="enviro_label" value="'.esc_attr($options['label']).'" /><br />';
    107         echo '<span class="description"><label for="enviro_label">'.__('Optional label shown at upper left', 'alar-environment-indicator').'</label></span>';
    108         echo '</td>'."\n";
    109         echo '</tr>'."\n";
    110 
    111         echo '<tr valign="top">'."\n";
    112         echo '<th scope="row"><label for="enviro_bg_color">'.__('Admin Bar Color', 'alar-environment-indicator').'</label></th>'."\n";
    113         echo '<td>';
    114         echo '<input type="color" name="admin_bar_styler[bg_color]" id="enviro_bg_color" value="'.esc_attr($options['bg_color']).'" /><br />';
    115         echo '<span class="description"><label for="enviro_bg_color">'.__('Primay color for admin bar', 'alar-environment-indicator').'</label></span>';
    116         echo '</td>'."\n";
    117         echo '</tr>'."\n";
    118 
    119         echo '<tr valign="top">'."\n";
    120         echo '<th scope="row"><label for="enviro_hover_color">'.__('Admin Bar Hover', 'alar-environment-indicator').'</label></th>'."\n";
    121         echo '<td>';
    122         echo '<input type="color" name="admin_bar_styler[hover_color]" id="enviro_hover_color" value="'.esc_attr($options['hover_color']).'" /><br />';
    123         echo '<span class="description"><label for="enviro_hover_color">'.__('Hover color for admin bar', 'alar-environment-indicator').'</label></span>';
    124         echo '</td>'."\n";
    125         echo '</tr>'."\n";
    126 
    127         echo '<tr valign="top">'."\n";
    128         echo '<th scope="row"><label for="enviro_font_color">'.__('Font Color', 'alar-environment-indicator').'</label></th>'."\n";
    129         echo '<td>';
    130         echo '<input type="color" name="admin_bar_styler[font_color]" id="enviro_font_color" value="'.esc_attr($options['font_color']).'" /><br />';
    131         echo '<span class="description"><label for="enviro_font_color">'.__('Color for menu items', 'alar-environment-indicator').'</label></span>';
    132         echo '</td>'."\n";
    133         echo '</tr>'."\n";
    134 
    135         echo '<tr valign="top">'."\n";
    136         echo '<th scope="row"><label for="enviro_presets">'.__('Preset Schemes', 'alar-environment-indicator').'</label></th>'."\n";
    137         echo '<td>';
    138         echo '<style>
    139 
    140         </style>';
     107        echo '<tr valign="top">'."\n";
     108        echo '<th scope="row"><label for="admin-bar-styler-label">'.__('Text Label', 'alar-admin-bar-styler').'</label></th>'."\n";
     109        echo '<td>';
     110        echo '<input type="text" name="admin_bar_styler[label]" id="admin-bar-styler-label" value="'.esc_attr($options['label']).'" /><br />';
     111        echo '<span class="description"><label for="admin-bar-styler-label">'.__('Optional label shown at upper left', 'alar-admin-bar-styler').'</label></span>';
     112        echo '</td>'."\n";
     113        echo '</tr>'."\n";
     114        echo '<tr valign="top">'."\n";
     115        echo '<th scope="row"><label for="admin-bar-styler-bg-color">'.__('Admin Bar Color', 'alar-admin-bar-styler').'</label></th>'."\n";
     116        echo '<td>';
     117        echo '<input type="color" name="admin_bar_styler[bg_color]" id="admin-bar-styler-bg-color" value="'.esc_attr($options['bg_color']).'" /><br />';
     118        echo '<span class="description"><label for="admin-bar-styler-bg-color">'.__('Primay color for admin bar', 'alar-admin-bar-styler').'</label></span>';
     119        echo '</td>'."\n";
     120        echo '</tr>'."\n";
     121        echo '<tr valign="top">'."\n";
     122        echo '<th scope="row"><label for="admin-bar-styler-hover-color">'.__('Admin Bar Hover', 'alar-admin-bar-styler').'</label></th>'."\n";
     123        echo '<td>';
     124        echo '<input type="color" name="admin_bar_styler[hover_color]" id="admin-bar-styler-hover-color" value="'.esc_attr($options['hover_color']).'" /><br />';
     125        echo '<span class="description"><label for="admin-bar-styler-hover-color">'.__('Hover color for admin bar', 'alar-admin-bar-styler').'</label></span>';
     126        echo '</td>'."\n";
     127        echo '</tr>'."\n";
     128        echo '<tr valign="top">'."\n";
     129        echo '<th scope="row"><label for="admin-bar-styler-font-color">'.__('Font Color', 'alar-admin-bar-styler').'</label></th>'."\n";
     130        echo '<td>';
     131        echo '<input type="color" name="admin_bar_styler[font_color]" id="admin-bar-styler-font-color" value="'.esc_attr($options['font_color']).'" /><br />';
     132        echo '<span class="description"><label for="admin-bar-styler-font-color">'.__('Color for menu items', 'alar-admin-bar-styler').'</label></span>';
     133        echo '</td>'."\n";
     134        echo '</tr>'."\n";
     135        echo '<tr valign="top">'."\n";
     136        echo '<th scope="row"><label for="admin-bar-styler-presets">'.__('Preset Schemes', 'alar-admin-bar-styler').'</label></th>'."\n";
     137        echo '<td>';
    141138        echo '<div style="margin:20px 0;">';
    142         echo '<span class="admin_bar_styler_preset red">'.__('Text', 'alar-admin-bar-styler').'</span>';
    143         echo '<span class="admin_bar_styler_preset yellow">'.__('Text', 'alar-admin-bar-styler').'</span>';
    144         echo '<span class="admin_bar_styler_preset green">'.__('Text', 'alar-admin-bar-styler').'</span>';
    145         echo '<span class="admin_bar_styler_preset blue">'.__('Text', 'alar-admin-bar-styler').'</span>';
     139        echo '<span class="admin-bar-styler-preset red">'.__('Text', 'alar-admin-bar-styler').'</span>';
     140        echo '<span class="admin-bar-styler-preset yellow">'.__('Text', 'alar-admin-bar-styler').'</span>';
     141        echo '<span class="admin-bar-styler-preset blue">'.__('Text', 'alar-admin-bar-styler').'</span>';
     142        echo '<span class="admin-bar-styler-preset green">'.__('Text', 'alar-admin-bar-styler').'</span>';
    146143        echo '</div>';
    147144        echo '<span class="description">'.__('Click to load a preset', 'alar-admin-bar-styler').'</span></td>'."\n";
    148145        echo '</tr>'."\n";
    149         // Wrap up the table.
    150146        echo '</table>'."\n";
    151 
    152         // Serve up the submit button.
    153147        submit_button();
    154148        echo '</form>'."\n";
    155149        echo '</div>'."\n";
    156 
    157150    }
    158151
     
    162155    public function enqueue_scripts_and_styles() {
    163156        GLOBAL $plugin_page;
     157        wp_enqueue_style('admin-bar-styler', plugins_url('/styles/styles.css', __FILE__));
    164158        if (strstr($plugin_page, 'admin-bar-styler')) {
    165             wp_enqueue_style('admin-bar-styler', plugins_url('/styles/styles.css', __FILE__));
    166159            wp_enqueue_script('admin-bar-styler', plugins_url('/scripts/scripts.js', __FILE__), array('jquery'));
    167160        }
     
    191184     * Inline styles.
    192185     *
    193      * Inlining CSS only works if the style sheet is already enqueued. Even
    194      * though this plugin doesn't use a stylesheet, the handle must still be
    195      * registered and enqueued ahead of the inline styles being added.
    196      *
    197186     */
    198187    public function inline_styles() {
     
    201190            $this->update_settings();
    202191        }
    203         // Aforementioned requirements.
    204         wp_register_style('enviro-css', false);
    205         wp_enqueue_style('enviro-css');
    206192        // Inline the CSS.
    207193        $options = get_option('admin_bar_styler', array());
     
    217203        $css .= '#wpadminbar #adminbarsearch::before {color: '.$options['font_color'].' !important;}';
    218204        $css .= '#wpadminbar .ab-top-menu > li.admin-bar-styler-label > div.ab-empty-item {color: '.$options['font_color'].' !important;font-size:18pt;font-weight:bold;}';
    219         wp_add_inline_style('enviro-css', $css);
     205        wp_add_inline_style('admin-bar-styler', $css);
    220206    }
    221207
  • admin-bar-styler/trunk/readme.txt

    r1865958 r1865996  
    11=== Admin Bar Style ===
    22Contributors: johnalarcon
    3 Tags: admin bar, admin bar color, colorizer, admin style, environment indicator
     3Tags: admin bar, admin bar color, admin bar style, colorizer, environment indicator
    44Donate link: https://johnalarcon.com
    55Requires at least: 4.9
    66Tested up to: 4.9.5
    77Requires PHP: 7.2
    8 Stable tag: 1.0.0
     8Stable tag: 1.1.0
    99License: GPLv2 or later
    1010License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    2222* Search for "admin bar styler" and download the plugin.
    2323* Install using the plugin admin interface.
     24
     25== Changelog ==
     26## 1.1.0
     27- Enhance: rework script/style enqueuing.
     28- Enhance: added comments for clarity.
     29- Remove: enqueue pre inline styles; no longer necessary.
     30- Fix: Reorder preset scheme colors from RYGB to RYBG.
     31- Fix: Update label/ID prefixes since plugin was renamed for public use.
     32- Fix: Update text domain to reflect new plugin name.
     33
     34## 1.0.0
     35- Initial creation.
  • admin-bar-styler/trunk/scripts/scripts.js

    r1865958 r1865996  
    22 * Plugin Name: Admin Bar Styler
    33 * Description: Colorize the admin bar to match your site style, or make a visual distinction between different environments such as DEV, QA, UAT, PROD.
    4  * Version: 1.0.0
     4 * Version: 1.1.0
    55 * Author: John Alarcon
    66 * Author URI: https://johnalarcon.com
     
    2525jQuery(document).ready(function($) {
    2626   
    27     $(".admin_bar_styler_preset.red").click(function(){
    28         $("#enviro_bg_color").val("#d32f2f");
    29         $("#enviro_font_color").val("#dddddd");
    30         $("#enviro_hover_color").val("#b71c1c");
     27    $(".admin-bar-styler-preset.red").click(function(){
     28        $("#admin-bar-styler-bg-color").val("#d32f2f");
     29        $("#admin-bar-styler-font-color").val("#dddddd");
     30        $("#admin-bar-styler-hover-color").val("#b71c1c");
    3131    });
    32     $(".admin_bar_styler_preset.yellow").click(function(){
    33         $("#enviro_bg_color").val("#fdd835");
    34         $("#enviro_font_color").val("#555555");
    35         $("#enviro_hover_color").val("#ffeb3b");
     32    $(".admin-bar-styler-preset.yellow").click(function(){
     33        $("#admin-bar-styler-bg-color").val("#fdd835");
     34        $("#admin-bar-styler-font-color").val("#555555");
     35        $("#admin-bar-styler-hover-color").val("#ffeb3b");
    3636    });
    37     $(".admin_bar_styler_preset.green").click(function(){
    38         $("#enviro_bg_color").val("#1b5e20");
    39         $("#enviro_font_color").val("#dddddd");
    40         $("#enviro_hover_color").val("#558b2f");
     37    $(".admin-bar-styler-preset.green").click(function(){
     38        $("#admin-bar-styler-bg-color").val("#1b5e20");
     39        $("#admin-bar-styler-font-color").val("#dddddd");
     40        $("#admin-bar-styler-hover-color").val("#558b2f");
    4141    });
    42     $(".admin_bar_styler_preset.blue").click(function(){
    43         $("#enviro_bg_color").val("#1565c0");
    44         $("#enviro_font_color").val("#dddddd");
    45         $("#enviro_hover_color").val("#0d47a1");
     42    $(".admin-bar-styler-preset.blue").click(function(){
     43        $("#admin-bar-styler-bg-color").val("#1565c0");
     44        $("#admin-bar-styler-font-color").val("#dddddd");
     45        $("#admin-bar-styler-hover-color").val("#0d47a1");
    4646    });
    4747   
  • admin-bar-styler/trunk/styles/styles.css

    r1865958 r1865996  
    22 * Plugin Name: Admin Bar Styler
    33 * Description: Colorize the admin bar to match your site style, or make a visual distinction between different environments such as DEV, QA, UAT, PROD.
    4  * Version: 1.0.0
     4 * Version: 1.1.0
    55 * Author: John Alarcon
    66 * Author URI: https://johnalarcon.com
     
    2323 *
    2424 */
    25 .admin_bar_styler_preset {
     25.admin-bar-styler-preset {
    2626    margin-right:5px;
    2727    padding:15px;
     
    2929    color: #ddd;
    3030    }
    31 .admin_bar_styler_preset.red {
     31.admin-bar-styler-preset.red {
    3232    background: #d32f2f;
    3333    }
    34 .admin_bar_styler_preset.yellow {
     34.admin-bar-styler-preset.yellow {
    3535    background: #fdd835;
    3636    color: #555;
    3737    }
    38 .admin_bar_styler_preset.green {
     38.admin-bar-styler-preset.green {
    3939    background: #1b5e20;
    4040    }
    41 .admin_bar_styler_preset.blue {
     41.admin-bar-styler-preset.blue {
    4242    background: #1565c0;
    4343    }
Note: See TracChangeset for help on using the changeset viewer.