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
This commit is contained in:
parent
2486cc70f7
commit
1f422200ee
|
@ -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
|
||||
//
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
Loading…
Reference in New Issue