public function handle_insert($value, Falcon_Reply $reply) { if (!empty($value)) { return $value; } $post = get_post($reply->post); if (!$this->is_allowed_type($post->post_type)) { return $value; } $user = $reply->get_user(); if ($reply->is_valid()) { Falcon::notify_invalid($user, bbp_get_topic_title($reply->post)); return false; } $new_reply = array('post_parent' => $reply->post, 'post_author' => $user->ID, 'post_content' => $reply->parse_body(), 'post_title' => $reply->subject); $meta = array('author_ip' => '127.0.0.1', 'forum_id' => bbp_get_topic_forum_id($reply->post), 'topic_id' => $reply->post); $reply_id = bbp_insert_reply($new_reply, $meta); do_action('bbp_new_reply', $reply_id, $meta['topic_id'], $meta['forum_id'], false, $new_reply['post_author']); // bbPress removes the user's subscription because bbp_update_reply() is hooked to 'bbp_new_reply' and it checks for $_POST['bbp_topic_subscription'] bbp_add_user_subscription($new_reply['post_author'], $meta['topic_id']); return $reply_id; }
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); }