Skip to content

Filter media library by optimization status - #13

Merged
ajaydsouza merged 3 commits into
WebberZone:mainfrom
muneeb-ashraf:feature/media-library-status-filter
Sep 4, 2026
Merged

Filter media library by optimization status#13
ajaydsouza merged 3 commits into
WebberZone:mainfrom
muneeb-ashraf:feature/media-library-status-filter

Conversation

@muneeb-ashraf

@muneeb-ashraf muneeb-ashraf commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add an optimization-status dropdown to the Media Library list view
  • drive Optimized, Skipped, and Failed from queue-table status; treat eligible unqueued, pending, and processing images as Not yet optimized
  • restrict every status to supported source MIME types while preserving existing MIME and date filters
  • keep an active URL filter working when the Optimized column is hidden
  • document the feature in the 1.1.0 changelog

Tests

  • PHP syntax checks
  • PHPCS on the changed production and test files
  • PHPStan
  • PHPCompatibility (PHP 7.4-8.6)
  • database-backed WordPress integration coverage asserting exact attachment IDs for every state

Known limitation

Media Library grid mode does not fire restrict_manage_posts and uses admin-ajax.php, so this dropdown remains list-view only.

Fixes #10

@ajaydsouza

ajaydsouza commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Thanks for the PR. The dropdown renders in the right place and the wiring is clean, but the filter results don't match the column they're filtering. A few things to fix before this can go in.

1. Use the queue table, not _wzio_data.

_wzio_data is written after every attempt — successful, skipped or failed — so EXISTS means "was attempted", not "was optimized". Converter::convert_attachment() calls Attachment_Meta::set() for every file regardless of outcome. Meanwhile the column checks Attachment_Meta::get_totals()['files'] === 0. The two disagree: on a library of mine with 1,748 attachments, "Optimized" returns 1,746 when it should return 1,675, and 71 items show "Not yet" in the column while sitting under "Optimized".

The {$wpdb->prefix}wzio_queue table already holds this state, every optimization path writes to it (Processor::process_attachment() and Media_Library::ajax_optimize() both go through Queue::add()Queue::complete()), and it's already indexed on (status, id). Please drive all the dropdown options off status. No new meta key and no backfill needed.

2. Unsupported attachments shouldn't appear in "Not yet optimized".

PDFs and videos currently land there, showing "Not an image that can be optimized" in the column. Restrict to Helpers::SOURCE_MIME_TYPES.

3. skipped needs its own option.

Eligible JPEGs/PNGs that produced no smaller sidecar end up skipped — 71 of them on my test library. They aren't "not yet optimized" and won't change on a retry, so they need to be distinguishable rather than folded into a bucket that implies pending work.

4. The hidden-column check must not disable the query.

can_view_status_filter() gates both render_status_filter() and filter_by_status(). Hide the "Optimized" column in Screen Options and upload.php?wzio_optimization_status=failed returns the entire library, with no dropdown to explain why. Gate the rendering only.

5. Smaller items:

  • Please mark this as @since 1.1.0 throughout. This was supposed to be implemented in 1.3.0 but I can advance it to 1.1.0
  • Also add a succinct readme.txt entry for 1.1.0 changelog.
  • Grid mode drops the filter (restrict_manage_posts doesn't fire, $pagenow is admin-ajax.php). A note in the PR is fine.
  • MediaLibraryTest.php only asserts the shape of the meta_query array — it never creates an attachment or checks which IDs come back, which is why it passes with the buckets wrong. Please seed one attachment per state and assert the exact returned IDs.

@muneeb-ashraf

Copy link
Copy Markdown
Contributor Author

Addressed the review in 8227e8d:

  • all four buckets now use queue-table state
  • unsupported MIME types are excluded
  • Skipped has its own option
  • hiding the column only hides the dropdown; an active URL filter still applies
  • all new APIs use @since 1.1.0, with a 1.1.0 changelog entry
  • tests now seed unqueued, pending, processing, done, skipped, failed, unsupported, alternate-MIME, and alternate-month attachments and assert exact returned IDs

I also added the grid-mode limitation to the PR description.

@ajaydsouza

Copy link
Copy Markdown
Contributor

Thanks — the filtering itself tests out well. CI is red from two things:

1. A bug on my side, now fixed. Database::is_installed() memoised its result for the whole request and install() never cleared it. Once ConverterTest probed before the table existed, every Queue call short-circuited for the rest of the run — which is why Queue::get_status() returned '' instead of 'done' at line 222. Fixed on main in d3f4d98 (CI green). Please can you rebase and resubmit?

2. The dropdown assertion. selected() outputs selected='selected', and the template already has a space before it, so the markup is value="failed" selected='selected'. The assertion expects value="failed" selected. The output is correct — just the assertion needs updating.

Once those are green I'll merge. Two follow-ups I'll handle myself afterwards:

  • Converter::delete_sidecars() clears the meta but leaves the queue row, so an attachment stays under "Optimized" after "Delete optimized copies".
  • My earlier suggestion to drop the meta check entirely was wrong — attachments optimized without a queue row now show as "Not yet optimized". Needs a meta fallback.

I'll also keep the dropdown visible when a filter is active but the column is hidden.

@muneeb-ashraf
muneeb-ashraf force-pushed the feature/media-library-status-filter branch from 8227e8d to 458de2d Compare September 4, 2026 14:44
@muneeb-ashraf

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (including d3f4d98) and updated the dropdown assertion to match selected='selected'. The branch has been resubmitted. Thanks for fixing the queue-table cache issue and clarifying the follow-ups.

@muneeb-ashraf
muneeb-ashraf force-pushed the feature/media-library-status-filter branch 2 times, most recently from 37ba80d to ccaa5d6 Compare September 4, 2026 14:52
@muneeb-ashraf

Copy link
Copy Markdown
Contributor Author

The rebase and dropdown assertion are now confirmed: PHPCS and PHP Compatibility pass, and the dropdown test itself is green. The unit matrix still reports Database::is_installed() as false after Database::install() in both queue-backed tests, even with d3f4d98 in this branch; class-database.php is identical to current main. I added boundary assertions to confirm the failure occurs before Queue::add(): https://github.com/WebberZone/webberzone-image-optimizer/actions/runs/33886291874. Could you please take another look at the main-side table-install/cache fix?

@muneeb-ashraf
muneeb-ashraf force-pushed the feature/media-library-status-filter branch from ccaa5d6 to c571f51 Compare September 4, 2026 15:01
@muneeb-ashraf

Copy link
Copy Markdown
Contributor Author

Tracked the remaining failure to the test fixture rather than d3f4d98. WP_UnitTestCase rewrites CREATE TABLE to CREATE TEMPORARY TABLE inside each test transaction, while MySQL's SHOW TABLES (used by Database::is_installed()) does not list temporary tables.

I moved Database::install() to class setup, outside the per-test transaction, added class-level cleanup, and removed the diagnostic assertions. The exact dropdown assertion is also in place. All checks are now green, including all seven PHPUnit jobs: https://github.com/WebberZone/webberzone-image-optimizer/actions/runs/33887130786

@ajaydsouza
ajaydsouza merged commit 1940fd2 into WebberZone:main Sep 4, 2026
9 checks passed
ajaydsouza added a commit that referenced this pull request Sep 6, 2026
…s-filter

Filter media library by optimization status
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Filter the media library by optimization status

2 participants