#38225 closed defect (bug) (fixed)
Improve documentation for is_single()
Reported by: | danburzo | Owned by: | DrewAPicture |
---|---|---|---|
Milestone: | 4.7 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Query | Keywords: | good-first-bug has-patch |
Focuses: | docs | Cc: |
Description
Please note that this is just by reading through the source code for get_body_class() and collating that with the docs, so I might be wrong, but would not this code branch be unreachable?
if (is_single()) { ... if (is_attachment()) { // Unreachable? } }
In file: https://core.trac.wordpress.org/browser/trunk/src/wp-includes/post-template.php#L570
Attachments (2)
Change History (13)
#2
@
8 years ago
Hi @ocean90, thank you for your patience with this!
I'm just starting out reading the source code (which is very well documented, BTW!), there might be something I'm missing. Does that mean that the is_single()
function will return true
for a single attachment page? In which case this comment needs to be updated?
Is the query for an existing single post? Works for any post type, except attachments and pages
#4
@
8 years ago
- Focuses docs added
- Keywords needs-patch good-first-bug added
- Milestone changed from Awaiting Review to Future Release
@danburzo Yeah, we should update the docs. Do you want to work on a patch?
#5
@
8 years ago
- Milestone changed from Future Release to 4.7
Just stumbled upon this while working on #18375. It would be great if we could fix it for this release.
#6
@
8 years ago
- Keywords has-unit-tests removed
- Summary changed from Unreachable code in get_body_class()? to Improve documentation for is_single()
This ticket was mentioned in Slack in #core by jeffpaul. View the logs.
8 years ago
#8
@
8 years ago
Request For Code Review
Hi @ocean90,
Could you please review this patch, which changes the documentation from:
* Works for any post type, except attachments and pages
to:
* Works for any post type, except pages.
As you showed in your comment, is_single()
does work for attachment post types. You pointed to how is_single() will be true for attachments.
#9
@
8 years ago
- Component changed from General to Query
- Keywords has-patch added; needs-patch removed
Thanks @ryankienstra! The patch looks good.
Hello @danburzo, welcome to Trac!
I've attached a unit test in 38225.patch which shows that it's working.
is_single()
is true because of this line.