/** * Update status of activities if parent status get updated. * @param string $new_status New status of post. * @param string $old_status Previous status of post. * @param object $post Post object. */ public function change_activity_status($new_status, $old_status, $post) { if ('question' == $post->post_type) { ap_update_activities(array('question_id' => $post->ID, 'parent_type' => 'post'), array('status' => $new_status)); } elseif ('answer' == $post->post_type) { ap_update_activities(array('answer_id' => $post->ID, 'parent_type' => 'post'), array('status' => $new_status)); } }
/** * Change status of post activity. * @param integer $post_id Post id. * @param string $status Activity status. * @return boolean|integer */ function ap_change_post_activities_status($post_id, $status) { $postarr = get_post($post_id); if (!$postarr) { return; } $status = sanitize_text_field($status); $where = array(); $columns = array(); if ('question' == $postarr->post_type) { $where['question_id'] = $post_id; $columns['status'] = $status; } elseif ('answer' == $postarr->post_type) { $where['answer_id'] = $post_id; $where['question_id'] = $postarr->post_parent; $columns['status'] = $status; } return ap_update_activities($where, $columns); }
/** * Change status of comment after comment is untrashed * @param object $comment Comment object. */ public function comment_approved($comment) { $post = get_post($comment->comment_post_ID); if (!('question' == $post->post_type || 'answer' == $post->post_type)) { return; } return ap_update_activities(array('item_id' => $comment->comment_ID, 'parent_type' => 'comment'), array('status' => 'publish')); }