Viewing 1 replies (of 1 total)
  • Plugin Author Ali Qureshi

    (@parorrey)

    This question is not related to this plugin but here’s the answer.

    To post comment the way you want it, use following post_comment method, you can add this in respond.php file. This can’t be done with the JSON API respond controller submit_comment method.

    function post_comment(){
    	   global $json_api;
    
     if ( !$json_api->query->post_id ) {
          $json_api->error("No post specified. Include 'post_id' var in your request.");
        } 
    
    if ( !$json_api->query->user_id )  {
          $json_api->error("Please include 'user_id' var in your request.");
        }
    
     if (!$json_api->query->content ) {
          $json_api->error("Please include 'content' var in your request.");
        }
    
    	$user_info = get_userdata( $json_api->query->user_id );
    
    	 $time = current_time('mysql');
    	 $agent = $_SERVER['HTTP_USER_AGENT'];
    	 $ip=$_SERVER['REMOTE_ADDR'];
    
    $data = array(
        'comment_post_ID' => $json_api->query->post_id,
        'comment_author' => $user_info->user_login,
        'comment_author_email' => $user_info->user_email,
        'comment_author_url' => $user_info->user_url,
        'comment_content' => $json_api->query->content,
        'comment_type' => '',
        'comment_parent' => 0,
        'user_id' => $user_info->ID,
        'comment_author_IP' =>  $ip,
        'comment_agent' => $agent,
        'comment_date' => $time,
        'comment_approved' => 1,
    );
    
    //print_r($data);
    
    $comment_id = wp_insert_comment($data);
    return array(
    			"status" => 'ok',
                "comment_id" => $comment_id
                 );
      }
Viewing 1 replies (of 1 total)
  • The topic ‘JSON API Auth Plugin not working for Add Comment’ is closed to new replies.