WordPress.org

Make WordPress Core


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

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.