我在插件中使用WordPress per_post_update钩子,并在其他网站上使用curl,但此钩子在每次更新时执行两次。所以卷曲两次。
add_action('post_updated', 'officexd_post_send_on_publish',10,2);
function officexd_post_send_on_publish($post_id) {
global $wpdb;
$post = get_post($post_id);
$obj = false;
if(count($post)) {
$obj = new stdClass();
$obj->tite = $post->post_title;
$content = apply_filters('the_content', $post->post_content);
$obj->description = $content;
$text = "<b>".$obj->tite."</b><br>";
$text .= $obj->description;
$src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full', false );
$data = array('postText' => $text);
if($src[0]) {
$data['image'] = $src[0];
}
curlRequest('wp-post',$data);
} else {
echo "Not working";
}
}