WordPress.org

Make WordPress Core

Changeset 13658


Ignore:
Timestamp:
03/11/2010 04:34:27 PM (9 years ago)
Author:
nacin
Message:

Introduce the disabled() form helper. Move selected() and checked() out of wp-admin and into full scope. see #12581

Location:
trunk
Files:
2 edited

Legend:

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

    r13624 r13658  
    171171
    172172    return $output;
    173 }
    174 
    175 /**
    176  * Outputs the html checked attribute.
    177  *
    178  * Compares the first two arguments and if identical marks as checked
    179  *
    180  * @since 1.0
    181  *
    182  * @param any $checked One of the values to compare
    183  * @param any $current (true) The other value to compare if not just true
    184  * @param bool $echo Whether to echo or just return the string
    185  */
    186 function checked( $checked, $current = true, $echo = true) {
    187     return __checked_selected_helper( $checked, $current, $echo, 'checked' );
    188 }
    189 
    190 /**
    191  * Outputs the html selected attribute.
    192  *
    193  * Compares the first two arguments and if identical marks as selected
    194  *
    195  * @since 1.0
    196  *
    197  * @param any selected One of the values to compare
    198  * @param any $current (true) The other value to compare if not just true
    199  * @param bool $echo Whether to echo or just return the string
    200  */
    201 function selected( $selected, $current = true, $echo = true) {
    202     return __checked_selected_helper( $selected, $current, $echo, 'selected' );
    203 }
    204 
    205 /**
    206  * Private helper function for checked and selected.
    207  *
    208  * Compares the first two arguments and if identical marks as $type
    209  *
    210  * @since 2.8
    211  * @access private
    212  *
    213  * @param any $helper One of the values to compare
    214  * @param any $current (true) The other value to compare if not just true
    215  * @param bool $echo Whether to echo or just return the string
    216  * @param string $type The type of checked|selected we are doing.
    217  */
    218 function __checked_selected_helper( $helper, $current, $echo, $type) {
    219     if ( (string) $helper === (string) $current)
    220         $result = " $type='$type'";
    221     else
    222         $result = '';
    223 
    224     if ($echo)
    225         echo $result;
    226 
    227     return $result;
    228173}
    229174
  • trunk/wp-includes/general-template.php

    r13502 r13658  
    22042204}
    22052205
     2206/**
     2207 * Outputs the html checked attribute.
     2208 *
     2209 * Compares the first two arguments and if identical marks as checked
     2210 *
     2211 * @since 1.0
     2212 *
     2213 * @param mixed $checked One of the values to compare
     2214 * @param mixed $current (true) The other value to compare if not just true
     2215 * @param bool $echo Whether to echo or just return the string
     2216 * @return string html attribute or empty string
     2217 */
     2218function checked( $checked, $current = true, $echo = true ) {
     2219    return __checked_selected_helper( $checked, $current, $echo, 'checked' );
     2220}
     2221
     2222/**
     2223 * Outputs the html selected attribute.
     2224 *
     2225 * Compares the first two arguments and if identical marks as selected
     2226 *
     2227 * @since 1.0
     2228 *
     2229 * @param mixed selected One of the values to compare
     2230 * @param mixed $current (true) The other value to compare if not just true
     2231 * @param bool $echo Whether to echo or just return the string
     2232 * @return string html attribute or empty string
     2233 */
     2234function selected( $selected, $current = true, $echo = true ) {
     2235    return __checked_selected_helper( $selected, $current, $echo, 'selected' );
     2236}
     2237
     2238/**
     2239 * Outputs the html disabled attribute.
     2240 *
     2241 * Compares the first two arguments and if identical marks as disabled
     2242 *
     2243 * @since 3.0.0
     2244 *
     2245 * @param mixed $disabled One of the values to compare
     2246 * @param mixed $current (true) The other value to compare if not just true
     2247 * @param bool $echo Whether to echo or just return the string
     2248 * @return string html attribute or empty string
     2249 */
     2250function disabled( $disabled, $current = true, $echo = true ) {
     2251    return __checked_selected_helper( $disabled, $current, $echo, 'disabled' );
     2252}
     2253
     2254/**
     2255 * Private helper function for checked, selected, and disabled.
     2256 *
     2257 * Compares the first two arguments and if identical marks as $type
     2258 *
     2259 * @since 2.8
     2260 * @access private
     2261 *
     2262 * @param any $helper One of the values to compare
     2263 * @param any $current (true) The other value to compare if not just true
     2264 * @param bool $echo Whether to echo or just return the string
     2265 * @param string $type The type of checked|selected|disabled we are doing
     2266 * @return string html attribute or empty string
     2267 */
     2268function __checked_selected_helper( $helper, $current, $echo, $type ) {
     2269    if ( (string) $helper === (string) $current )
     2270        $result = " $type='$type'";
     2271    else
     2272        $result = '';
     2273
     2274    if ( $echo )
     2275        echo $result;
     2276
     2277    return $result;
     2278}
     2279
    22062280?>
Note: See TracChangeset for help on using the changeset viewer.