[wp-trac] [WordPress Trac] #35268: Allow comparison of multiple values for checked(), selected(), and disabled()
WordPress Trac
noreply at wordpress.org
Wed Dec 30 19:41:36 UTC 2015
#35268: Allow comparison of multiple values for checked(), selected(), and
disabled()
-------------------------+-----------------------------
Reporter: kingkool68 | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version:
Severity: normal | Keywords:
Focuses: |
-------------------------+-----------------------------
The aim of this ticket is to make these convenience functions a little
more convenient by allowing the comparison of multiple values for
{{{checked()}}}, {{{selected()}}}, {{{disabled()}}}. Take the following
use case of a form asking you to select days of the week:
Testing the value with {{{if()}}}:
{{{#!php
<?php
$days = array( 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday',
'Saturday', 'Sunday', );
$selected_days = array( 'Monday', 'Wednesday', 'Friday', );
foreach ( $days as $day ) { ?>
<label><input type="checkbox" name="days[]" value="<?php echo
esc_attr( $day ); ?>" <?php if ( in_array( $day, $selected_days ) ) echo
'checked="checked"'; ?>><?php echo $day; ?></label>
<?php } ?>
}}}
Using {{{checked()}}} instead:
{{{#!php
<?php
$days = array( 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday',
'Saturday', 'Sunday', );
$selected_days = array( 'Monday', 'Wednesday', 'Friday', );
foreach ( $days as $day ) { ?>
<label><input type="checkbox" name="days[]" value="<?php echo
esc_attr( $day ); ?>" <?php checked( $selected_days, $day ); ?>><?php echo
$day; ?></label>
<?php } ?>
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/35268>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list