Changeset 1492178
- Timestamp:
- 09/08/2016 03:04:26 AM (10 years ago)
- Location:
- howdy-tweaks/trunk
- Files:
-
- 4 copied
-
howdy-greeting-tweaks.php (copied) (copied from howdy-tweaks/tags/2.2/howdy-greeting-tweaks.php) (14 diffs)
-
howdy.js (copied) (copied from howdy-tweaks/tags/2.2/howdy.js)
-
lang (copied) (copied from howdy-tweaks/tags/2.2/lang)
-
readme.txt (copied) (copied from howdy-tweaks/tags/2.2/readme.txt) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
howdy-tweaks/trunk/howdy-greeting-tweaks.php
r1492151 r1492178 5 5 Description: Tweaks to the Howdy greeting and Favorites menu 6 6 Author: Kailey Lampert 7 Version: 2. 27 Version: 2.3 8 8 Author URI: http://kaileylampert.com/ 9 9 … … 26 26 load_plugin_textdomain( 'howdy-tweaks', false, dirname( plugin_basename( __FILE__ ) ) . '/lang' ); 27 27 28 new howdy_tweaks();28 $howdy_tweaks = new howdy_tweaks(); 29 29 30 30 class howdy_tweaks { 31 31 32 /** 33 * Get hooked in 34 * 35 * @return void 36 */ 32 37 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 */ 42 51 function register() { 43 / * intercept user favorites */52 // intercept user favorites 44 53 if ( isset( $_POST['ht_options_user'] ) ) { 45 54 $input = $this->sanitize( $_POST['ht_options_user'] ); … … 47 56 } 48 57 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' ) ); 51 62 register_setting( 'howdy-tweaks_options', 'ht_greeting', 'esc_attr' ); 52 63 } 53 64 65 /** 66 * Sanitize options for saving 67 * 68 * @param array $input Options array 69 * @return array 70 */ 54 71 function sanitize( $input ) { 55 72 56 foreach ( $input as $k => $opts ) {73 foreach ( $input as $k => $opts ) { 57 74 $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'] ) ) { 62 79 unset( $input[ $k ] ); 80 } 63 81 } 64 82 … … 66 84 } 67 85 86 /** 87 * Create menu page 88 * Set up corresponding help tab 89 * 90 * @return void 91 */ 68 92 function menu() { 69 93 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 */ 74 104 function scripts( $hook ) { 75 if ( $hook != 'settings_page_howdy-tweaks' ) return; 105 if ( $hook != 'settings_page_howdy-tweaks' ) { 106 return; 107 } 76 108 wp_enqueue_script( 'jquery' ); 77 109 wp_enqueue_script( 'jquery-ui' ); … … 80 112 } 81 113 114 /** 115 * Output page 116 * 117 * @return void 118 */ 82 119 function page() { 83 120 84 121 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' : '' ) . '">'; 88 125 settings_fields( 'howdy-tweaks_options' ); 89 126 90 127 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' ); 163 137 164 138 submit_button( __( 'Save', 'howdy-tweaks' ), 'primary' ); … … 167 141 echo '</div>'; 168 142 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 */ 171 218 function help_tab() { 172 219 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() { 185 238 $help = ''; 186 239 $help .= '<p>' . __( 'Items checked "Favorites" will appear in a new Favorites menu on the right side of the Toolbar.', 'howdy-tweaks' ) . ' '; … … 192 245 return $help; 193 246 } 247 248 /** 249 * Insert custom 'user info' links 250 * 251 * @param WP_Admin_Bar $wp_admin_bar 252 * @return void 253 */ 194 254 function the_info_tweaks( $wp_admin_bar ) { 195 255 … … 199 259 $opts = array_filter( $opts ); //clean up empties 200 260 201 foreach ( $opts as $k => $vals ) {261 foreach ( $opts as $k => $vals ) { 202 262 if ( $vals['info'] ) { 203 263 … … 205 265 $node = array ( 206 266 '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'] 210 270 ); 211 271 … … 217 277 } 218 278 279 /** 280 * Insert custom 'favorite' links 281 * 282 * @param WP_Admin_Bar $wp_admin_bar 283 * @return void 284 */ 219 285 function the_favs_tweaks( $wp_admin_bar ) { 220 286 global $blog_id; … … 224 290 225 291 $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 ( 230 296 'class' => 'opposite' 231 297 ) 232 298 ) ); 233 299 $i = 0; 234 foreach ( $opts as $k => $vals ) {300 foreach ( $opts as $k => $vals ) { 235 301 if ( $vals['favs'] != 0 ) { 236 302 $label = str_replace( '%ID%', $blog_id, $vals['label'] ); 237 303 $node = array ( 238 304 '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'] 242 308 ); 243 309 … … 247 313 } 248 314 //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 */ 253 327 function change_howdy( $wp_admin_bar ) { 254 328 … … 256 330 257 331 //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' ); 259 333 //change the "howdy" 260 261 $user_id = get_current_user_id(); 334 335 // fetch user data 336 // $user_id = get_current_user_id(); 262 337 $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 ) { 266 341 $howdy = str_replace( '%name%', $current_user->display_name, $greeting ); 267 342 } else { … … 271 346 $my_account->title = $howdy . $avatar; 272 347 //remove the original node 273 $wp_admin_bar->remove_node( 'my-account');348 $wp_admin_bar->remove_node( 'my-account' ); 274 349 //add back our modified version 275 $wp_admin_bar->add_node( $my_account);276 277 } 278 279 } //end class howdy-tweaks350 $wp_admin_bar->add_node( $my_account ); 351 352 } 353 354 } //end class howdy-tweaks -
howdy-tweaks/trunk/readme.txt
r1492151 r1492178 4 4 Tags: howdy, favorites, admin links 5 5 Requires at least: 3.3 6 Tested up to: 4. 27 Stable tag: 2. 26 Tested up to: 4.6 7 Stable tag: 2.3 8 8 9 9 Change "Howdy" and add more links to the Favorites drop-down … … 26 26 1. WordPress 3.3 27 27 2. WordPress 3.3 28 3. pre 2.029 4. pre 2.030 28 31 29 == Upgrade Notice == 30 31 = 2.3 = 32 Maintenance. Tested up to 4.6. 32 33 33 34 = 2.2 =
Note: See TracChangeset
for help on using the changeset viewer.