WordPress.org

Make WordPress Core

#20819 closed defect (bug) (fixed)

Restrict Media Library header image chooser to only images (no audio, video, etc)

Reported by: georgestephanis Owned by: ryan
Milestone: 3.4 Priority: normal
Severity: normal Version: 3.4
Component: Appearance Keywords: has-patch commit
Focuses: Cc:

Description

For 'Choose an image from your media library' users can select other media such as Audio or Video items

http://cloud.stephanis.info/3l0z1g2q003T4530230o

The URL query string preselects the 'Image' file type, but others can be 'Set as header'

Attachments (5)

20819.patch (622 bytes) - added by SergeyBiryukov 23 months ago.
20819.2.patch (1.6 KB) - added by SergeyBiryukov 23 months ago.
20819.3.patch (1.4 KB) - added by SergeyBiryukov 23 months ago.
20819.4.patch (2.8 KB) - added by SergeyBiryukov 23 months ago.
20819.5.patch (5.0 KB) - added by SergeyBiryukov 23 months ago.

Download all attachments as: .zip

Change History (16)

comment:1 SergeyBiryukov23 months ago

  • Component changed from General to Appearance
  • Keywords needs-patch added; 2nd-opinion removed
  • Milestone changed from Awaiting Review to 3.4

Setting an audio file as header obviously results in a broken image when cropping and a warning:

Warning: imagecreatefromstring() [function.imagecreatefromstring]: Data is not in a recognized format in wp-includes\media.php on line 258

Image could not be processed. Please go back and try again.

SergeyBiryukov23 months ago

comment:2 SergeyBiryukov23 months ago

  • Keywords has-patch added; needs-patch removed

SergeyBiryukov23 months ago

comment:3 SergeyBiryukov23 months ago

20819.2.patch also adds PHPDocs for the functions introduced in #19840.

comment:4 follow-ups: ocean9023 months ago

We could also use one of our magic functions: __return_empty_array().

SergeyBiryukov23 months ago

comment:5 in reply to: ↑ 4 SergeyBiryukov23 months ago

Replying to ocean90:

We could also use one of our magic functions: __return_empty_array().

Indeed, thanks.

comment:6 nacin23 months ago

  • Keywords commit added

Looks good.

comment:7 ryan23 months ago

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

In [20982]:

Don't show mime type filter links when choosing an image header from the media library. Props SergeyBiryukov, georgestephanis. fixes #20819

SergeyBiryukov23 months ago

comment:8 in reply to: ↑ 4 SergeyBiryukov23 months ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

Replying to ocean90:

We could also use one of our magic functions: __return_empty_array().

Actually, no. That hides the file type links when calling the uploader window on Edit Post screen as well.

We need to check for context, like filter_upload_tabs() and attachment_fields_to_edit() do:
http://core.trac.wordpress.org/browser/trunk/wp-admin/custom-header.php?rev=20982#L969

20819.4.patch fixes the issue and brings the same changes to custom-background.php.

comment:9 nacin23 months ago

Can we simply do:

if ( isset( $_REQUEST['context'] ) && $_REQUEST['context'] == 'custom-background' )
    add_filter( 'media_upload_mime_type_links', '__return_empty_array' );

comment:10 SergeyBiryukov23 months ago

Yes, then we can remove the individual checks from attachment_fields_to_edit() and filter_upload_tabs() as well. Done in 20819.5.patch

SergeyBiryukov23 months ago

comment:11 ryan23 months ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In [21009]:

Check context before adding media upload filters. Props SergeyBiryukov. fixes #20819

Note: See TracTickets for help on using tickets.