Opened 10 years ago
Closed 10 years ago
#25005 closed defect (bug) (fixed)
Notice using get_sample_permalink()
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 3.7 | Priority: | normal |
Severity: | minor | Version: | 2.5 |
Component: | Warnings/Notices | Keywords: | has-patch |
Focuses: | Cc: |
Description
Hello
This is about a Notice in get_sample_permalink(), here the core:
function get_sample_permalink($id, $title = null, $name = null) { $post = get_post($id); if ( !$post->ID ) return array('', ''); ...
So if the $id is not correct, the $post->ID will throw a Notice: Trying to get property of non-object in file.php on line n
I think we can use a simple "!$post" or "is_a( $post, 'WP_Post' ) )" here.
Thanks for reading
Attachments (1)
Change History (10)
#2
in reply to:
↑ 1
@
10 years ago
Are you serious? ... Please ... don't be that guy.
Replying to alexvorn2:
this will slow the process of the function, just use a correct ID :D
#4
@
10 years ago
- Type changed from enhancement to defect (bug)
This is a bug, not an enhancement. We should be checking the value of $post
here, probably just changing the if statement to if ( ! $post || ! $post->ID )
#5
follow-up:
↓ 6
@
10 years ago
- Component changed from General to Warnings/Notices
- Keywords needs-patch added
- Milestone changed from Awaiting Review to 3.7
- Version set to 2.5
#7
@
10 years ago
$post is enough. Otherwise get_post() should be checked what it will return. That is also why is_a() isn't needed. Also if it was needed $post instanceof WP_Post
would be faster.
this will slow the process of the function, just use a correct ID :D