WordPress.org

Make WordPress Core

Opened 13 months ago

Last modified 7 days ago

#44641 new defect (bug)

Customizing Button Text in Custom Media Manager Frame Doesn't Work Anymore

Reported by: Kelderic Owned by:
Milestone: 5.3 Priority: normal
Severity: normal Version: 4.9.7
Component: Media Keywords: has-patch needs-testing
Focuses: Cc:

Description

Summary

I have a plugin that calls up the Media Manager. I use the "gallery" state, and customize the main button text via the wp.media arguments. I've noticed a regression. The text in the primary button is no longer overridden by the arguments that I pass.

What I'm Doing (Code is simplified)

var file_frame = wp.media.frame = wp.media({
	frame: 'post',
	state: 'gallery',
	library : { type : 'image'},
	button: {text: 'Edit Image Order'},  // <----- LINE IN QUESTION
	multiple: true
});

file_frame.open();

What Should Happen

The text inside the primary button in the media manager modal should change from "Create a new Gallery" to "Edit Image Order".

https://imgur.com/faJevb7

What Actually Happens

The button ignores my arguments and retains its default text.

https://imgur.com/6gLdtLv

Attachments (2)

44641.diff (1.5 KB) - added by donmhico 7 days ago.
44641.2.diff (718 bytes) - added by donmhico 6 days ago.
A better fix than the first patch.

Download all attachments as: .zip

Change History (6)

#1 @Kelderic
13 months ago

I've found a workaround, btw. Before triggering the frame.open() function, I can set my own value into wp.media.view.l10n.insertIntoPost. Then reset that value after I open the frame.

// CUSTOMIZE THE MAIN BUTTON TEXT

var originalInsertIntoPost = wp.media.view.l10n.insertIntoPost;

wp.media.view.l10n.insertIntoPost = 'Select Icon';

// OPEN THE MODAL

frame.open();

// RESET THE MAIN BUTTON TEXT

wp.media.view.l10n.insertIntoPost = originalInsertIntoPost;

This works and doesn't affect any other frames, but it seems hacky.

#2 @joemcgill
4 months ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to 5.3

Hi @Kelderic,

Thanks for the report and for following up with your workaround. I agree that this is hacky and should be fixed. I was able to confirm that this is still an issue in WordPress 5.2-beta3, though I wasn't able to investigate why this is happening. I'm going to add this to the 5.3 milestone for further investigation.

#3 @Kelderic
3 weeks ago

I appreciate the response, @joemcgill, but I'm afraid that this has gotten lost in the hundreds of tickets assigned to 5.3.

@donmhico
7 days ago

#4 @donmhico
7 days ago

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

I've attached a patch, 44641.diff, but i'm not sure if this is what we want. On one hand, it does change the button label in the initial frame displayed. However, when you try to go to different frames by clicking the menu nav links in the left panel. The button labels of the new loaded frames will then revert to using the default label.

Now my question is, do we want the button label we set in the initialization of wp.media() -

var file_frame = wp.media.frame = wp.media({
	frame: 'post',
	state: 'gallery',
	library : { type : 'image'},
	button: {text: 'Edit Image Order'},  // <----- LINE IN QUESTION
	multiple: true
});

used in all of the frames? Or we just want it to be in the initial opened frame?

@donmhico
6 days ago

A better fix than the first patch.

Note: See TracTickets for help on using tickets.