I'm having trouble getting the wordpress json-api update post api call to work. I'm current on wordpress 3.8.1, json-api 1.1.1, and json-api-auth 1.7. I'm using the wordpress json-api-auth plugin to return a nonce and a cookie for update_post api call. After that, I use a call to the update_post endpoint to update a certain post that already exists. Using the error_log cmd, I have found that the issue lies in this block of code:
wp-includes/query.php (in the get_posts method)
2971 // Check post status to determine if post should be displayed.
2972 if ( !empty($this->posts) && ($this->is_single || $this->is_page) ) {
2973 $status = get_post_status($this->posts[0]);
2974 $post_status_obj = get_post_status_object($status);
2975 //$type = get_post_type($this->posts[0]);
2976 if ( !$post_status_obj->public ) {
2977 if ( ! is_user_logged_in() ) {
2978 // User must be logged in to view unpublished posts.
2979 $this->posts = array();
2980 } else {
2981 if ( $post_status_obj->protected ) {
2982 // User must have edit permissions on the draft to preview.
2983 if ( ! current_user_can($edit_cap, $this->posts[0]->ID) ) {
2984 $this->posts = array();
2985 } else {
2986 $this->is_preview = true;
2987 if ( 'future' != $status )
2988 $this->posts[0]->post_date = current_time('mysql');
2989 }
2990 } elseif ( $post_status_obj->private ) {
2991 if ( ! current_user_can($read_cap, $this->posts[0]->ID) )
2992 $this->posts = array();
2993 } else {
2994 $this->posts = array();
2995 }
2996 }
2997 }
The call to is_user_logged_in() is returning false because the $current_user == 0, but I am logged in according to the api. I have tried to create a json_user global variable in generate_auth_cookie (wp-content/plugins/json-api-auth/controllers/Auth.php) and set it to the current_user variable in the set_posts_query function (wp-content/plugins/json-api/singletons/introspector.php) before calling the query_posts function in the wp-includes/query.php. The error_log returns $current_user->ID is still zero after $current_user = $json_user. I'm sure that there is something I'm missing and my workaround idea could be terrible. How do I change the $current_user object to something other than 0?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire