WordPress显然在$post
对象在期间publish_post
这(通常)不是问题,因为您可以通过get_post_format( $post->ID )
循环外部。
这似乎在xmlrpc_publish_post
或app_publish_post
. 人们必须解决这个问题,才能在移动/桌面应用程序上使用插件/主题功能。
我的具体代码如下,以防我这边出错。
function posse_twitter( $post_ID ) {
error_log(\'Executing posse_twitter()\');
global $post;
// check post format if necessary
if ( get_post_format( $post->ID ) != \'status\' ) return;
error_log(\'posse_twitter() made it past format check\');
$post_id = $post->ID;
$shortlink = wp_get_shortlink();
$tweet_content = $post->post_content.\' \'.$shortlink;
// ...run code once
if ( !get_post_meta( $post_id, \'tweeted\', $single = true ) ) {
error_log(\'posse_twitter() not tweeted before\');
// require the relevant libraries
require get_template_directory() .\'/inc/posse/libraries/tmhOAuth/tmhOAuth.php\';
require get_template_directory() .\'/inc/posse/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
));
error_log(\'posse_twitter() made it past tmhOAuth, should be on Twitter now\');
update_post_meta( $post_id, \'tweeted\', true );
}
}
add_action( \'xmlrpc_publish_post\', \'posse_twitter\' );
add_action( \'app_publish_post\', \'posse_twitter\' );
add_action( \'publish_post\', \'posse_twitter\' );
error_log()
自从我调试这个以来,它就被包括在内了。当
xmlrpc_publish_post
和
app_publish_post
被击中,但无法通过格式检查。
更新:即使我先将文章保存为草稿(通过XML-RPC),这也不起作用。