dongou2019 2016-02-06 16:49
浏览 36

关于单例,全局,wordpress和wordpress插件的Php范围问题

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?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度