Repository navigation
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
|
The PR says it only adds tests for a filter "introduced in PR #14024". But the diff also contains the filter implementation itself. |
| * | ||
| * @since 7.2.0 | ||
| * | ||
| * @param string|null $override_alt_text Short-circuit return value. |
There was a problem hiding this comment.
The docblock's claims @param string|null $override_alt_text but actually can return anything.
There was a problem hiding this comment.
I'm not sure I understand? Technically, yes, any filter could have anything for the first parameter (because you can't control what filters a third-party plugin or theme might be using), but I think the convention is to document the data type that should be there.
The implementation and the docblock largely follows the pattern used in other "short-circuit" filters in WordPress core. For example:
- pre_wp_unique_post_slug - first
@paramisstring|null - pre_wp_mail - first
@paramisnull|bool - pre_wp_load_alloptions - first
@paramisarray|null
| /** | ||
| * Filters whether to short-circuit the parsing of alt text from an image. | ||
| * | ||
| * Returning a non-null value will short-circuit the image parsing, |
There was a problem hiding this comment.
It claims: Returning a non-null value will short-circuit the image parsing, which implies the full image parsing, not just the altext
|
About tests:
|
I've closed PR #14024 in favor of this one so that all discussion (for either the filter itself or the tests) will be in one place. |
| if ( empty( $meta['title'] ) && $caption_length < 80 ) { | ||
| if ( in_array( 'title', $allowed_keys, true ) && empty( $meta['title'] ) && $caption_length < 80 ) { | ||
| // Assume the title is stored in 2:120 if it's short. | ||
| $meta['title'] = $caption; |
There was a problem hiding this comment.
To execute this line, you need to have both caption and title in $allowed_keys. I think you should only need title?
| $description_length = strlen( $exif_usercomment ); | ||
| if ( empty( $meta['title'] ) && $description_length < 80 ) { | ||
| if ( in_array( 'title', $allowed_keys, true ) && empty( $meta['title'] ) && $description_length < 80 ) { | ||
| $meta['title'] = trim( $exif_usercomment ); |
There was a problem hiding this comment.
Same thing here as above - you need to have both caption and title in $allowed_keys. I think it should just be title.
|
Overall, the |
|
Thanks for the thorough review and catch on the I have updated the PR accordingly:
All tests pass cleanly in single site and multisite with 0 PHPCS violations. Ready for another look! |
Introduces unit tests in `tests/phpunit/tests/image/alttext.php` covering short-circuiting with a custom string, disabling alt text generation with an empty string, falling through when null is returned, passing the file path argument to the callback, and bypassing file access requirements. Follow-up to #66248 and PR WordPress#14024. Trac ticket: https://core.trac.wordpress.org/ticket/66248
…mage_metadata()`. Allows developers to customize or disable extraction of specific metadata fields (such as 'alt', 'caption', 'title', etc.) or disable metadata parsing entirely via a single filter, as proposed by @joedolson on Trac #66248. Guards IPTC, XMP ('alt'), and EXIF extraction based on the filtered allowed keys to avoid redundant disk I/O and XML/DOMDocument parsing overhead when fields are not needed. Maintains the complete default 13-key return array structure to ensure strict backward compatibility for all callers. Includes dedicated unit tests in `readImageMetadataAllowedKeys.php`. See #66248.
…op pre_wp_get_image_alttext filter. - Decouple 'title' from 'caption' in both IPTC and EXIF parsing within wp_read_image_metadata() so that allowing only 'title' still extracts titles stored in IPTC 2#120 or EXIF UserComment. - Remove pre_wp_get_image_alttext filter in favor of the unified wp_read_image_metadata_allowed_keys filter. - Add unit tests for independent title and caption extraction in readImageMetadataAllowedKeys.php. See #66248.
ca1607d to
7e24989
Compare
Adds comprehensive unit test coverage for the
pre_wp_get_image_alttextfilter introduced in #66248 (PR #14024).The tests in
tests/phpunit/tests/image/alttext.phpcover:''to turn off alt text generation as documented.nullis returned.$filepath argument is passed to the filter callback.Testing:
vendor/bin/phpcs src/wp-admin/includes/image.php tests/phpunit/tests/image/alttext.php: passed with 0 errors and 0 warnings.vendor/bin/phpunit tests/phpunit/tests/image/alttext.php: all 12 tests (17 assertions) pass cleanly on both single site and multisite.Trac ticket: https://core.trac.wordpress.org/ticket/66248
Use of AI Tools
AI assistance: Yes
Tool(s): Antigravity
Model(s): Gemini
Used for: Drafting unit tests and test matrix for
pre_wp_get_image_alttext. Code and test execution were reviewed and verified locally by robelsust.This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.