【问题标题】:php array to call wordpress get_current_user_infophp数组调用wordpress get_current_user_info
【发布时间】:2014-04-22 18:42:01
【问题描述】:

我已经阅读和调整代码三天了,但无法弄清楚。因为我是 php 新手。编写这个 php 登录脚本的开发人员没有为 WordPress 编写代码,也没有为我需要的自动登录编写代码。我想我已经弄清楚了我没有在这里发布的代码末尾的自动登录。

他为他的数组创建了这段代码,该代码将为三个永远不会改变的 api 字符串设置值,但我需要将登录的 WordPress 用户的用户名和密码包含在他的数组中。数组信息稍后在脚本中由 xml 传递。这是为了自动 SSL 登录到另一台服务器,当单击图像时,它会运行 php 代码。

这是我刚从他那里得到的代码,但我不相信它是正确的,因为我插入它时,Notepad++ 中的所有颜色都发生了变化:

// Set the Query POST parameters - array    
$query_vals = array(
'api_username' => 'api-username-goes-here',
'api_password' => 'password-here', 
'api_key' => 'api-key-here’,
'username' => $current_user[‘user_login’],
'password' => $current_user[‘user_pass’]        
);

我知道最后两行不可能是正确的。访问 WordPress 获取用户变量以与他的数组一起使用的正确代码是什么?

非常感谢任何帮助。

【问题讨论】:

标签: php arrays wordpress


【解决方案1】:

把‘改成’

// Set the Query POST parameters
$query_vals = array(
'api_username' => 'api-username-goes-here',
'api_password' => 'password-here', 
'api_key' => 'api-key-here',
'username' => $current_user['user_login'],
'password' => $current_user['user_pass']
);

【讨论】:

    【解决方案2】:

    您需要先在代码中的某处调用它:

    global $current_user;
    get_currentuserinfo();
    

    然后您需要将数组更改为如下内容:

    'username' => $current_user->user_login
    

    【讨论】:

    • 我看到的唯一问题是我不想搞砸需要传递给 xml 的开发人员代码的其他部分。您对此有何看法?
    • 您只是改变了在数组中设置值的方式。最终结果仍然是一个数组,所以它不应该搞砸任何东西。如果您担心原始文件,请备份它,以便在出现问题时快速修复。
    猜你喜欢
    • 1970-01-01
    • 2014-06-04
    • 1970-01-01
    • 1970-01-01
    • 2021-07-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-17
    相关资源
    最近更新 更多