Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple select support for wp_dropdown_categories #790

Closed
wants to merge 3 commits into from
Closed

Multiple select support for wp_dropdown_categories #790

wants to merge 3 commits into from

Conversation

smileBeda
Copy link
Contributor

@smileBeda smileBeda commented Sep 10, 2021

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)

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.

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') );`
@ClassyBot
Copy link
Contributor

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
Copy link
Contributor

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

@striebwj striebwj added this to the 1.4.0-rc1 milestone Sep 10, 2021
@bahiirwa bahiirwa added the type: feature request New feature or request label Sep 11, 2021
@nylen nylen modified the milestones: 1.4.0-rc1, 1.5.0-rc1 Nov 22, 2021
@nylen
Copy link
Contributor

nylen commented Nov 22, 2021

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

- Changes Version @SInCE annotation to not use `CP-` prefix
- Changes new attribute to be boolean instead of string
- Adds boolean validation
- Changes logic to display `multiple` HTML 5 attribute based on boolean input
... when multiple is false, pass empty string.
@smileBeda
Copy link
Contributor Author

smileBeda commented Nov 22, 2021

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
Copy link
Contributor Author

This shouldn't be closed.

@mattyrob
Copy link
Collaborator

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

@smileBeda
Copy link
Contributor Author

smileBeda commented Jun 28, 2022

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?

@bahiirwa bahiirwa reopened this Jun 29, 2022
@bahiirwa
Copy link
Collaborator

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

@bahiirwa bahiirwa added the status: needs refresh Merge Conflicts detected by Github. Needs a refresh from develop. label Sep 19, 2022
@mattyrob mattyrob removed this from the 1.5.0-rc1 milestone Sep 21, 2022
@smileBeda
Copy link
Contributor Author

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 smileBeda closed this Jan 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs refresh Merge Conflicts detected by Github. Needs a refresh from develop. type: feature request New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants