简体   繁体   中英

wordpress login(set_current_user) makes error

I try to login an user in to wordpress/woocommerce with this code:

function login_user_in_wp ($user_id) {
    $user = set_current_user($user_id);
    wp_set_auth_cookie($user->ID, $remember);
    do_action('wp_login', $user->user_login);
}

It "works" and logs the user in. The problem is, that the page is making an error:

Warning: Missing argument 2 for wc_maybe_store_user_agent(), called in /Applications/MAMP/htdocs/shop/wp-includes/class-wp-hook.php on line 298 and defined in /Applications/MAMP/htdocs/shop/wp-content/plugins/woocommerce/includes/wc-core-functions.php on line 1551

Does anybody know why? I have newest version.

Thank you

I found the error:

function login_user_in_wp ($user_id) {
    $user = set_current_user($user_id);
    wp_set_auth_cookie($user->ID, $remember);
    do_action('wp_login', $user->user_login, 10, 2);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM