Make WordPress Core

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#29056 closed defect (bug) (wontfix)

Media Grid: Support media_row_actions

Reported by: pavelevap's profile pavelevap Owned by:
Milestone: Priority: low
Severity: normal Version: 4.0
Component: Media Keywords: dev-feedback 2nd-opinion
Focuses: ui, javascript, administration Cc:

Description

When using plugins like Regenerate Thumbnails, it is not possible to use it in Grid mode, because it uses filter media_row_action, which is not displayed anywhere in Grid (or modal).

Attachments (1)

29056.diff (6.7 KB) - added by ericlewis 11 years ago.

Download all attachments as: .zip

Change History (13)

This ticket was mentioned in IRC in #wordpress-dev by ocean90. View the logs.


11 years ago

#2 @ocean90
11 years ago

  • Component changed from General to Media
  • Focuses administration added
  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to 4.0
  • Priority changed from normal to low
  • Summary changed from Media Grid: Support media_row_action to Media Grid: Support media_row_actions

helen:

maybe we can put those in the modal or something, we have edit more/view attachment page links there

#3 @nosilver4u
11 years ago

Would be nice to have this for EWWW Image Optimizer, and most of the other image optimizer plugins utilize similar actions (WP Smush.it, CW Image Optimizer, and Kraken.io). I suspect there are others (like Cloudinary) that could benefit from this too.

@ericlewis
11 years ago

#4 @ericlewis
11 years ago

  • Focuses ui javascript added
  • Keywords dev-feedback 2nd-opinion added; needs-patch removed

In attachment:29056.diff, move all row actions into the Edit Attachment modal sidebar. This doesn't introduce support for media_row_actions.

As to the real point of this ticket, supporting media_row_actions, @helen and I spoke today about whether we should be supporting row actions here, she is dubious of doing - she can put her thought process here.

We support attachment_field_to_edit, and can employ a similar approach for compatibility here, even if it's awkward to build HTML and toss it on the attachment model.

#5 follow-up: @helen
11 years ago

  • Milestone 4.0 deleted
  • Resolution set to wontfix
  • Status changed from new to closed

As noted, I've landed on not supporting this action in the context of the details modal, and the grid does not lend itself to supporting it, either. It's not a table, and therefore not a "row". You also do not get $post context in the JS template like you do in PHP, thus making it necessary to do another compat workaround. I would suggest using attachment_fields_to_edit instead, which would also make it available in the original media modal. If we need to add/check more context for where/when to display stuff added in that hook, then we can open a new ticket for that.

#6 in reply to: ↑ 5 ; follow-up: @swift
11 years ago

Just to follow-up and confirm here - there is no way for plugins to inject content (action links/buttons) into the sidebar of the Attachment Details modal that comes up when an image is clicked in the new grid view?

If so, that's really unfortunate as there is no easy way to add actions to media in grid view because they can't show up anywhere. This is an important feature that should be implemented. I can certainly see how it may get complicated to port support from media_row_actions, but at the least, there should be a new action hook here to implement this functionality.

Replying to helen:

As noted, I've landed on not supporting this action in the context of the details modal, and the grid does not lend itself to supporting it, either. It's not a table, and therefore not a "row". You also do not get $post context in the JS template like you do in PHP, thus making it necessary to do another compat workaround. I would suggest using attachment_fields_to_edit instead, which would also make it available in the original media modal. If we need to add/check more context for where/when to display stuff added in that hook, then we can open a new ticket for that.

#7 in reply to: ↑ 6 ; follow-up: @helen
11 years ago

Replying to swift:

helen:
I would suggest using attachment_fields_to_edit instead, which would also make it available in the original media modal. If we need to add/check more context for where/when to display stuff added in that hook, then we can open a new ticket for that.

#8 in reply to: ↑ 7 @swift
11 years ago

Replying to helen:

OK, I've done a more thorough search online and through the code and I think I finally figured out how this can work. Part of the issue is that the documentation is really weak around this in the Codex so it's not very clear how to do it - maybe that can be expanded on to help future people with the same question.

#9 follow-up: @helgatheviking
11 years ago

There are actions in place inside the modal:

"View attachment page | Edit more details | Delete Permanently"

I don't understand why it is a crazy idea to be able to add another? Maybe they aren't "row" actions any more, but they are still actions to be performed on the current attachment.

"View attachment page | Edit more details | Delete Permanently | Add Guacamole"

They appear to be coming from media-template.php (please correct me if I am wrong) and that already has at least one apply_filters() in it, so why can't the attachment actions be run through a filter too?

attachment_fields_to_edit doesn't seem to be applicable to the modal either and the fields all seem hard-coded. @swift if you've figured out how to add actions/fields to the modal, would you mind sharing?

#10 in reply to: ↑ 9 ; follow-ups: @swift
11 years ago

I did manage to get it working, see below. Basically you have to create a "form field" but the set the 'input' = 'html' and put whatever HTML code you want into the html value.

It works, but I agree, it would make more sense to have an action filter here - that also avoids having to worry about the show_in_edit flag.

Good luck

	public function addMediaModalAction($form_fields, $post) {
		$form_fields["my_action"] = array(
		  'label' => __(""),
		  'input' => "html",
		  'html' => '<a class="thickbox button" title="Do Something" href="' . admin_url( 'admin-ajax.php' ) . '?action=my_action">' . __('Label','plugin') . '</a>',
		  'show_in_edit' => false,
		);
		return $form_fields;
	}
	
	add_action( 'attachment_fields_to_edit', array($this, 'addMediaModalAction'), 10, 2 );

Replying to helgatheviking:

There are actions in place inside the modal:

"View attachment page | Edit more details | Delete Permanently"

I don't understand why it is a crazy idea to be able to add another? Maybe they aren't "row" actions any more, but they are still actions to be performed on the current attachment.

"View attachment page | Edit more details | Delete Permanently | Add Guacamole"

They appear to be coming from media-template.php (please correct me if I am wrong) and that already has at least one apply_filters() in it, so why can't the attachment actions be run through a filter too?

attachment_fields_to_edit doesn't seem to be applicable to the modal either and the fields all seem hard-coded. @swift if you've figured out how to add actions/fields to the modal, would you mind sharing?

#11 in reply to: ↑ 10 @galeroy
11 years ago

@swift - I'd like to try implementing your work-around. I'm a junior level programmer, however, and am wondering if you'd be kind enough to provide a few more details?

Would it be possible to explain:

+ which file your code would be placed in? ( media-template.php ?)

+ which section or line number the above code would be place in?

+ an example of the corresponding html? I'm not exactly sure how to - or if I need to - modify this line in your example - (to correspond to my environment):
$form_fields["my_action"] = array('label' => __(""),

Thanks a lot.

Replying to swift:

I did manage to get it working, see below. Basically you have to create a "form field" but the set the 'input' = 'html' and put whatever HTML code you want into the html value.

It works, but I agree, it would make more sense to have an action filter here - that also avoids having to worry about the show_in_edit flag.

Good luck

	public function addMediaModalAction($form_fields, $post) {
		$form_fields["my_action"] = array(
		  'label' => __(""),
		  'input' => "html",
		  'html' => '<a class="thickbox button" title="Do Something" href="' . admin_url( 'admin-ajax.php' ) . '?action=my_action">' . __('Label','plugin') . '</a>',
		  'show_in_edit' => false,
		);
		return $form_fields;
	}
	
	add_action( 'attachment_fields_to_edit', array($this, 'addMediaModalAction'), 10, 2 );

Replying to helgatheviking:

There are actions in place inside the modal:

"View attachment page | Edit more details | Delete Permanently"

I don't understand why it is a crazy idea to be able to add another? Maybe they aren't "row" actions any more, but they are still actions to be performed on the current attachment.

"View attachment page | Edit more details | Delete Permanently | Add Guacamole"

They appear to be coming from media-template.php (please correct me if I am wrong) and that already has at least one apply_filters() in it, so why can't the attachment actions be run through a filter too?

attachment_fields_to_edit doesn't seem to be applicable to the modal either and the fields all seem hard-coded. @swift if you've figured out how to add actions/fields to the modal, would you mind sharing?

#12 in reply to: ↑ 10 @galeroy
11 years ago

Please disregard my previous questions. Thanks/sorry. I was able to figure it out.

Replying to swift:

I did manage to get it working, see below. Basically you have to create a "form field" but the set the 'input' = 'html' and put whatever HTML code you want into the html value.

It works, but I agree, it would make more sense to have an action filter here - that also avoids having to worry about the show_in_edit flag.

Good luck

	public function addMediaModalAction($form_fields, $post) {
		$form_fields["my_action"] = array(
		  'label' => __(""),
		  'input' => "html",
		  'html' => '<a class="thickbox button" title="Do Something" href="' . admin_url( 'admin-ajax.php' ) . '?action=my_action">' . __('Label','plugin') . '</a>',
		  'show_in_edit' => false,
		);
		return $form_fields;
	}
	
	add_action( 'attachment_fields_to_edit', array($this, 'addMediaModalAction'), 10, 2 );

Replying to helgatheviking:

There are actions in place inside the modal:

"View attachment page | Edit more details | Delete Permanently"

I don't understand why it is a crazy idea to be able to add another? Maybe they aren't "row" actions any more, but they are still actions to be performed on the current attachment.

"View attachment page | Edit more details | Delete Permanently | Add Guacamole"

They appear to be coming from media-template.php (please correct me if I am wrong) and that already has at least one apply_filters() in it, so why can't the attachment actions be run through a filter too?

attachment_fields_to_edit doesn't seem to be applicable to the modal either and the fields all seem hard-coded. @swift if you've figured out how to add actions/fields to the modal, would you mind sharing?

Note: See TracTickets for help on using tickets.