コード例 #1
0
ファイル: vote.php プロジェクト: VLabsInc/WordPressPlatforms
 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'))));
     }
 }
コード例 #2
0
ファイル: hooks.php プロジェクト: kevinfodness/anspress
 /**
  * Action triggred after unpublishing a comment.
  * @param  object|array $comment Comment obejct.
  */
 public function unpublish_comment($comment)
 {
     $comment = (object) $comment;
     $post = get_post($comment->comment_post_ID);
     if ($post->post_type == 'question') {
         ap_remove_question_subscriber($post->ID, $comment->user_id);
     } elseif ($post->post_type == 'answer') {
         $post_id = wp_get_post_parent_id($comment->comment_post_ID);
         ap_remove_question_subscriber($post_id, $comment->user_id);
     }
 }