/** * Actions to run after posting a comment * @param object|array $comment Comment object. */ public function publish_comment($comment) { if (ap_is_profile_active()) { $comment = (object) $comment; $post = get_post($comment->comment_post_ID); if ($post->post_type == 'question') { ap_insert_notification($comment->user_id, $post->post_author, 'comment_on_question', array('post_id' => $post->ID, 'comment_id' => $comment->comment_ID)); } elseif ($post->post_type == 'answer') { ap_insert_notification($comment->user_id, $post->post_author, 'comment_on_answer', array('post_id' => $post->ID, 'comment_id' => $comment->comment_ID)); } } }
/** * Insert notification about new follower * @param integer $user_to_follow Whom to follow. * @param integer $current_user_id Current user ID. */ public function notify_user_about_follower($user_to_follow, $current_user_id) { ap_insert_notification($current_user_id, $user_to_follow, 'new_follower'); }
public function ap_added_reputation($user_id, $action_id, $reputation, $type, $current_user_id) { ap_insert_notification($current_user_id, $user_id, 'received_reputation', array('reputation' => $reputation, 'type' => $type)); }
/** * Ajax action for selecting a best answer * @return void * @since 2.0.0 */ public function select_best_answer() { $answer_id = (int) $_POST['answer_id']; if (!is_user_logged_in()) { ap_send_json(ap_ajax_responce('no_permission')); return; } if (!wp_verify_nonce($_POST['__nonce'], 'answer-' . $answer_id)) { ap_send_json(ap_ajax_responce('something_wrong')); return; } $post = get_post($answer_id); $user_id = get_current_user_id(); if (ap_question_best_answer_selected($post->post_parent)) { do_action('ap_unselect_answer', $user_id, $post->post_parent, $post->ID); update_post_meta($post->ID, ANSPRESS_BEST_META, 0); update_post_meta($post->post_parent, ANSPRESS_SELECTED_META, false); update_post_meta($post->post_parent, ANSPRESS_UPDATED_META, current_time('mysql')); if (ap_opt('close_after_selecting')) { wp_update_post(array('ID' => $post->post_parent, 'post_status' => 'publish')); } ap_update_user_best_answers_count_meta($user_id); ap_update_user_solved_answers_count_meta($user_id); ap_send_json(ap_ajax_responce(array('message' => 'unselected_the_answer', 'action' => 'unselected_answer', 'do' => 'reload'))); } else { do_action('ap_select_answer', $user_id, $post->post_parent, $post->ID); update_post_meta($post->ID, ANSPRESS_BEST_META, 1); update_post_meta($post->post_parent, ANSPRESS_SELECTED_META, $post->ID); update_post_meta($post->post_parent, ANSPRESS_UPDATED_META, current_time('mysql')); if (ap_opt('close_after_selecting')) { wp_update_post(array('ID' => $post->post_parent, 'post_status' => 'closed')); } ap_update_user_best_answers_count_meta($user_id); ap_update_user_solved_answers_count_meta($user_id); ap_insert_notification($user_id, $post->post_author, 'answer_selected', array('post_id' => $post->ID)); $html = ap_select_answer_btn_html($answer_id); ap_send_json(ap_ajax_responce(array('message' => 'selected_the_answer', 'action' => 'selected_answer', 'do' => 'reload', 'html' => $html))); } }