首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在WordPress中,这些代码块之间有什么区别?

在WordPress中,这些代码块之间有什么区别?
EN

Stack Overflow用户
提问于 2015-03-16 16:27:26
回答 2查看 45关注 0票数 0

这不起作用:

代码语言:javascript
复制
$simple_local_avatars = new Simple_Local_Avatars;

if(isset($_POST['save_account_details'] ) ) {
    $user_id = get_current_user_id();
    $simple_local_avatars->edit_user_profile_update($user_id);
}

但这是有效的,只是不是动态的:

代码语言:javascript
复制
$simple_local_avatars = new Simple_Local_Avatars;

if(isset($_POST['save_account_details'] ) ) {
    $simple_local_avatars->edit_user_profile_update(58);
}

edit_user_profile_update函数需要当前登录的用户id。

EN

回答 2

Stack Overflow用户

发布于 2015-03-16 16:31:36

您的第一个代码块无法检索用户id,而第二个代码块可以。尝试在您的第一个$user_idecho,它将是空的。

换句话说:get_current_user_id();不返回任何内容。它是空的。

编辑:

代码语言:javascript
复制
if(isset($_POST['save_account_details'] ) ) {
    $user_id = get_current_user_id();
    echo $user_id;
    $simple_local_avatars->edit_user_profile_update($user_id);
}
票数 2
EN

Stack Overflow用户

发布于 2015-03-16 16:49:32

目前似乎还没有用户登录,这就是为什么你会得到0作为返回的用户id。

因此,尝试类似这样的操作,以确保用户已登录:

编辑:

代码语言:javascript
复制
    if(isset($_POST['save_account_details'] ) ) {
        global $current_user;
        get_currentuserinfo();
        $user_id = $current_user->ID;
         if($user_id){
           $simple_local_avatars->edit_user_profile_update($user_id);
         }else{
                wp_die("Please log in first.");
         }

}

希望它能帮助你..

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29072372

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档