Enhance checked and selected as well as consolidating code. See #9032 props johnbillion for the idea.
git-svn-id: http://svn.automattic.com/wordpress/trunk@10662 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
b35b81f298
commit
6eb64d687b
|
@ -365,29 +365,58 @@ function link_cat_row( $category, $name_override = false ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@internal Missing Short Description}}
|
* Outputs the html checked attribute.
|
||||||
|
*
|
||||||
|
* Compares the first two arguments and if identical marks as checked
|
||||||
*
|
*
|
||||||
* @since unknown
|
* @since unknown
|
||||||
*
|
*
|
||||||
* @param unknown_type $checked
|
* @param any $checked One of the values to compare
|
||||||
* @param unknown_type $current
|
* @param any $current (true) The other value to compare if not just true
|
||||||
|
* @param bool $echo Whether or not to echo or just return the string
|
||||||
*/
|
*/
|
||||||
function checked( $checked, $current) {
|
function checked( $checked, $current = true, $echo = true) {
|
||||||
if ( $checked == $current)
|
return __checked_selected_helper( $checked, $current, $echo, 'checked' );
|
||||||
echo ' checked="checked"';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@internal Missing Short Description}}
|
* Outputs the html selected attribute.
|
||||||
|
*
|
||||||
|
* Compares the first two arguments and if identical marks as selected
|
||||||
*
|
*
|
||||||
* @since unknown
|
* @since unknown
|
||||||
*
|
*
|
||||||
* @param unknown_type $selected
|
* @param any $checked One of the values to compare
|
||||||
* @param unknown_type $current
|
* @param any $current (true) The other value to compare if not just true
|
||||||
|
* @param bool $echo Whether or not to echo or just return the string
|
||||||
*/
|
*/
|
||||||
function selected( $selected, $current) {
|
function selected( $selected, $current = true, $echo = true) {
|
||||||
if ( $selected == $current)
|
return __checked_selected_helper( $selected, $current, $echo, 'selected' );
|
||||||
echo ' selected="selected"';
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Private helper function for checked and selected.
|
||||||
|
*
|
||||||
|
* Compares the first two arguments and if identical marks as $type
|
||||||
|
*
|
||||||
|
* @since unknown
|
||||||
|
* @access private
|
||||||
|
*
|
||||||
|
* @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 or not 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 ( $helper == $current)
|
||||||
|
$result = " $type='$type'";
|
||||||
|
else
|
||||||
|
$result = '';
|
||||||
|
|
||||||
|
if ($echo)
|
||||||
|
echo $result;
|
||||||
|
|
||||||
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
Loading…
Reference in New Issue