2.x Remove Attachment::$caption
property in favor of Attachment::caption()
method
#2612
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Ticket: #2610
Issue
This pull request iterates on the work by @xavivars in #2610 (thanks, @xavivars). For 2.x, we missed that the caption of an attachment is set while initializing it. See this excerpt from 1.x:
timber/lib/Image.php
Lines 215 to 217 in 8d9bff2
Solution
This pull request:
Attachment::$caption
property and instead adds anAttachment::caption()
method. I think this is the approach we choose more and more: Using methods instead of countless properties we have to initialize.wp_get_attachment_caption
filter, which is used in the equivalent WordPress core functionwp_get_attachment_caption()
.Impact
This doesn’t break backwards compatibility, even if
Timber\Image::$caption
is used in PHP, becauseTimber\Core::__get()
will automatically resolve toTimber\Image::caption()
.Usage Changes
None.
Considerations
Yes,
caption()
belongs inTimber\Attachment
and notTimber\Image
, because you can set captions in all kinds of attachments in WordPress, not just images.Testing
Yes.