[wp-trac] [WordPress Trac] #36934: Use of get_the_excerpt($post) is broken if post has no excerpt and you are inside a loop
WordPress Trac
noreply at wordpress.org
Tue Jul 5 10:54:33 UTC 2016
#36934: Use of get_the_excerpt($post) is broken if post has no excerpt and you are
inside a loop
-------------------------------------------------+-------------------------
Reporter: magicroundabout | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: 4.6
Component: Formatting | Version: 4.5
Severity: normal | Resolution:
Keywords: has-patch needs-testing needs-unit- | Focuses: template
tests |
-------------------------------------------------+-------------------------
Changes (by swissspidy):
* keywords: has-patch needs-testing => has-patch needs-testing needs-unit-
tests
* milestone: Awaiting Review => 4.6
Comment:
So the trouble began with #27246 after adding the optional `$post`
parameter to `get_the_excerpt()`. A handful of tests where added for that
function, but apparently the impact this change had on `wp_trim_excerpt()`
went unnoticed until now.
`wp_trim_excerpt()` needs to be aware of the current post. Unfortunately,
[attachment:36394.diff] or [attachment:36934.3.patch] are not enough, as
`get_the_content()` relies on a bunch of global variables tied to the
current post (especially`$pages`, `$more` and `$numpages`, see
`setup_postdata()`) .
This means we need to use `setup_postdata()` to temporarily set these
variables. [attachment:36934a.diff] does this inside `get_the_content()`
(introducing a new `$post` parameter) whereas [attachment:36934b.diff]
does this inside `wp_trim_excerpt()` (only adding the `$post` parameter
there).
Both methods seem to work, but it needs tests.
I don't like how `$more` is dependant on `get_queried_object_id()`. This
means the output of`get_the_excerpt()` will be different depending on
whether you're on that post or not (see current tests in the patches).
Ideally, these variables shouldn't be global at all, but instead be
fetched via `WP_Post` methods. `setup_postdata()` could be simplified a
lot.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/36934#comment:11>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list