public function handle_insert($value, Falcon_Reply $reply)
{
if (!empty($value)) {
return $value;
}
$comment_parent = null;
list($type, $parent_id) = explode('_', $reply->post, 2);
switch ($type) {
case 'post':
$post = get_post($parent_id);
break;
case 'comment':
$comment_parent = get_comment($parent_id);
if (empty($comment_parent)) {
return $value;
}
$post = get_post($comment_parent->comment_post_ID);
break;
default:
return $value;
}
if (!$this->is_allowed_type($post->post_type)) {
return $value;
}
$user = $reply->get_user();
if (!$reply->is_valid()) {
Falcon::notify_invalid($user, $post->post_title);
return new WP_Error('falcon.connector.wordpress.invalid_reply');
}
$data = array('comment_post_ID' => $post->ID, 'user_id' => $user->ID, 'comment_author' => $user->display_name, 'comment_author_email' => $user->user_email, 'comment_author_url' => $user->user_url, 'comment_content' => $reply->parse_body());
if (!empty($comment_parent)) {
$data['comment_parent'] = $comment_parent->comment_ID;
}
return wp_insert_comment($data);
}