【发布时间】:2018-03-02 12:32:30
【问题描述】:
所以我想做的是:在用户可以提交链接的页面上有一个提交字段,成功提交后用户将被重定向到注册页面,成功注册后他之前提交的链接将出现在他的个人资料中。这怎么可能?任何可能做到这一点的插件?谢谢!任何事情都会有帮助!
【问题讨论】:
标签: wordpress form-submit registration profile
所以我想做的是:在用户可以提交链接的页面上有一个提交字段,成功提交后用户将被重定向到注册页面,成功注册后他之前提交的链接将出现在他的个人资料中。这怎么可能?任何可能做到这一点的插件?谢谢!任何事情都会有帮助!
【问题讨论】:
标签: wordpress form-submit registration profile
流程是这样的:
$_POST
$_POST读取提交链接的值,并预填一个<input type="hidden">字段wp_user_create和add_user_meta函数设置个人资料。我认为使用插件是多余的,尤其是因为 WP 插件通常质量不是很高。
这是没有任何验证的准系统示例。请不要按原样使用。
<?php
/**
* Template Name: Custom registration
*/
// If the link info is missing, go back to the link submission page
$link = false;
if (!isset($_POST['user_submitted_link']) || !isset($_POST['user_link'])) {
wp_redirect('/link-submission-page');
} else {
$link = isset($_POST['user_submitted_link']) ? $_POST['user_submitted_link'] : $_POST['user_link'];
}
// If the registration form was submitted
// the $_POST['user_link'] will be set and we can
// register the user
if (isset($_POST['user_link'])) {
$new_user = wp_create_user($_POST['email'], $_POST['password'], $_POST['email']);
if ($new_user) {
add_user_meta($new_user, 'user_link', $_POST['user_link']);
// User account is created, you can redirect to login or do whatever here
}
}
// Render the registration form if we have a $link
if ($link) : ?>
<form action="<?php the_permalink(); ?>" method="POST">
<input type="email" name="email">
<input type="password" name="password">
<input type="hidden" name="user_link" value="<?= $_POST['user_submitted_link']; ?>">
<button>Register</button>
</form>
<?php endif;
所以这是一个自定义页面模板。将其保存为custom-register.php 或主题文件夹中的其他内容,然后在 WP 中创建一个新页面并使用右侧的页面模板下拉菜单选择此“自定义注册”模板。
为此,链接提交页面需要在名为 user_submitted_link 的字段中发布值。
这应该足以让您入门。这是未经测试的代码,没有任何保证。
【讨论】: