publish_post hook isn’t working for scheduled posts

I reworked (added another version of) my function to remove the if statement to check post status, as the post is scheduled to publish it turns out i don’t need to check it again.

/* the function */
function tcr_tweet2($postID)
{

            /* get the post that's being published */
            $post = get_post($postID); 
            $post_title = $post->post_title;

            /* get the author of the post */
            $author_id=$post->post_author;
            /* author needs a twitterid in their meta data*/
            $author = get_the_author_meta('twitterid',$author_id );

            /* get the permalink and shorten it */
            $url = get_permalink($postID);
            $short_url = getBitlyUrl($url);

            //check to make sure the tweet is within the 140 char limit
            //if not, shorten and place ellipsis and leave room for link. 
                    if (strlen($post_title) + strlen($short_url) > 100) {
                       $total_len = strlen($post_title) + strlen($short_url);
                       $over_flow_count = $total_len - 100;
                       $post_title = substr($post_title,0,strlen($post_title) - $over_flow_count - 3);
                       $post_title .= '...';                
                    }

            //add in the shortened bit.ly link
            $message =  "New: ".$post_title." - ".$short_url." by @".$author." #hashtag";

             if ( $post->post_status != 'publish' ) return;
            //call the tweet function to tweet out the message
            goTweet($message);
}

I can then use the following hook just for this version and it works.

 add_action('future_to_publish', 'tcr_tweet2');

Leave a Comment