Plugin Directory

Changeset 1492178


Ignore:
Timestamp:
09/08/2016 03:04:26 AM (10 years ago)
Author:
trepmal
Message:

maintenance update

Location:
howdy-tweaks/trunk
Files:
4 copied

Legend:

Unmodified
Added
Removed
  • howdy-tweaks/trunk/howdy-greeting-tweaks.php

    r1492151 r1492178  
    55Description: Tweaks to the Howdy greeting and Favorites menu
    66Author: Kailey Lampert
    7 Version: 2.2
     7Version: 2.3
    88Author URI: http://kaileylampert.com/
    99
     
    2626load_plugin_textdomain( 'howdy-tweaks', false, dirname( plugin_basename( __FILE__ ) ) .  '/lang' );
    2727
    28 new howdy_tweaks();
     28$howdy_tweaks = new howdy_tweaks();
    2929
    3030class howdy_tweaks {
    3131
     32    /**
     33     * Get hooked in
     34     *
     35     * @return void
     36     */
    3237    function __construct() {
    33 
    34         add_action( 'admin_init', array( &$this, 'register' ) );
    35         add_action( 'admin_menu', array( &$this, 'menu' ) );
    36         add_action( 'admin_enqueue_scripts', array( &$this, 'scripts' ) );
    37         add_action( 'admin_bar_menu', array( &$this, 'the_info_tweaks' ) );
    38         add_action( 'admin_bar_menu', array( &$this, 'the_favs_tweaks'), 100 );
    39         add_action( 'admin_bar_menu', array( &$this, 'change_howdy' ) );
    40     }
    41 
     38        add_action( 'admin_init',            array( $this, 'register' ) );
     39        add_action( 'admin_menu',            array( $this, 'menu' ) );
     40        add_action( 'admin_enqueue_scripts', array( $this, 'scripts' ) );
     41        add_action( 'admin_bar_menu',        array( $this, 'the_info_tweaks' ) );
     42        add_action( 'admin_bar_menu',        array( $this, 'the_favs_tweaks' ), 100 );
     43        add_action( 'admin_bar_menu',        array( $this, 'change_howdy' ) );
     44    }
     45
     46    /**
     47     * Register and save options
     48     *
     49     * @return void
     50     */
    4251    function register() {
    43         /* intercept user favorites */
     52        // intercept user favorites
    4453        if ( isset( $_POST['ht_options_user'] ) ) {
    4554            $input = $this->sanitize( $_POST['ht_options_user'] );
     
    4756        }
    4857
    49         if ( ! current_user_can( 'manage_options' ) ) return;
    50         register_setting( 'howdy-tweaks_options', 'ht_options', array ( &$this, 'sanitize' ) );
     58        if ( ! current_user_can( 'manage_options' ) ) {
     59            return;
     60        }
     61        register_setting( 'howdy-tweaks_options', 'ht_options', array ( $this, 'sanitize' ) );
    5162        register_setting( 'howdy-tweaks_options', 'ht_greeting', 'esc_attr' );
    5263    }
    5364
     65    /**
     66     * Sanitize options for saving
     67     *
     68     * @param array $input Options array
     69     * @return array
     70     */
    5471    function sanitize( $input ) {
    5572
    56         foreach( $input as $k => $opts ) {
     73        foreach ( $input as $k => $opts ) {
    5774            $input[ $k ]['label'] = esc_attr( $opts['label'] );
    58             $input[ $k ]['favs'] = isset( $opts['favs'] ) ? 1 : '';
    59             $input[ $k ]['info'] = isset( $opts['info'] ) ? 1 : '';
    60             $input[ $k ]['url'] = empty( $opts['url'] ) ? '' : esc_url( $opts['url'] );
    61             if ( empty( $input[ $k ]['label'] ) )
     75            $input[ $k ]['favs']  = isset( $opts['favs'] ) ? 1 : '';
     76            $input[ $k ]['info']  = isset( $opts['info'] ) ? 1 : '';
     77            $input[ $k ]['url']   = empty( $opts['url'] ) ? '' : esc_url( $opts['url'] );
     78            if ( empty( $input[ $k ]['label'] ) ) {
    6279                unset( $input[ $k ] );
     80            }
    6381        }
    6482
     
    6684    }
    6785
     86    /**
     87     * Create menu page
     88     * Set up corresponding help tab
     89     *
     90     * @return void
     91     */
    6892    function menu() {
    6993        global $howdy_tweaks_page;
    70         $howdy_tweaks_page = add_options_page( __( 'Howdy Tweaks', 'howdy-tweaks' ),  __( 'Howdy Tweaks', 'howdy-tweaks' ), 'edit_posts', 'howdy-tweaks', array( &$this, 'page' ) );
    71         add_action("load-$howdy_tweaks_page", array( &$this, 'help_tab' ) );
    72     }
    73 
     94        $howdy_tweaks_page = add_options_page( __( 'Howdy Tweaks', 'howdy-tweaks' ),  __( 'Howdy Tweaks', 'howdy-tweaks' ), 'edit_posts', 'howdy-tweaks', array( $this, 'page' ) );
     95        add_action( "load-$howdy_tweaks_page", array( $this, 'help_tab' ) );
     96    }
     97
     98    /**
     99     * Enqueue scripts
     100     *
     101     * @param string $hook Page hook
     102     * @return void
     103     */
    74104    function scripts( $hook ) {
    75         if ( $hook != 'settings_page_howdy-tweaks' ) return;
     105        if ( $hook != 'settings_page_howdy-tweaks' ) {
     106            return;
     107        }
    76108        wp_enqueue_script( 'jquery' );
    77109        wp_enqueue_script( 'jquery-ui' );
     
    80112    }
    81113
     114    /**
     115     * Output page
     116     *
     117     * @return void
     118     */
    82119    function page() {
    83120
    84121        echo '<div class="wrap">';
    85         echo '<h2>' . __('Howdy Tweaks', 'howdy-tweaks' ) . '</h2>';
    86 
    87         echo '<form method="post" action="'. ( current_user_can( 'manage_options' ) ? 'options.php' : '' ) .'">';
     122        echo '<h2>' . __( 'Howdy Tweaks', 'howdy-tweaks' ) . '</h2>';
     123
     124        echo '<form method="post" action="' . ( current_user_can( 'manage_options' ) ? 'options.php' : '' ) . '">';
    88125        settings_fields( 'howdy-tweaks_options' );
    89126
    90127        if ( current_user_can( 'manage_options' ) ) {
    91             $greeting = get_option( 'ht_greeting', 'Howdy,');
    92    
    93             echo '<p><label for="greeting">' . __( 'Greeting', 'howdy-tweaks' ) . ': <input type="text" name="ht_greeting" id="greeting" value="' . $greeting. '" size="50" /></label></p>';
    94             echo '<p>'. sprintf( __( 'Available placeholders: %1$s', 'howdy-tweaks' ) , '<code>%name%</code>' ) .'<br />'.
    95             __( 'If not specified, %name% will be added to the end. ', 'howdy-tweaks' ) .'</p>';
    96         }
    97 
    98         /***************/
    99         function options_table( $name ) {
    100 
    101             $heading = '';
    102             if ( 'ht_options' == $name ) {
    103                 if ( ! current_user_can( 'manage_options' ) ) return;
    104                 $values = get_option( $name, array() );
    105                 $heading = '<h3>Global Options</h3>';
    106             }
    107             if ( 'ht_options_user' == $name ) {
    108                 $values = get_user_meta( get_current_user_id(), 'ht_options', true );
    109                 $values = empty( $values ) ? array() : $values;
    110                 $heading = '<h3>User Options</h3>';
    111             }
    112 
    113             echo '<div class="ht_options_group">';
    114             echo $heading;
    115             $garbage = uniqid();
    116             echo "<input type='hidden' class='ht_garbage' value='{$garbage}' />";
    117 
    118             //echo '<pre>'. print_r($values,true) .'</pre>';
    119 
    120             ?>
    121             <table class="widefat ht_table">
    122             <thead>
    123                 <tr>
    124                     <th><?php _e( 'Label', 'howdy-tweaks' ); ?></th>
    125                     <th><?php _e( 'Favorites', 'howdy-tweaks' ); ?></th>
    126                     <th><?php _e( 'Info Links', 'howdy-tweaks' ); ?></th>
    127                     <th><?php _e( 'Link', 'howdy-tweaks' ); ?></th>
    128                 </tr>
    129             </thead>
    130             <tfoot>
    131                 <tr>
    132                     <th><?php _e( 'Label', 'howdy-tweaks' ); ?></th>
    133                     <th><?php _e( 'Favorites', 'howdy-tweaks' ); ?></th>
    134                     <th><?php _e( 'Info Links', 'howdy-tweaks' ); ?></th>
    135                     <th><?php _e( 'Link', 'howdy-tweaks' ); ?></th>
    136                 </tr>
    137             </tfoot>
    138             <tbody>
    139                 <?php foreach( $values as $id => $opt ) { ?>
    140                 <tr>
    141                     <td><input type="text" name="<?php echo $name; ?>[<?php echo $id; ?>][label]" value="<?php echo $opt['label']; ?>" size="40" /></td>
    142                     <td><input type="checkbox" name="<?php echo $name; ?>[<?php echo $id; ?>][favs]" value="1" <?php checked($opt['favs']); ?> /></td>
    143                     <td><input type="checkbox" name="<?php echo $name; ?>[<?php echo $id; ?>][info]" value="1" <?php checked($opt['info']); ?> /></td>
    144                     <td><input type="text" name="<?php echo $name; ?>[<?php echo $id; ?>][url]" value="<?php echo $opt['url']; ?>" size="40" /></td>
    145                 </tr>
    146                 <?php } ?>
    147                 <tr class="ht_new_row">
    148                     <td><input type="text" name="<?php echo $name; ?>[<?php echo $garbage; ?>][label]" value="" size="40" /></td>
    149                     <td><input type="checkbox" name="<?php echo $name; ?>[<?php echo $garbage; ?>][favs]" value="" /></td>
    150                     <td><input type="checkbox" name="<?php echo $name; ?>[<?php echo $garbage; ?>][info]" value="" /></td>
    151                     <td><input type="text" name="<?php echo $name; ?>[<?php echo $garbage; ?>][url]" value="" size="40" /></td>
    152                 </tr>
    153             </tbody>
    154             </table>
    155             <?php
    156    
    157             echo '<p><a href="#" class="ht_add_new">' . __( 'Add another row', 'howdy-tweaks' ) . '</a></p>';
    158             echo '</div>';
    159         }///
    160        
    161         options_table( 'ht_options' );
    162         options_table( 'ht_options_user' );
     128            $greeting = get_option( 'ht_greeting', 'Howdy,' );
     129
     130            echo '<p><label for="greeting">' . __( 'Greeting', 'howdy-tweaks' ) . ': <input type="text" name="ht_greeting" id="greeting" value="' . $greeting . '" size="50" /></label></p>';
     131            echo '<p>' . sprintf( __( 'Available placeholders: %1$s', 'howdy-tweaks' ) , '<code>%name%</code>' ) . '<br />' .
     132            __( 'If not specified, %name% will be added to the end. ', 'howdy-tweaks' ) . '</p>';
     133        }
     134
     135        $this->options_table( 'ht_options' );
     136        $this->options_table( 'ht_options_user' );
    163137
    164138        submit_button( __( 'Save', 'howdy-tweaks' ), 'primary' );
     
    167141        echo '</div>';
    168142
    169     }// end page()
    170    
     143    } // end page()
     144
     145    /**
     146     * Print html tables for options fields
     147     *
     148     * @param string $name Which set of options to print
     149     * @return void
     150     */
     151    function options_table( $name ) {
     152
     153        $heading = '';
     154        if ( 'ht_options' == $name ) {
     155            if ( ! current_user_can( 'manage_options' ) ) return;
     156            $values = get_option( $name, array() );
     157            $heading = '<h3>Global Options</h3>';
     158        }
     159        if ( 'ht_options_user' == $name ) {
     160            $values = get_user_meta( get_current_user_id(), 'ht_options', true );
     161            $values = empty( $values ) ? array() : $values;
     162            $heading = '<h3>User Options</h3>';
     163        }
     164
     165        echo '<div class="ht_options_group">';
     166        echo $heading;
     167        $garbage = uniqid();
     168        echo "<input type='hidden' class='ht_garbage' value='{$garbage}' />";
     169
     170        //echo '<pre>' . print_r( $values, true ) . '</pre>';
     171
     172        ?>
     173        <table class="widefat ht_table">
     174        <thead>
     175            <tr>
     176                <th><?php _e( 'Label', 'howdy-tweaks' ); ?></th>
     177                <th><?php _e( 'Favorites', 'howdy-tweaks' ); ?></th>
     178                <th><?php _e( 'Info Links', 'howdy-tweaks' ); ?></th>
     179                <th><?php _e( 'Link', 'howdy-tweaks' ); ?></th>
     180            </tr>
     181        </thead>
     182        <tfoot>
     183            <tr>
     184                <th><?php _e( 'Label', 'howdy-tweaks' ); ?></th>
     185                <th><?php _e( 'Favorites', 'howdy-tweaks' ); ?></th>
     186                <th><?php _e( 'Info Links', 'howdy-tweaks' ); ?></th>
     187                <th><?php _e( 'Link', 'howdy-tweaks' ); ?></th>
     188            </tr>
     189        </tfoot>
     190        <tbody>
     191            <?php foreach ( $values as $id => $opt ) { ?>
     192            <tr>
     193                <td><input type="text"     name="<?php echo $name; ?>[<?php echo $id; ?>][label]" value="<?php    echo $opt['label']; ?>" size="40" /></td>
     194                <td><input type="checkbox" name="<?php echo $name; ?>[<?php echo $id; ?>][favs]"  value="1" <?php checked( $opt['favs'] ); ?> /></td>
     195                <td><input type="checkbox" name="<?php echo $name; ?>[<?php echo $id; ?>][info]"  value="1" <?php checked( $opt['info'] ); ?> /></td>
     196                <td><input type="text"     name="<?php echo $name; ?>[<?php echo $id; ?>][url]"   value="<?php    echo $opt['url']; ?>" size="40" /></td>
     197            </tr>
     198            <?php } ?>
     199            <tr class="ht_new_row">
     200                <td><input type="text"     name="<?php echo $name; ?>[<?php echo $garbage; ?>][label]" value="" size="40" /></td>
     201                <td><input type="checkbox" name="<?php echo $name; ?>[<?php echo $garbage; ?>][favs]"  value="" /></td>
     202                <td><input type="checkbox" name="<?php echo $name; ?>[<?php echo $garbage; ?>][info]"  value="" /></td>
     203                <td><input type="text"     name="<?php echo $name; ?>[<?php echo $garbage; ?>][url]"   value="" size="40" /></td>
     204            </tr>
     205        </tbody>
     206        </table>
     207        <?php
     208
     209        echo '<p><a href="#" class="ht_add_new">' . __( 'Add another row', 'howdy-tweaks' ) . '</a></p>';
     210        echo '</div>';
     211    }
     212
     213    /**
     214     * Set up help tab
     215     *
     216     * @return void
     217     */
    171218    function help_tab() {
    172219        global $howdy_tweaks_page;
    173         $screen = get_current_screen();
    174         if ( $screen->id != $howdy_tweaks_page )
    175             return;
    176 
    177         $screen->add_help_tab( array(
    178             'id'    => 'howdy-tweaks',
    179             'title' => __( 'Howdy Tweaks', 'howdy-tweaks' ),
    180             'content' => $this->help(),
    181         ) );
    182     }
    183 
    184     function help() {
     220        $screen = get_current_screen();
     221        if ( $screen->id != $howdy_tweaks_page ) {
     222            return;
     223        }
     224
     225        $screen->add_help_tab( array(
     226            'id'      => 'howdy-tweaks',
     227            'title'   => __( 'Howdy Tweaks', 'howdy-tweaks' ),
     228            'content' => $this->help_text(),
     229        ) );
     230    }
     231
     232    /**
     233     * Return help tab content
     234     *
     235     * @return string
     236     */
     237    function help_text() {
    185238        $help = '';
    186239        $help .= '<p>' . __( 'Items checked "Favorites" will appear in a new Favorites menu on the right side of the Toolbar.', 'howdy-tweaks' ) . ' ';
     
    192245        return $help;
    193246    }
     247
     248    /**
     249     * Insert custom 'user info' links
     250     *
     251     * @param WP_Admin_Bar $wp_admin_bar
     252     * @return void
     253     */
    194254    function the_info_tweaks( $wp_admin_bar ) {
    195255
     
    199259        $opts = array_filter( $opts ); //clean up empties
    200260
    201         foreach( $opts as $k => $vals ) {
     261        foreach ( $opts as $k => $vals ) {
    202262            if ( $vals['info'] ) {
    203263
     
    205265                $node = array (
    206266                    'parent' => 'my-account',
    207                     'id' => 'ht-info-'.sanitize_title( $label ),
    208                     'title' => $label,
    209                     'href' => $vals['url']
     267                    'id'     => 'ht-info-' . sanitize_title( $label ),
     268                    'title'  => $label,
     269                    'href'   => $vals['url']
    210270                );
    211271
     
    217277    }
    218278
     279    /**
     280     * Insert custom 'favorite' links
     281     *
     282     * @param WP_Admin_Bar $wp_admin_bar
     283     * @return void
     284     */
    219285    function the_favs_tweaks( $wp_admin_bar ) {
    220286        global $blog_id;
     
    224290
    225291        $wp_admin_bar->add_menu( array(
    226             'id' => 'favorites',
    227             'parent'    => 'top-secondary',
    228             'title' => 'Favorites',
    229             'meta' => array (
     292            'id'     => 'favorites',
     293            'parent' => 'top-secondary',
     294            'title'  => __( 'Favorites', 'howdy-tweaks' ),
     295            'meta'   => array (
    230296                'class' => 'opposite'
    231297            )
    232298        ) );
    233299        $i = 0;
    234         foreach( $opts as $k => $vals ) {
     300        foreach ( $opts as $k => $vals ) {
    235301            if ( $vals['favs'] != 0 ) {
    236302                $label = str_replace( '%ID%', $blog_id, $vals['label'] );
    237303                $node = array (
    238304                    'parent' => 'favorites',
    239                     'id' => 'ht-fave-'.sanitize_title( $label ),
    240                     'title' => $label,
    241                     'href' => $vals['url']
     305                    'id'     => 'ht-fave-' . sanitize_title( $label ),
     306                    'title'  => $label,
     307                    'href'   => $vals['url']
    242308                );
    243309
     
    247313        }
    248314        //if there are no 'favorites' items, remove the menu
    249         if ($i < 1) $wp_admin_bar->remove_menu( 'favorites');
    250 
    251     }
    252 
     315        if ( $i < 1 ) {
     316            $wp_admin_bar->remove_menu( 'favorites' );
     317        }
     318
     319    }
     320
     321    /**
     322     * Change the "howdy"
     323     *
     324     * @param WP_Admin_Bar $wp_admin_bar
     325     * @return void
     326     */
    253327    function change_howdy( $wp_admin_bar ) {
    254328
     
    256330
    257331        //get the node that contains "howdy"
    258         $my_account = $wp_admin_bar->get_node('my-account');
     332        $my_account = $wp_admin_bar->get_node( 'my-account' );
    259333        //change the "howdy"
    260        
    261         $user_id = get_current_user_id();
     334
     335        // fetch user data
     336        // $user_id      = get_current_user_id();
    262337        $current_user = wp_get_current_user();
    263         $avatar = get_avatar( $user_id, 16 );
    264 
    265         if (strpos( $greeting, '%name%' ) !== false ) {
     338        $avatar       = get_avatar( $current_user->ID, 16 );
     339
     340        if ( strpos( $greeting, '%name%' ) !== false ) {
    266341            $howdy = str_replace( '%name%', $current_user->display_name, $greeting );
    267342        } else {
     
    271346        $my_account->title = $howdy . $avatar;
    272347        //remove the original node
    273         $wp_admin_bar->remove_node('my-account');
     348        $wp_admin_bar->remove_node( 'my-account' );
    274349        //add back our modified version
    275         $wp_admin_bar->add_node($my_account);
    276 
    277     }
    278 
    279 }//end class howdy-tweaks
     350        $wp_admin_bar->add_node( $my_account );
     351
     352    }
     353
     354} //end class howdy-tweaks
  • howdy-tweaks/trunk/readme.txt

    r1492151 r1492178  
    44Tags: howdy, favorites, admin links
    55Requires at least: 3.3
    6 Tested up to: 4.2
    7 Stable tag: 2.2
     6Tested up to: 4.6
     7Stable tag: 2.3
    88
    99Change "Howdy" and add more links to the Favorites drop-down
     
    26261. WordPress 3.3
    27272. WordPress 3.3
    28 3. pre 2.0
    29 4. pre 2.0
    3028
    3129== Upgrade Notice ==
     30
     31= 2.3 =
     32Maintenance. Tested up to 4.6.
    3233
    3334= 2.2 =
Note: See TracChangeset for help on using the changeset viewer.