WordPress.org

Make WordPress Core

Changeset 10662


Ignore:
Timestamp:
02/27/09 18:28:09 (6 years ago)
Author:
westi
Message:

Enhance checked and selected as well as consolidating code. See #9032 props johnbillion for the idea.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/template.php

    r10657 r10662  
    366366 
    367367/** 
    368  * {@internal Missing Short Description}} 
    369  * 
    370  * @since unknown 
    371  * 
    372  * @param unknown_type $checked 
    373  * @param unknown_type $current 
    374  */ 
    375 function checked( $checked, $current) { 
    376     if ( $checked == $current) 
    377         echo ' checked="checked"'; 
    378 } 
    379  
    380 /** 
    381  * {@internal Missing Short Description}} 
    382  * 
    383  * @since unknown 
    384  * 
    385  * @param unknown_type $selected 
    386  * @param unknown_type $current 
    387  */ 
    388 function selected( $selected, $current) { 
    389     if ( $selected == $current) 
    390         echo ' selected="selected"'; 
     368 * Outputs the html checked attribute. 
     369 * 
     370 * Compares the first two arguments and if identical marks as checked 
     371 *  
     372 * @since unknown 
     373 * 
     374 * @param any $checked One of the values to compare 
     375 * @param any $current (true) The other value to compare if not just true 
     376 * @param bool $echo Whether or not to echo or just return the string 
     377 */ 
     378function checked( $checked, $current = true, $echo = true) { 
     379    return __checked_selected_helper( $checked, $current, $echo, 'checked' ); 
     380} 
     381 
     382/** 
     383 * Outputs the html selected attribute. 
     384 *  
     385 * Compares the first two arguments and if identical marks as selected 
     386 * 
     387 * @since unknown 
     388 * 
     389 * @param any $checked One of the values to compare 
     390 * @param any $current (true) The other value to compare if not just true 
     391 * @param bool $echo Whether or not to echo or just return the string 
     392 */ 
     393function selected( $selected, $current = true, $echo = true) { 
     394    return __checked_selected_helper( $selected, $current, $echo, 'selected' ); 
     395} 
     396 
     397/** 
     398 * Private helper function for checked and selected. 
     399 *  
     400 * Compares the first two arguments and if identical marks as $type 
     401 * 
     402 * @since unknown 
     403 * @access private 
     404 * 
     405 * @param any $checked One of the values to compare 
     406 * @param any $current (true) The other value to compare if not just true 
     407 * @param bool $echo Whether or not to echo or just return the string 
     408 * @param string $type The type of checked|selected we are doing. 
     409 */ 
     410function __checked_selected_helper( $helper, $current, $echo, $type) { 
     411    if ( $helper == $current) 
     412        $result = " $type='$type'"; 
     413    else 
     414        $result = ''; 
     415     
     416    if ($echo) 
     417        echo $result; 
     418     
     419    return $result; 
    391420} 
    392421 
Note: See TracChangeset for help on using the changeset viewer.