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.';
}
}