[wp-trac] [WordPress Trac] #22409: add multiple selected options support to selected() function
WordPress Trac
noreply at wordpress.org
Sat Nov 10 23:31:58 UTC 2012
#22409: add multiple selected options support to selected() function
-----------------------------+-------------------------
Reporter: bitacre | Type: enhancement
Status: new | Priority: normal
Milestone: Awaiting Review | Component: Validation
Version: 3.4.2 | Severity: minor
Keywords: |
-----------------------------+-------------------------
The current {{{selected()}}} function returns ''selected="selected"'' if
two strings match, but does not correctly handle arrays that result from
select options that have ''multiple="multiple"'' enabled (it just checks
the first item in the array by forcing a string type).
I suggest either adding correct handling of arrays or alternatively adding
a separate {{{multiselected()}}} function to handle this situation.
This could be accomplished by altering the current
{{{__checked_selected_helper()}}} function to this:
{{{
function __checked_selected_helper( $helper, $current, $echo, $type ) {
if( is_array( $helper ) && in_array( $current, $helper, true ) )
$result = " $type='$type'";
elseif ( (string) $helper === (string) $current )
$result = " $type='$type'";
else
$result = '';
if ( $echo )
echo $result;
return $result;
}
}}}
I've just added the first 2 lines and changed the first {{{if}}} to an
{{{elseif}}}.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/22409>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list