WordPress.org

Make WordPress Core

Opened 11 months ago

Last modified 2 months 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: needs-patch
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

Change History (2)

#1 @Kelderic
11 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
2 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.

Note: See TracTickets for help on using tickets.