问题描述
我正在查看本指南 https://www.pirenko.com/creating-wordpress-auto-login-links/ 并尝试将其调整为使用 customer-invoice.PHP 模板的报价邮件。
问题:
$secret_string=wp_generate_password( 8,false );
$login_link ='http://website.com/wp-json/sand_login/prk_route?username='.$username.'&secret='.$user_info->secret_key;
我首先删除了对密钥的检查,只是想看看我是否可以让它与电子邮件地址一起工作,并添加了一个重定向到结帐。一旦我可以在当前用户元数据上更新安全密钥,我将添加对安全密钥的检查。
add_action( 'rest_api_init',function () {
register_rest_route(
'sand_login','prk_route',array(
'methods' => 'GET','callback' => 'pirenko_login_user',)
);
});
function pirenko_login_user() {
// Validate input
if (isset($_GET['username']) && $_GET['username']!="") {
$username = $_GET['username'];
$user = get_user_by('email',$username );
if ($user) {
//Check if secret key matches
$check_user = get_user_by( 'id',$user->ID );
//Login info is correct - let's proceed
// Manage login cookies
wp_clear_auth_cookie();
wp_set_current_user ( $user->ID );
wp_set_auth_cookie ( $user->ID );
// Finally redirect user
$order = new WC_Order($order_id);
$payment_page = $order->get_checkout_payment_url($order->ID);
wp_safe_redirect( $payment_page );
exit();
}
else {
echo "Could not find user!";
exit();
}
}
else {
echo "Parameters are missing!";
exit();
}
}
customer-invoice.PHP 中的电子邮件函数如下所示:
if ($order && $order->has_status('enquiry')) {
$email_text = str_replace('{betaallink}','<a class="payment" href="' . esc_url($order->get_checkout_payment_url()) . '">',$email_text);
$email_text = str_replace('{/betaallink}','</a>',$email_text);
}
我更新到这个,没有开始的秘钥:
if ($order && $order->has_status('enquiry')) {
$user = $order->get_user();
$username = $user ? $user->__get('user_email') : '';
$login_link ='http://website.com/wp-json/sand_login/prk_route?username='.$username;
$email_text = str_replace('{betaallink}','<a class="payment" href="'. $login_link .'">',$email_text);
}
这有效。用户登录并使用此 URL 重定向到购物车,其中包含用户注册的所有未结订单:
https://website.com/afrekenen/order-pay/?pay_for_order=true&key
我这样做是完全错误的吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)