[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
Wed Mar 20 15:48:53 UTC 2019
#36934: Use of get_the_excerpt($post) is broken if post has no excerpt and you are
inside a loop
-------------------------------------------------+-------------------------
Reporter: magicroundabout | Owner: swissspidy
Type: defect (bug) | Status: reviewing
Priority: normal | Milestone: Future
| Release
Component: Posts, Post Types | Version: 4.5
Severity: normal | Resolution:
Keywords: has-patch needs-testing has-unit- | Focuses: template
tests dev-feedback |
-------------------------------------------------+-------------------------
Comment (by boonebgorges):
In [changeset:"44941" 44941]:
{{{
#!CommitTicketReference repository="" revision="44941"
Posts: Avoid the use of globals in `get_the_content()` and related
functions.
This changeset introduces `$post` parameters to `get_the_content()` and
`wp_trim_excerpt()`. When a `$post` object is passed to one of these
functions,
the functions will operate on the data from that object, rather than from
the
post globals (`$authordata`, `$page`, etc). This ensures that the
functions work
in a predictable manner when used outside of the regular post loop.
The global-mismatch problem is surfaced in cases where `get_the_excerpt()`
is
called outside of the post loop, on posts that don't have a defined
excerpt. In
these cases, the post globals - used to generate a fallback excerpt - may
refer
to the incorrect object, resulting in PHP notices or other unpredictable
behavior. See #36934 for a related issue.
Props spacedmonkey, kraftbj, Shital Patel.
Fixes #42814.
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/36934#comment:62>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list