Пример #1
0
/**
 * Remove a follower
 * @param  integer 		$current_user_id 		Current user id
 * @param  integer 		$user_to_follow  		user id to unfollow
 * @return boolean
 */
function ap_remove_follower($current_user_id, $user_to_follow)
{
    $row = ap_remove_subscriber($user_to_follow, $current_user_id, 'u_all');
    if ($row !== false) {
        do_action('ap_removed_follower', $current_user_id, $user_to_follow);
    }
    return $row;
}
Пример #2
0
 public function subscribe()
 {
     $action_id = (int) $_POST['action_id'];
     $type = sanitize_text_field($_POST['type']);
     if (!wp_verify_nonce($_POST['__nonce'], 'subscribe_' . $action_id . '_' . $type)) {
         ap_send_json(ap_ajax_responce('something_wrong'));
         return;
     }
     if (!is_user_logged_in()) {
         ap_send_json(ap_ajax_responce('please_login'));
         return;
     }
     if ($type === 'category') {
         $subscribe_type = 'category';
     } elseif ($type === 'tag') {
         $subscribe_type = 'tag';
     } else {
         $subscribe_type = false;
     }
     $user_id = get_current_user_id();
     $is_subscribed = ap_is_user_subscribed($action_id, $user_id, $subscribe_type);
     if ($is_subscribed) {
         if ($subscribe_type === false) {
             $row = ap_remove_question_subscriber($action_id);
         } else {
             $row = ap_remove_subscriber($user_id, $action_id, $subscribe_type);
         }
         if (FALSE !== $row) {
             ap_send_json(ap_ajax_responce(array('message' => 'unsubscribed', 'action' => 'unsubscribed', 'container' => '#subscribe_' . $action_id . ' b', 'do' => 'updateHtml', 'html' => __('Follow question', 'ap'))));
         }
     } else {
         if ($subscribe_type === false) {
             ap_add_question_subscriber($action_id);
         } else {
             ap_add_subscriber($user_id, $action_id, $subscribe_type);
         }
         ap_send_json(ap_ajax_responce(array('message' => 'subscribed', 'action' => 'subscribed', 'container' => '#subscribe_' . $action_id . ' b', 'do' => 'updateHtml', 'html' => __('Unfollow question', 'ap'))));
     }
 }
Пример #3
0
 /**
  * Process ajax subscribe request.
  */
 public function subscribe()
 {
     $action_id = (int) $_POST['args'][0];
     $type = sanitize_text_field($_POST['args'][1]);
     if (!ap_verify_nonce('subscribe_' . $action_id . '_' . $type)) {
         $this->something_wrong();
     }
     if (!is_user_logged_in()) {
         $this->send('please_login');
     }
     $question_id = 0;
     if ('tax_new_q' === $type) {
         $subscribe_type = 'tax_new_q';
     } else {
         $subscribe_type = 'q_all';
         $question_id = $action_id;
     }
     $user_id = get_current_user_id();
     $is_subscribed = ap_is_user_subscribed($action_id, $subscribe_type, $user_id);
     $elm = '#subscribe_' . $action_id . ' .ap-btn';
     if ($is_subscribed) {
         $row = ap_remove_subscriber($action_id, $user_id, $subscribe_type);
         if (false !== $row) {
             $count = ap_subscribers_count($action_id, $subscribe_type);
             $this->send(array('message' => 'unsubscribed', 'action' => 'unsubscribed', 'do' => array('updateHtml' => $elm . ' .text', 'toggle_active_class' => $elm), 'count' => $count, 'html' => __('Follow', 'anspress-question-answer'), 'view' => array('subscribe_' . $action_id => $count)));
         }
     } else {
         $row = ap_new_subscriber($user_id, $action_id, $subscribe_type, $question_id);
         if (false !== $row) {
             $count = ap_subscribers_count($action_id, $subscribe_type);
             $this->send(array('message' => 'subscribed', 'action' => 'subscribed', 'do' => array('updateHtml' => '#subscribe_' . $action_id . ' .text', 'toggle_active_class' => $elm), 'count' => $count, 'html' => __('Unfollow', 'anspress-question-answer'), 'view' => array('subscribe_' . $action_id => $count)));
         }
     }
     $this->something_wrong();
 }
Пример #4
0
/**
 * Unscubscribe user from a question
 * @param  integer  $question_id Questions ID
 * @param  boolean|integer $user_id
 * @return boolean|array
 */
function ap_remove_question_subscriber($question_id, $user_id = false)
{
    $is_subscribed = ap_is_user_subscribed($question_id);
    if ($user_id === false) {
        $user_id = get_current_user_id();
    }
    if ($is_subscribed) {
        ap_remove_subscriber($user_id, $question_id);
        $counts = ap_subscribers_count($question_id);
        //update post meta
        update_post_meta($question_id, ANSPRESS_SUBSCRIBER_META, $counts);
        return array('count' => $counts, 'action' => 'unsubscribed');
    }
    return false;
}
Пример #5
0
 /**
  * Remove answer subscriptions before delete
  * @param  integer $answer_id answer ID.
  */
 public function delete_answer($answer_id)
 {
     ap_remove_subscriber($answer_id, false, 'a_all');
 }