WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#8481 closed enhancement (wontfix)

Improved version of checked() in template.php

Reported by: chmac Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: General Keywords:
Focuses: Cc:

Description

function psu_checked($checked, $current) {
	if ( (is_array($current) && in_array($checked, $current)) || $checked == $current)
		echo ' checked="checked"';
}

instead of

function checked( $checked, $current) {
	if ( $checked == $current)
		echo ' checked="checked"';
}

Attachments (2)

checked-upgrade.patch (456 bytes) - added by chmac 5 years ago.
checked-selected-helper-upgrade.patch (2.4 KB) - added by chmac 5 years ago.
New patch against the new checked_selected_helper() function

Download all attachments as: .zip

Change History (11)

chmac5 years ago

comment:1 chmac5 years ago

This function allows for an array of checked values to be passed which is useful in repetitive functions where an array of values are checked, but the array is not in any particular order.

comment:2 janeforshort5 years ago

  • Keywords has-patch added

comment:3 Denis-de-Bernardy5 years ago

  • Keywords needs-patch added; has-patch removed
  • Milestone changed from 2.8 to Future Release

patch needs a refresh against trunk

comment:4 chmac5 years ago

  • Keywords has-patch added; needs-patch removed
  • Milestone changed from Future Release to 2.8

Ok, patch against the new code in trunk.

I've switched the milestone back to 2.8, not sure if I'm supposed to change it or not, but figured I'd give it a whirl. :-)

comment:5 Denis-de-Bernardy5 years ago

I considered submitting an updated patch along those lines before bumping to Future.

Possible issues I foresaw:

  • Should $current and $test be documented as accepting anything?
  • If so, and if the is_array() check is not first, the $current == $test may end up being erroneously true with the new usage. Probably irrelevant, but it did have me thinking twice.

Just FYI...

+1 to the patch with updated phpdoc (i.e. accepts numeric/bool/string, different behavior with array).

comment:6 chmac5 years ago

I've updated the patch, amended the phpdocs and switched the order around.

I think it makes more sense to say if (is_array($selected)) because that way you can have an array of selected values and mark each one as checked / selected. It probably doesn't make sense to mark multiple values selected but I'll leave that alone for now.

chmac5 years ago

New patch against the new checked_selected_helper() function

comment:7 Denis-de-Bernardy5 years ago

  • Keywords tested commit added

comment:8 westi5 years ago

  • Keywords has-patch tested commit removed
  • Milestone changed from 2.8 to Future Release

Not sure there is a big benefit in this.

Current patch doesn't work (hint $selected isn't defined).

Punting to Future release.

comment:9 Denis-de-Bernardy5 years ago

  • Milestone Future Release deleted
  • Resolution set to wontfix
  • Status changed from new to closed

let's close as wontfix, then, so as to trim the ticket list. it's a very minor enhancement, and can potentially lead to confusion.

Note: See TracTickets for help on using tickets.