WordPress.org

Make WordPress Core

Opened 12 months ago

Closed 25 hours ago

#43658 closed defect (bug) (fixed)

Media attachment filter drop-down mime types in grid mode is not properly filtered by available mime types

Reported by: itzmekhokan Owned by: adamsilverstein
Milestone: 5.2 Priority: normal
Severity: normal Version: 4.9.4
Component: Media Keywords: has-patch has-screenshots has-unit-tests commit
Focuses: Cc:

Description

In Gird mode media attachment filter is not properly filtered by available mime types, it shows all mime types by default via -

get_post_mime_types()

But in List mode its already filtered by checking

if ( ! wp_match_mime_types( $mime_type, $avail_post_mime_types ) ) {
	continue;
}

Attachments (7)

media-grid-attachment-filter-dropdown.png (330.0 KB) - added by itzmekhokan 12 months ago.
Grid view attachments filters drop-down
media-list-attachment-filter-dropdown.png (141.6 KB) - added by itzmekhokan 12 months ago.
List view attachment filters drop-down
43658.patch (1.3 KB) - added by itzmekhokan 12 months ago.
43658.1.patch (1.3 KB) - added by itzmekhokan 12 months ago.
Corrected coding standards by added whitespace
43658.diff (3.0 KB) - added by adamsilverstein 3 weeks ago.
43658.2.diff (9.3 KB) - added by adamsilverstein 3 weeks ago.
43658.3.diff (16.1 KB) - added by adamsilverstein 2 weeks ago.

Download all attachments as: .zip

Change History (20)

@itzmekhokan
12 months ago

Grid view attachments filters drop-down

@itzmekhokan
12 months ago

List view attachment filters drop-down

@itzmekhokan
12 months ago

#1 @itzmekhokan
12 months ago

  • Keywords has-patch added

#2 @itzmekhokan
12 months ago

  • Keywords has-screenshots added

#3 @adamsilverstein
12 months ago

  • Keywords needs-testing needs-unit-tests added
  • Milestone changed from Awaiting Review to 5.0
  • Owner set to adamsilverstein
  • Status changed from new to assigned

@itzmekhokan thanks for the bug report and patch!

Overall your patch looks good and I see the issue you are trying to resolve. Can you please provide the code snippet you are using to alter the dropdown for testing? Also, it would be nice to add a a unit test confirming the filter works as expected and changes the return from wp_enqueue_media.

One small coding standards correction, this line is missing some whitespace before/after brackets: unset($mimeTypes[$mime_type]);

@itzmekhokan
12 months ago

Corrected coding standards by added whitespace

#4 @itzmekhokan
12 months ago

I have tested the flow thoroughly with the 43658.1.patch and it is working properly, as expected and changes the return from wp_enqueue_media.

However, I faced an issue with unit testing. Can you please guide me with the flow, i need to follow for the same.

Looking for your co-operation dearly.

#5 @pento
5 months ago

  • Milestone changed from 5.0 to 5.1

#6 @adamsilverstein
2 months ago

  • Milestone changed from 5.1 to 5.2

This one needs some more attention before its ready. Punting to 5.2.

#7 @adamsilverstein
3 weeks ago

43658.diff includes unit tests that verify the correct mime types are available to the grid. these tests fail before the patch and succeed after it.

@itzmekhokan can you take a look at what I did for the unit tests - let me know if you have any questions - and also verify this resolves the issue you were seeing.

#8 @adamsilverstein
3 weeks ago

Noting in travis I'm seeing phpcs errors that can't be fixed automatically: https://travis-ci.org/adamsilverstein/wordpress-develop-fork/jobs/500433986. I'm assuming I need to fix these before committing.

This ticket was mentioned in Slack in #core-committers by adamsilverstein. View the logs.


3 weeks ago

#10 @adamsilverstein
2 weeks ago

Travis was failing (https://travis-ci.org/adamsilverstein/wordpress-develop-fork/jobs/500433986) because the linting errors in wp-includes/media.php could not be fixed automatically.

I ran phpcs --standard=phpcs.xml.dist src/wp-includes/media.php and manually addressed all errors. Errors fixed included "Assignments must be the first block of code on a line" and "Use Yoda Condition checks, you must" as well as "Use placeholders and $wpdb->prepare(); found $sql"

43658.3.diff includes code fixes in response to phpcs

travis build started: https://travis-ci.org/adamsilverstein/wordpress-develop-fork/builds/501627830

#11 @adamsilverstein
2 weeks ago

  • Keywords has-unit-tests added; needs-testing needs-unit-tests removed

#12 @adamsilverstein
30 hours ago

  • Keywords commit added

43658.diff is ready: not going to worry about the phpcs errors for unchanged code.

#13 @adamsilverstein
25 hours ago

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

In 44947:

Media: grid view attachment filter drop down - only show available mime types.

In the media library gird view, properly limit the media attachment filter to available mime types, matching the list view.

Props itzmekhokan.
Fixes #43658.

Note: See TracTickets for help on using tickets.