[wp-hackers] post processing weirdness

Scott Merrill skippy at skippy.net
Sat Jun 25 15:21:58 GMT 2005


A user of my subscribe2 plugin has brought a weird situation to my 
attention.

My plugin sends notifications of new posts when you publish them, 
registering itself against the publish_post action.  Included in the 
update notification is the permalink of the post.

If a user goes to the Write screen, composes a post, and presses the 
"Publish" button, the permalink in the update notification correctly 
applies the rewrite code to generate cruft-free URIs.

If a user creates and saves a Draft post, then later goes back and 
publishes that draft post, the update notification sends out a crufty URI.

I have confirmed that this happens on my 1.5.1.2 test blog.

I noticed slightly similar weird behavior when working on my WP-Cron 
Future Pings plugin: the global cached post object reflects its state 
_before_ you publish, and not the final state _after_ you click 
"Publish".  To avoid this in WP-Cron Future Pings, I directly queries 
the database for the post ID, to ensure that I had the most up-to-date data.

But for my subscribe2 plugin, I won't be able to do that right (unless I 
want to duplicate the contents of the get_permalink() function).

This is the offending line in wp-includes/template-functions-links.php:
if ('' != $permalink && 'draft' != $post->post_status) {

What harm is there in generating a permalink for a draft post?

My _real_ question, though, is what is this?
    $post = & get_post($id);
Line 40 of wp-includes/template-functions-links.php.

I grepped for "get_post" and found several get_post_*(), and of course 
get_posts(); but no get_post().  Is this simply a typo, or am I missing 
something?

I suspect that the get_post() results in a no-op, leaving $post set to 
the global $post object, which is still marked as Draft, even though 
"Publish" has been set.

Is this analysis correct?

-- 
skippy at skippy.net | http://skippy.net/

gpg --keyserver pgp.mit.edu --recv-keys 9CFA4B35
506C F8BB 17AE 8A05 0B49  3544 476A 7DEC 9CFA 4B35


More information about the wp-hackers mailing list