[英]Require user login to submit form
How can I require that a user be logged in, in order to submit an input? 我如何要求用户登录才能提交输入?
I found this piece of code, not sure how I can modify it to suit my needs: 我找到了这段代码,不确定如何修改它以满足我的需要:
add_action('login_head','ref_access');
function ref_access() {
global $error;
if( !empty($_GET['ref']) && 'access' == $_GET['ref'] )
$error = 'Restricted area, please login to continue.';
}
This input will be posted to a MySQL database. 此输入将发布到MySQL数据库。
This is the input code as it stands in my plugin: 这是我插件中的输入代码:
<input type="text" maxlength="4" name="' . $quanid . '" value="" class="input" />
As of right now, anyone can submit this, regardless of login status. 截至目前,无论登录状态如何,任何人都可以提交。
You can use Wordpress's built in function for that: is_user_logged_in() . 您可以为此使用Wordpress的内置函数: is_user_logged_in() 。
Example: 例:
function ref_access() {
global $error;
if (is_user_logged_in()) {
// process form here.
}else {
$error = "Hey, get out of here";
return ;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.