Make WordPress Core

Opened 14 months ago

Closed 13 months ago

Last modified 7 months ago

#40589 closed defect (bug) (fixed)

Media: Replace button enabled when no media item selected

Reported by: timmydcrawford Owned by: adamsilverstein
Milestone: 4.9 Priority: normal
Severity: normal Version:
Component: Media Keywords: has-patch has-screenshots commit
Focuses: javascript Cc:


Initially discovered while working on the new Media Widgets for the customizer: https://github.com/xwp/wp-core-media-widgets/issues/102

Steps to Recreate:

  • Open up a post in the editor
  • Insert an image via the "Add Media" button
  • Once the image is displayed in the editor, click the pencil icon to open the image editor modal
  • Click the "Replace" button below the image
  • Note the current image is selected in the replace view, and the "Replace" button is enabled
  • Un-select the current image so no image is selected, note the "Replace" button is still enabled
  • Click the "Replace" button, and an error will be thrown ( see screenshot )

Some logic could be added to prevent the exception, but ideally it seems like the "Replace" button should be disabled when there is no active selection.

Attachments (4)

replace-button-error.png (61.5 KB) - added by timmydcrawford 14 months ago.
Screencast 2017-04-28 15:11:27.mp4 (4.9 MB) - added by subrataemfluence 14 months ago.
Screen cast of step by step operation
40589.diff (1.4 KB) - added by psiico 14 months ago.
40589.2.diff (429 bytes) - added by adamsilverstein 14 months ago.

Change History (15)

14 months ago

Screen cast of step by step operation

#1 @subrataemfluence
14 months ago

Please disregard added screen cast. I missed the "trunk". Sorry for this.

14 months ago


#2 @psiico
14 months ago

  • Keywords has-patch needs-testing added

#3 @psiico
14 months ago

  • Keywords has-screenshots added


#4 @adamsilverstein
14 months ago


Thanks for your work and patch here, and for providing the screencast.

We don't need to track selection in the click callback because the toolbar component already supports a section: required attribute that produces the desired behavior.

40589.2.diff is an alternate approach that uses that feature.

Can you please test? Thanks.

This ticket was mentioned in Slack in #core by timmyc. View the logs.

14 months ago

#6 @timmydcrawford
14 months ago

40589.2.diff is testing out well for me - the button is disabled now until an item is selected.

#7 @ocean90
13 months ago

  • Milestone changed from Awaiting Review to Future Release
  • Version trunk deleted

#8 @adamsilverstein
13 months ago

  • Keywords commit added; needs-testing removed

#9 @adamsilverstein
13 months ago

  • Owner set to adamsilverstein
  • Resolution set to fixed
  • Status changed from new to closed

In 40902:

Media: Disable the edit image->replace button when no item selected.

On the edit media screen, ensure that the 'replace' button is disabled until a media item is selected. Fix an issue where clicking the button with no item selected threw a JavaScript error and failed to work.

Props timmydcrawford, subrataemfluence, psiico.
Fixes #40589.

#10 @netweb
13 months ago

  • Milestone changed from Future Release to 4.9

#11 @wonderboymusic
7 months ago

#36453 was marked as a duplicate.

Note: See TracTickets for help on using tickets.