WordPress用户链接提交
问题描述:
所以事情我想要做的是:有一个页面上提交场在那里用户可以提交一个链接,并成功的submition后用户将被重定向到注册页面,之后他submited succsesful注册链接前面会出现在他的个人资料。这怎么可能?任何插件可以做到这一点? Thans!任何事都会有帮助WordPress用户链接提交
答
流程是这样的:
- 创建自定义的注册页面
- 与链接的页面提交表单做了
$_POST
到自定义注册页面 - 注册页面读取的值提交的链接从
$_POST
和预填充<input type="hidden">
字段 - 当用户提交注册页面时,使用
wp_user_create
和add_user_meta
函数来设置profil即
我认为使用插件是过量的,特别是因为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
字段的值。
这应该足以让你开始。这是未经测试的代码,没有担保。
谢谢!我开始研究它。如果我以后有问题,我可以问你一些问题吗? –