Make WordPress Core

Opened 14 years ago

Last modified 3 weeks ago

#20810 new enhancement

Add disable arg or attributes arg to wp_dropdown_categories() & wp_dropdown_pages()

Reported by: wpsmith Owned by:
Priority: normal Milestone:
Component: Posts, Post Types Version: 2.1
Severity: normal Keywords: has-patch
Cc: Focuses: template

Description

It would be beneficial to be able to add disabled="disabled" attribute to the select tag or add multiple attributes to the select tag.

Related: #20156, #20167

Attachments (4)

wp_dropdown_categories_disabled_opt.patch (1.1 KB ) - added by wpsmith 14 years ago.
Disabled arg for wp_dropdown_categories()
wp_dropdown_categories_attr_opt.patch (1.2 KB ) - added by wpsmith 14 years ago.
Extra attributes for wp_dropdown_categories()
wp_dropdown_pages_disabled_opt.patch (1.0 KB ) - added by wpsmith 14 years ago.
Disabled arg for wp_dropdown_pages()
wp_dropdown_pages_attr_opt.patch (1.1 KB ) - added by wpsmith 14 years ago.
Extra attributes for wp_dropdown_pages()

Download all attachments as: .zip

Change History (12)

@wpsmith
14 years ago

Disabled arg for wp_dropdown_categories()

@wpsmith
14 years ago

Extra attributes for wp_dropdown_categories()

@wpsmith
14 years ago

Disabled arg for wp_dropdown_pages()

@wpsmith
14 years ago

Extra attributes for wp_dropdown_pages()

#1 @prionkor
14 years ago

+1 we need it on all dropdown functions.

An array of attribute could be passed. Like:

$args = array(

'attrs' = array(

'multiple' => 'multiple',
'disable' => 'disabled'

)

)

It will allow users to add extra attribute like classes or any other html 5 attributes on the dropdown.

Last edited 14 years ago by prionkor (previous) (diff)

#2 @prionkor
14 years ago

  • Cc sisir@… added

#3 @nacin
13 years ago

  • Component TemplatePosts, Post Types
  • Focuses template added

#4 @lumpysimon
11 years ago

+1 for this, I'm having to use jQuery at the moment to achieve this.

#5 @johnbillion
11 years ago

  • Keywords has-patch needs-refresh added
  • Milestone Awaiting ReviewFuture Release
  • Version2.1

Patch needs a refresh.

#6 @garrett-eclipse
10 years ago

+1
Currently utilizing jQuery or rebuilding the $output through the wp_dropdown_cats filter.

This ticket was mentioned in PR #12145 on WordPress/wordpress-develop by @sainathpoojary.


3 months ago
#7

  • Keywords needs-refresh removed

This PR adds a disabled boolean argument to both wp_dropdown_categories() and wp_dropdown_pages(). When set to true, the generated <select> dropdowns are rendered with the HTML5 disabled attribute (<select disabled>).

https://github.com/user-attachments/assets/a8cf79a3-a027-44c1-ae02-00d3b3f48811

Trac ticket: #20810

#8 @softglaze
3 weeks ago

Test Report

Tested PR #12145, applied to ticket/20810 at a554ae14ae.

Environment

WordPress: 7.2-alpha-20260820.014058
PHP: 8.3
Serving: build/ (a build has run)
Multisite: no, and not available in this app
Standing on: ticket/20810
Trunk commit: a554ae14ae
Ticket: #20810
Applied: PR #12145, onto a554ae14ae

Steps taken
Created a fresh wordpress-develop site with the toolkit and let it install and build, then started the dev server and recorded what the two functions emit on unpatched trunk.

Applied PR #12145 to that site, ran npm run build so the PHP changes reached the tree the server mounts, and started the server again.

Called both functions through an mu-plugin on the running site rather than reading the diff: wp_dropdown_categories( array( 'echo' => 0, 'disabled' => true, 'hide_empty' => 0 ) ) and wp_dropdown_pages( array( 'echo' => 0, 'disabled' => true ) ), and the same two calls again with the argument left out.

Expected
With disabled => true the generated <select> should carry the HTML5 disabled attribute, and without the argument it should be unchanged from before.

Actual
Before the patch, on trunk, the argument was ignored by both functions:

wp_dropdown_categories <select name='cat' id='cat' class='postform'>
wp_dropdown_pages <select name='page_id' id='page_id'>

After applying the patch and rebuilding, both honour it:

wp_dropdown_categories <select disabled name='cat' id='cat' class='postform'>
wp_dropdown_pages <select name='page_id' id='page_id' disabled>

And with the argument left out, neither emits the attribute, so nothing changes for existing callers:

wp_dropdown_categories <select name='cat' id='cat' class='postform'>
wp_dropdown_pages <select name='page_id' id='page_id'>

Result: Works as described.

Notes
Tested on Windows 11 with the site served from build/ by WordPress Playground, single site.

The patch applied cleanly to a checkout of today's trunk, all four files, no fuzz.

I did not run the PHPUnit tests the PR adds; this is a behavioural check of the two functions on a running site.

Reported by @softglaze, using the WordPress Contributor Toolkit.

Note: See TracTickets for help on using tickets.