[wp-hackers] Ability to compare arrays in checked() function

Sudar Muthu sudar at sudarmuthu.com
Thu Aug 6 12:24:21 UTC 2009


Matt,

Your approach is good, it didn't strike me before. :)

But I also feel that if we add the condition to check for arrays into the
function, it might help us to save some keystokes while creating forms.

I am still not able to decide which approach will be better though.

With Regards,
Sudar

http://SudarMuthu.com
http://twitter.com/sudarmuthu


On Thu, Aug 6, 2009 at 17:48, Matt Martz <matt at sivel.net> wrote:

> On Thu, Aug 6, 2009 at 8:10 AM, Sudar Muthu<sudar at sudarmuthu.com> wrote:
> > Hi all,
> >
> > The checked() function (present in wp-admin/includes/template.php) checks
> > whether two parameters passed to it are equal and then outputs
> > checked='checked', which can be used in forms having checkboxes or radio
> > buttons.
> >
> > Sometimes (particularly for checkboxes), we might need to check for
> multiple
> > values. So I am proposing a change to the checked() function.
> >
> > It can first check whether the default value is an array and if yes, it
> can
> > return checked='checked' if the current value is present in the default
> > array.
> >
> > I have created a new ticket and have attached a patch with this change.<
> > http://core.trac.wordpress.org/ticket/10556>
> >
> > Do let me know what you guys think about it.
>
>
> I have always used:
>
> <?php checked(true, in_array('needle', $options['haystack'])); ?>
>
> Seems to work fine and is pretty easy.
>
> --
> Matt Martz
> matt at sivel.net
> http://sivel.net/
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list