Add imagify_get_mime_types filter to imagify_get_mime_types()#1184
Add imagify_get_mime_types filter to imagify_get_mime_types()#1184Miraeld wants to merge 3 commits into
Conversation
…ypes() Adopted from #1177, using wpm_apply_filters_typed per project standard. Co-authored-by: mauroTabsSpaces <300527260+mauroTabsSpaces@users.noreply.github.com>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Duplication | 0 |
🟢 Coverage 100.00% diff coverage
Metric Results Coverage variation Report missing for 3fb41021 Diff coverage ✅ 100.00% diff coverage (50.00%) Coverage variation details
Coverable lines Covered lines Coverage Common ancestor commit (3fb4102) Report Missing Report Missing Report Missing Head commit (325baa8) 19540 647 3.31% Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch:
<coverage of head commit> - <coverage of common ancestor commit>Diff coverage details
Coverable lines Covered lines Diff coverage Pull request (#1184) 8 8 100.00% Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified:
<covered lines added or modified>/<coverable lines added or modified> * 100%1 Codacy didn't receive coverage data for the commit, or there was an error processing the received data. Check your integration for errors and validate that your coverage setup is correct.
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
Covers the default, image, and not-image type branches and the new imagify_get_mime_types filter. Co-authored-by: mauroTabsSpaces <300527260+mauroTabsSpaces@users.noreply.github.com>
Codacy diff coverage only measures the unit suite (composer code-coverage runs --testsuite unit), so integration tests alone left the changed lines at 0%. Add unit tests via Brain Monkey. Also discard malformed entries returned by the imagify_get_mime_types filter: only string extension => 'type/subtype' string pairs survive, protecting downstream mime checks from bad callback returns. Co-authored-by: mauroTabsSpaces <300527260+mauroTabsSpaces@users.noreply.github.com>
Description
Closes #1177
Adds a filter on the return value of
imagify_get_mime_types(), allowing developers to customize the mime types Imagify considers optimizable when checking whether a file is supported.This PR adopts community PR #1177 from @mauroTabsSpaces (credited as commit co-author), which originally proposed a plain
apply_filters()call. Per our project standard, it was converted towpm_apply_filters_typed( 'array', 'imagify_get_mime_types', $mimes )and a filter docblock was added. We adopt it internally because fork PRs cannot pass CI here: our integration tests require theIMAGIFY_TESTS_API_KEYsecret, which GitHub does not expose to workflows triggered from forks.Type of change
Detailed scenario
What was tested
imagify_get_mime_types()returns the same array as before (default passthrough — no behavior change for existing sites). With anadd_filter( 'imagify_get_mime_types', ... )callback registered, the returned array reflects the callback's modification. A callback returning a non-array value is coerced back to an array bywpm_apply_filters_typed, protecting callers from invalid filter output.How to test
add_filter( 'imagify_get_mime_types', function( $mimes ) { unset( $mimes['pdf'] ); return $mimes; } );$typeargument passed toimagify_get_mime_types()).Affected Features & Quality Assurance Scope
imagify_get_mime_types()ininc/functions/attachments.php— used by mime-type support checks across the plugin. Default behavior is unchanged when no filter callback is registered, so regression risk is limited to code paths that explicitly hook into the new filter.Technical description
Documentation
New filter
imagify_get_mime_types:wpm_apply_filters_typed( 'array', 'imagify_get_mime_types', $mimes )array $mimes— mime types asextension => mime typepairs. Contains images and/or PDF depending on the$typeargument passed toimagify_get_mime_types().New dependencies
None.
Risks
None identified. The change is additive (a new filter hook around an existing return value); with no callback registered, output is identical to before.
wpm_apply_filters_typed( 'array', ... )enforces the return type, so a misbehaving third-party callback cannot corrupt the mime types array with a non-array value.Mandatory Checklist
Code validation
Code style
Unticked items justification
wpm_apply_filters_typed()call around an existing return statement, with no branching logic to cover. Manual verification (see "What was tested") confirms both the default passthrough and the filtered path.Additional Checks