0
我有一个应用程序,我试图访问需要登录的安全Wordpress网页。我发现Wordpress codex上的一些代码,我认为会强制登录,但它似乎没有做任何事情。我希望从用户不存在的角度来说,我可以强制登录。强制登录Wordpress网站
function custom_login() {
$creds = array();
$creds['user_login'] = 'myusername';
$creds['user_password'] = 'mypassword';
$creds['remember'] = true;
$user = wp_signon($creds, false);
if (is_wp_error($user))
echo $user->get_error_message();
}
function download_page()
{
global $wpdb;
$user = wp_get_current_user();
if (!($user->exists())) {
custom_login();
}else{
return '<p>You\'re not logged in! <br /> <a style="color:#ffa200;" href="'. get_page_link(39) . '">Click here </a>' .
'to login and download products that you\'ve purchased.';
}
}