[wp-hackers] user_trailingslashit()?

Mike Schinkel mikeschinkel at newclarity.net
Tue Dec 8 07:13:28 UTC 2009

On Dec 8, 2009, at 1:29 AM, Andrew Nacin wrote:
>> Why not just:
>> $link =user_trailingslashit(get_bloginfo('home')) .
>> str_replace('%pagename%', $post_type['plural'] . '/' . $post->post_name,
>> $permastruct);
> This is incorrect code. Here, you're misapplying user_trailingslashit, which
> is for whether a permalink structure calls for a slash at the end.
> get_bloginfo('home') will not return a trailing slash and will need one, but
> here, it will only be given one if the permalink structure calls for one.
> (And then the user's permalink structure is ignored as to whether a trailing
> slash is desired -- I think you get the picture.)

THANK YOU!  I misread the code to be encompassing the full expression and not just get_bloginfo().  It really had be thrown for a loop.

When you are confused by code as I have been by the WP_Rewrite() stuff you forget to check basic assumptions and things trip you up that normally wouldn't.

BTW, I think that's why I would tend to write the code to look something like this:

$root = trailingslashit(get_bloginfo('home'));
$path = str_replace('%pagename%', $post_type['plural'] . '/' . $post->post_name, $permastruct);
$link = user_trailingslashit($root . $path);

That's harder to misread. (I won't said it is as performant; I usually write my code to be understandable even if it's a tiny fraction slower. But I know and respect that understandable code isn't always the first priority.)


> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers

More information about the wp-hackers mailing list