Should be simple - I'd like WP to tweet the content of a post once (when it's published the first time) if the post format is 'status'.
The code below isn't returning an error on publish, nor is it tweeting OR updating the post metadata, which leads me to believe I'm either using the hook incorrectly or there's something wrong with checking the post type as I have.
This is currently living in my functions.php
I'm using Matt Harris' tmhOAuth and have successfully tweeted from a standalone tweet.php using most of the function below.
Keys and secrets removed for security.
function posse_twitter( $post ) {
// check post type if necessary
if ( $post->post_type != 'status' ) return;
$post_id = $post->ID;
$tweet_content = $post->post_content;
if ( !get_post_meta( $post_id, 'tweeted', $single = true ) ) {
// ...run code once
//Include Libraries
require 'libraries/tmhOAuth/tmhOAuth.php';
require 'libraries/tmhOAuth/tmhUtilities.php';
$tmhOAuth = new tmhOAuth(array(
'consumer_key' => 'XXXXX',
'consumer_secret' => 'XXXXX',
'user_token' => 'XXXXX',
'user_secret' => 'XXXXX',
));
$code = $tmhOAuth->request('POST', $tmhOAuth->url('1/statuses/update'), array(
'status' => $tweet_content
));
if ($code == 200) {
tmhUtilities::pr(json_decode($tmhOAuth->response['response']));
} else {
tmhUtilities::pr($tmhOAuth->response['response']);
}
update_post_meta( $post_id, 'tweeted', true );
}
}
add_action( 'draft_to_published', 'posse_twitter' );
$tweet_content/$post->post_contentset? If so: Delete the meta value (or update tofalseas long as you're developing, so you can test it). – kaiser Oct 29 '12 at 23:14var_dump( $post->post_content );inside... or have I understood you wrong? Seems like a funny question for someone writing such advanced code, so I guess I'm missing the point of your question. – kaiser Oct 30 '12 at 0:09$postobject gives meint(730), which is the correct post ID. Dumping anything from the object (e.g.$post->post_type) returns NULL. – Edbury Oct 30 '12 at 15:05