[wp-trac] [WordPress Trac] #14294: get_permalink() calling get_post_permalink() with post object instead of post ID
WordPress Trac
wp-trac at lists.automattic.com
Tue Jul 13 05:30:11 UTC 2010
#14294: get_permalink() calling get_post_permalink() with post object instead of
post ID
--------------------------+-------------------------------------------------
Reporter: mikeschinkel | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Post Types | Version: 3.0
Severity: normal | Keywords:
--------------------------+-------------------------------------------------
Can someone please check my logic on this? It appears that
get_permalink() in WP 3.0 ([http://core.trac.wordpress.org/browser/trunk
/wp-includes/link-template.php#L111 /wp-includes/link-template.php line
111]) is calling get_post_permalink() with a post object instead of post
ID as the first parameter.
The [http://core.trac.wordpress.org/browser/trunk/wp-includes/link-
template.php#L176 signature for get_post_permalink()] is:
{{{
function get_post_permalink( $id = 0, $leavename = false, $sample = false
)
}}}
And then it applies [http://core.trac.wordpress.org/browser/trunk/wp-
includes/link-template.php#L207 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
[http://core.trac.wordpress.org/browser/trunk/wp-includes/link-
template.php#L207 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);
}}}
to
{{{
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.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/14294>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list