Make WordPress Core

Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#38225 closed defect (bug) (fixed)

Improve documentation for is_single()

Reported by: danburzo's profile danburzo Owned by: drewapicture's profile 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)

38225.patch (906 bytes) - added by ocean90 8 years ago.
38225.diff (527 bytes) - added by ryankienstra 8 years ago.

Download all attachments as: .zip

Change History (13)

@ocean90
8 years ago

#1 @ocean90
8 years ago

  • Keywords has-unit-tests added
  • Version trunk deleted

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.

#2 @danburzo
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

#3 @ocean90
8 years ago

#38241 was marked as a duplicate.

#4 @ocean90
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 @swissspidy
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 @swissspidy
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

@ryankienstra
8 years ago

#8 @ryankienstra
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 @swissspidy
8 years ago

  • Component changed from General to Query
  • Keywords has-patch added; needs-patch removed

Thanks @ryankienstra! The patch looks good.

#10 @DrewAPicture
8 years ago

  • Owner set to DrewAPicture
  • Resolution set to fixed
  • Status changed from new to closed

In 39052:

Docs: Update the DocBlock description for WP_Query::is_single() to mention that it works for any post types excluding pages.

Props ryankienstra.
Fixes #38225.

#11 @ocean90
8 years ago

In 39095:

Query: Add tests for WP_Query::is_single() and get_body_class() with attachments.

See [39052]
See #38225.

Note: See TracTickets for help on using tickets.