我编写了一个简单的插件,可以在帖子发布时获取帖子的内容,并将其发送到外部站点进行归档。这通常是可行的,但当处理以前没有保存或发布的帖子时,没有post_content
值可用。如果在发布之前另存为草稿,则所有操作都正常,只有在直接发布时,该值才为空。
我的插件是这样的:
function send_data($postID,$post){
global $post;
print_r($post); //used for debugging the contents of $post
//stuff here to send the post for archiving
}
add_action(\'publish_post\',\'send_data\',2);
如果一切顺利,我将此作为$post的内容:
WP_Post Object ( [ID] => 159 [post_author] => 1 [post_date] => 2013-01-30 09:11:05 [post_date_gmt] => 0000-00-00 00:00:00 [post_content] => This is the content of the post [post_title] => Something new [post_excerpt] => [post_status] => draft [comment_status] => open [ping_status] => open [post_password] => [post_name] => [to_ping] => [pinged] => [post_modified] => 2013-01-30 09:11:05 [post_modified_gmt] => 2013-01-30 09:11:05 [post_content_filtered] => [post_parent] => 0 [guid] => http://wordpress/?p=159 [menu_order] => 0 [post_type] => post [post_mime_type] => [comment_count] => 0 [filter] => raw )
但是,如果我直接从创建帖子内容跳到“发布”按钮,我会得到一个空值
$post->post_content
:
WP_Post Object ( [ID] => 159 [post_author] => 1 [post_date] => 2013-01-30 09:11:05 [post_date_gmt] => 0000-00-00 00:00:00 [post_content] => [post_title] => Something new [post_excerpt] => [post_status] => draft [comment_status] => open [ping_status] => open [post_password] => [post_name] => [to_ping] => [pinged] => [post_modified] => 2013-01-30 09:11:05 [post_modified_gmt] => 2013-01-30 09:11:05 [post_content_filtered] => [post_parent] => 0 [guid] => http://wordpress/?p=159 [menu_order] => 0 [post_type] => post [post_mime_type] => [comment_count] => 0 [filter] => raw )
有没有人想过我该如何让这更可靠?有钩子吗
after_publish_post
或者类似的东西?
任何想法都很感激。