get_permalink() calling get_post_permalink() with post object instead of post ID
|Reported by:||mikeschinkel||Owned by:|
Can someone please check my logic on this? It appears that get_permalink() in WP 3.0 (/wp-includes/link-template.php line 111) is calling get_post_permalink() with a post object instead of post ID as the first parameter.
function get_post_permalink( $id = 0, $leavename = false, $sample = false )
And then it applies the "post_type_link" filter on line 207 without touching $id hence without attempting to change it's data type:
return apply_filters('post_type_link', $post_link, $id, $leavename, $sample)
I found it because it was breaking my use of the "post_type_link" hook on code that previously worked in a beta version of 3.0. The fix is easy, just change
return get_post_permalink($post, $leavename, $sample);
return get_post_permalink($post->ID, $leavename, $sample);
I was able to resolve it in my own "post_type_link" hook with this:
$id = (is_numeric($id) ? $id : is_object($id) and isset($id->ID) ? $id->ID : 0);
But wouldn't it be better just to fix the bug, assuming it is a bug?
OTOH, please let me know if this is my misunderstanding and what I should be doing differently; it probably is because this seems too easy.