我已经创建了一个自定义登录页面(不是自定义原始登录页面),并使用以下代码登录用户:
if($_POST){
if (!empty($_POST[\'username\']) && !empty($_POST[\'password\'])) {
$creds = array(
\'user_login\' => $_POST[\'username\'],
\'user_password\' => $_POST[\'password\'],
\'remember\' => true
);
$login = wp_signon( $creds, false );
if ( is_wp_error( $login ) ) {
$exiturl = get_site_url().\'/account/auth\';
header("Location: $exiturl");
exit();
}
} else {
echo "access denied";
}
日志记录过程工作正常,但如果
an admin user 通过此表单登录,他们无法访问管理面板。他们成功登录并
can surf the website 但是他们
can\'t access admin panel 要做任何事情(写入、编辑、更改设置等)!
有什么我遗漏的吗?我需要做饼干什么的吗?!
SO网友:KoCo
我应该换衣服的false 到true 在队列中$login = wp_signon( $creds, false );
所以最终的工作代码是
if($_POST){
if (!empty($_POST[\'username\']) && !empty($_POST[\'password\'])) {
$creds = array(
\'user_login\' => $_POST[\'username\'],
\'user_password\' => $_POST[\'password\'],
\'remember\' => true
);
$login = wp_signon( $creds, true);
if ( is_wp_error( $login ) ) {
$exiturl = get_site_url().\'/account/auth\';
header("Location: $exiturl");
exit();
}
} else {
echo "access denied";
}