我无法在api呼叫工作后获得wordpress json-api更新。我现在使用wordpress 3.8.1,json-api 1.1.1和json-api-auth 1.7。我使用wordpress json-api-auth插件为update_post api调用返回一个随机数和一个cookie。之后,我使用对update_post端点的调用来更新已存在的某个帖子。使用error_log cmd,我发现问题在于这段代码:
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 }
对is_user_logged_in()的调用返回false,因为$ current_user == 0,但我根据api登录。我试图在generate_auth_cookie(wp-content / plugins / json-api-auth / controllers / Auth.php)中创建一个json_user全局变量,并将其设置为set_posts_query函数中的current_user变量(wp-content / plugins / json- api / singletons / introspector.php)在调用wp-includes / query.php中的query_posts函数之前。 error_log返回$ current_user-> $ current_user = $ json_user后ID仍为零。我确信有一些我想念的东西,我的解决方法可能很糟糕。如何将$ current_user对象更改为0以外的其他对象?