Opened 12 years ago
Closed 11 years ago
#24257 closed enhancement (fixed)
is_attachment() should accept $attachment parameter
Reported by: | alex-ye | Owned by: | wonderboymusic |
---|---|---|---|
Milestone: | 3.9 | Priority: | normal |
Severity: | normal | Version: | 3.5.1 |
Component: | Query | Keywords: | has-patch needs-unit-tests |
Focuses: | Cc: |
Description
Like is_single(),is_page(),is_author() ... etc I can't see any reason why we is_attachment() function accept $attachment parameter to make easy checks.
Attachments (2)
Change History (13)
#4
in reply to:
↑ 3
@
11 years ago
- Keywords has-patch added; close removed
Replying to wonderboymusic:
You aren't checking the
post_type
- nothing about that function is attachment-specific, it could evaluate true against an arbitrarily-passed post
I just make the patch like the is_page() function, We doesn't need to check the post-type since we pass an attachment ID, title, slug, or array of such.. so we don't need to check the Post object too.
You didn't give a reasons why the core doesn't add $attachment parameter.
#5
in reply to:
↑ 3
@
11 years ago
Replying to wonderboymusic:
You aren't checking the
post_type
- nothing about that function is attachment-specific, it could evaluate true against an arbitrarily-passed post
The check for $this->is_attachment
does exactly this. How could that return TRUE
for another post type?
#8
@
11 years ago
- Milestone changed from Awaiting Review to 3.9
24257.diff refreshes and adds Unit Tests
#9
@
11 years ago
- Owner set to wonderboymusic
- Resolution set to fixed
- Status changed from new to closed
In 27016:
#10
@
11 years ago
- Keywords needs-unit-tests added
- Resolution fixed deleted
- Status changed from closed to reopened
I think this is solid. Could we add some assertions that also assert false? Just to make sure we don't have problems in the future. It might be nice to further assert things like $query->is_single/is_page/is_attachment (the property, not the methods), that the queried object matches the post that was created, etc.
Additionally, note that attachments are also is_single except in a single situation where it is instead is_page. It would be good to test is_singular(), is_singular and the respective is_(post|page) (methods and properties) in both truthiness and falseness.
You aren't checking the
post_type
- nothing about that function is attachment-specific, it could evaluate true against an arbitrarily-passed post