Пример #1
0
 /**
  * Process follow ajax callback
  */
 public function follow()
 {
     $user_to_follow = (int) $_POST['user_id'];
     $current_user_id = get_current_user_id();
     if (!ap_verify_nonce('follow_' . $user_to_follow . '_' . $current_user_id)) {
         $this->something_wrong();
     }
     if (!is_user_logged_in()) {
         $this->send('please_login');
     }
     if ($user_to_follow == $current_user_id) {
         $this->send('cannot_follow_yourself');
     }
     $is_following = ap_is_user_following($user_to_follow, $current_user_id);
     $elm = '#follow_' . $user_to_follow;
     if ($is_following) {
         ap_remove_follower($current_user_id, $user_to_follow);
         $this->send(array('message' => 'unfollow', 'action' => 'unfollow', 'do' => array('updateText' => array($elm, __('Follow', 'anspress-question-answer')), 'toggle_active_class' => $elm)));
     } else {
         ap_add_follower($current_user_id, $user_to_follow);
         $this->send(array('message' => 'follow', 'action' => 'follow', 'do' => array('updateText' => array('#follow_' . $user_to_follow, __('Unfollow', 'anspress-question-answer')), 'toggle_active_class' => $elm)));
     }
 }
Пример #2
0
 public function follow()
 {
     $user_to_follow = (int) $_POST['user_id'];
     $current_user_id = get_current_user_id();
     if (!wp_verify_nonce($_POST['__nonce'], 'follow_' . $user_to_follow . '_' . $current_user_id)) {
         ap_send_json(ap_ajax_responce('something_wrong'));
         return;
     }
     if (!is_user_logged_in()) {
         ap_send_json(ap_ajax_responce('please_login'));
         return;
     }
     if ($user_to_follow == $current_user_id) {
         ap_send_json(ap_ajax_responce('cannot_follow_yourself'));
         return;
     }
     $is_following = ap_is_user_following($user_to_follow, $current_user_id);
     if ($is_following) {
         ap_remove_follower($current_user_id, $user_to_follow);
         ap_send_json(ap_ajax_responce(array('message' => 'unfollow', 'action' => 'unfollow', 'container' => '#follow_' . $user_to_follow, 'do' => 'updateText', 'text' => __('Follow', 'ap'))));
         return;
     } else {
         ap_add_follower($current_user_id, $user_to_follow);
         ap_send_json(ap_ajax_responce(array('message' => 'follow', 'action' => 'follow', 'container' => '#follow_' . $user_to_follow, 'do' => 'updateText', 'text' => __('Unfollow', 'ap'))));
     }
 }