WordPress.org

Make WordPress Core

Opened 7 years ago

Last modified 3 months ago

#19278 new enhancement

Allow WP_List_Table ::get_bulk_items() to receive a nested array and output optgroups

Reported by: goldenapples Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Administration Keywords: has-patch dev-feedback needs-testing
Focuses: Cc:

Description

I'm just putting this out there as a possible enhancement to the WP_List_Table... would like feedback as to whether anyone else would find it helpful. If so, I'm more than happy to write up a patch for this.

I think it may be useful to be able to pass a nested array to WP_List_Table::get_bulk_actions() and have it output the options within the subarray in an <optgroup>. My specific use case is in applying meta fields to a custom table. I would like to be able to define something like this in my get_bulk_items function:

function get_bulk_actions() {
	$actions = array(
		'delete' => 'Delete',
		'outofstock' => 'Mark out of stock',
		'applytags' => array(
			'label' => 'Apply tags to products',
			'actions' => array(
				'featured' => 'Featured',
				'sale' => 'On Sale'
				)
			)
		);
	return $actions;
}

and have the output look something like this:

<select name="action">
	<option value='-1' selected='selected'>Bulk Actions</option>

	<option value='delete'>Delete</option>
	<option value='outofstock'>Mark out of stock</option>
	<optgroup label="Apply tags to products">
		<option value='feature'>Featured</option>
		<option value='sale'>On sale</option>
	</optgroup>
</select>

A very minor feature, and possibly too fringe of a use case to bother with. But I've worked on a couple projects now where being able to specify markup like that would have made that screen more user-friendly. Any thoughts?

Attachments (1)

19278.diff (1.2 KB) - added by mattkeys 3 months ago.

Download all attachments as: .zip

Change History (7)

#1 @goldenapples
7 years ago

  • Component changed from General to Administration

#2 @scribu
7 years ago

  • Type changed from feature request to enhancement

Well, officially, you're not even able to add new bulk actions. #16031

It's unlikely this will get any attention until the above is handled.

#3 @goldenapples
7 years ago

Ha! I didn't even see that ticket, and I was wondering why I had to manually trigger $this->process_bulk_actions() in order to get them to work. Thanks... I'll take a look at that ticket.

#4 @chriscct7
4 years ago

  • Keywords needs-patch added

#5 @chriscct7
3 years ago

  • Severity changed from minor to normal

@mattkeys
3 months ago

#6 @mattkeys
3 months ago

  • Keywords has-patch dev-feedback needs-testing added; needs-patch removed

Going to play necromancer here a bit and submit a patch for this. I work with WP List Table often and I know many other developers use it in their plugins/themes (despite the codex warning). Optgroup's would be a nice way to organize bulk actions.

The patch I submitted just checks if the current value from the existing bulk actions foreach is an array. If it is, the key becomes the optgroup label, and a new foreach is used to loop over the optgroup's children. Otherwise it proceeds as usual. I also modified a couple variable names to semantic reasons.

I would love to hear back from others about any unforeseen impacts that this change might have.

Note: See TracTickets for help on using tickets.