ClassicPress icon indicating copy to clipboard operation
ClassicPress copied to clipboard

Multiple select support for wp_dropdown_categories

Open smileBeda opened this issue 4 years ago • 8 comments

Description

Adds a new argument to the $args array for wp_dropdown_categories, allowing to pass either empty string or multiple.

If left empty, the select defaults to a single select, if multiple is passed the Select will allow for multiple selection and pass an [] to the name attribute value as well.

See also https://forums.classicpress.net/t/update-wp-dropdown-categories-to-allow-for-multiple-selection/

Motivation and context

The requirement to produce a Categories or else Custom taxonomy Dropdown with multiselect support has been around for years (google search will show what I mean). I use to replace said function in my plugins with this (and other) amendments and thus I think it is time to have this tiny, but powerful change in core.

How has this been tested?

This was tested on several installs of mine (I use to replace said function with a custom one). Also tested this particular commit on my local install Example usage: wp_dropdown_categories( array('multiple' => 'multiple') );

Screenshots

Before

Screenshot 2021-09-10 at 11 06 25

After

Screenshot 2021-09-10 at 11 06 37

NOTE: This now also allows for Select2 MultiSelects, of course (the developer just needs to instantiate S2 on the select input produced...)

Types of changes

  • New Feature (backwards compatible and non-disturbing)

smileBeda avatar Sep 10 '21 04:09 smileBeda

This pull request has been mentioned on ClassicPress Forums. There might be relevant details there:

https://forums.classicpress.net/t/update-wp-dropdown-categories-to-allow-for-multiple-selection/3555/5

ClassyBot avatar Sep 10 '21 04:09 ClassyBot

This pull request has been mentioned on ClassicPress Forums. There might be relevant details there:

https://forums.classicpress.net/t/update-wp-dropdown-categories-to-allow-for-multiple-selection/3555/6

ClassyBot avatar Sep 10 '21 04:09 ClassyBot

Needs testing (including automated tests) and revision (changing multiple to a boolean value) similar to #791 .

nylen avatar Nov 22 '21 01:11 nylen

Pushed 2 commits that:

  • Fix poorly styled @since version (remove CP- prefix, but did NOT update version!)
  • Transform new argument to boolean
  • Add validation for new (and existing) boolean arguments
  • Update logic to print multiple or nothing depending on new argument value passed to wp_dropdown_categories

Tested locally for functionality as well.

smileBeda avatar Nov 22 '21 09:11 smileBeda

This shouldn't be closed.

smileBeda avatar Jun 28 '22 10:06 smileBeda

I suspect this auto closed due to fork where PR originated being deleted.

mattyrob avatar Jun 28 '22 10:06 mattyrob

Ah, ups - I guess that would have been me then when I cleaned up old CP repos lying around in my repo.

But I've seen other such things getting "reopened", so I guess this can be done here too?

smileBeda avatar Jun 28 '22 11:06 smileBeda

Unfortunately, the branch is closed. Needs re-opening.

bahiirwa avatar Sep 19 '22 08:09 bahiirwa

As per latest decisions it seems CP will be re-forked, re-synced with WP, so I think the changes of this PR (and all others I committed in the past improving similar functions) can/should be discarded, since they add new features not in WP and thus would just complicate the keeping-in-sync process.

smileBeda avatar Jan 06 '23 03:01 smileBeda