From 1f422200ee7cd30abddf5898527101fb72988d6b Mon Sep 17 00:00:00 2001 From: nacin Date: Thu, 11 Mar 2010 16:34:27 +0000 Subject: [PATCH] Introduce the disabled() form helper. Move selected() and checked() out of wp-admin and into full scope. see #12581 git-svn-id: http://svn.automattic.com/wordpress/trunk@13658 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/template.php | 55 ------------------------ wp-includes/general-template.php | 74 ++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 55 deletions(-) diff --git a/wp-admin/includes/template.php b/wp-admin/includes/template.php index 69df74141..90b75460b 100644 --- a/wp-admin/includes/template.php +++ b/wp-admin/includes/template.php @@ -172,61 +172,6 @@ function link_cat_row( $category, $name_override = false ) { return $output; } -/** - * Outputs the html checked attribute. - * - * Compares the first two arguments and if identical marks as checked - * - * @since 1.0 - * - * @param any $checked One of the values to compare - * @param any $current (true) The other value to compare if not just true - * @param bool $echo Whether to echo or just return the string - */ -function checked( $checked, $current = true, $echo = true) { - return __checked_selected_helper( $checked, $current, $echo, 'checked' ); -} - -/** - * Outputs the html selected attribute. - * - * Compares the first two arguments and if identical marks as selected - * - * @since 1.0 - * - * @param any selected One of the values to compare - * @param any $current (true) The other value to compare if not just true - * @param bool $echo Whether to echo or just return the string - */ -function selected( $selected, $current = true, $echo = true) { - return __checked_selected_helper( $selected, $current, $echo, 'selected' ); -} - -/** - * Private helper function for checked and selected. - * - * Compares the first two arguments and if identical marks as $type - * - * @since 2.8 - * @access private - * - * @param any $helper One of the values to compare - * @param any $current (true) The other value to compare if not just true - * @param bool $echo Whether to echo or just return the string - * @param string $type The type of checked|selected we are doing. - */ -function __checked_selected_helper( $helper, $current, $echo, $type) { - if ( (string) $helper === (string) $current) - $result = " $type='$type'"; - else - $result = ''; - - if ($echo) - echo $result; - - return $result; -} - // // Category Checklists // diff --git a/wp-includes/general-template.php b/wp-includes/general-template.php index d72e90d76..c5d9e969e 100644 --- a/wp-includes/general-template.php +++ b/wp-includes/general-template.php @@ -2203,4 +2203,78 @@ function get_the_generator( $type = '' ) { return apply_filters( "get_the_generator_{$type}", $gen, $type ); } +/** + * Outputs the html checked attribute. + * + * Compares the first two arguments and if identical marks as checked + * + * @since 1.0 + * + * @param mixed $checked One of the values to compare + * @param mixed $current (true) The other value to compare if not just true + * @param bool $echo Whether to echo or just return the string + * @return string html attribute or empty string + */ +function checked( $checked, $current = true, $echo = true ) { + return __checked_selected_helper( $checked, $current, $echo, 'checked' ); +} + +/** + * Outputs the html selected attribute. + * + * Compares the first two arguments and if identical marks as selected + * + * @since 1.0 + * + * @param mixed selected One of the values to compare + * @param mixed $current (true) The other value to compare if not just true + * @param bool $echo Whether to echo or just return the string + * @return string html attribute or empty string + */ +function selected( $selected, $current = true, $echo = true ) { + return __checked_selected_helper( $selected, $current, $echo, 'selected' ); +} + +/** + * Outputs the html disabled attribute. + * + * Compares the first two arguments and if identical marks as disabled + * + * @since 3.0.0 + * + * @param mixed $disabled One of the values to compare + * @param mixed $current (true) The other value to compare if not just true + * @param bool $echo Whether to echo or just return the string + * @return string html attribute or empty string + */ +function disabled( $disabled, $current = true, $echo = true ) { + return __checked_selected_helper( $disabled, $current, $echo, 'disabled' ); +} + +/** + * Private helper function for checked, selected, and disabled. + * + * Compares the first two arguments and if identical marks as $type + * + * @since 2.8 + * @access private + * + * @param any $helper One of the values to compare + * @param any $current (true) The other value to compare if not just true + * @param bool $echo Whether to echo or just return the string + * @param string $type The type of checked|selected|disabled we are doing + * @return string html attribute or empty string + */ +function __checked_selected_helper( $helper, $current, $echo, $type ) { + if ( (string) $helper === (string) $current ) + $result = " $type='$type'"; + else + $result = ''; + + if ( $echo ) + echo $result; + + return $result; +} + ?>