如何要求用户登录才能提交输入?
我发现了这段代码,不确定如何修改它以满足我的需求:
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.';
}
此输入将发布到MySQL数据库中。
这是我的插件中的输入代码:
<input type="text" maxlength="4" name="' . $quanid . '" value="" class="input" />
截至目前,任何人都可以提交此文件,无论登录状态如何。
您可以使用Wordpress的内置函数:is_user_loged_in()。
示例:
function ref_access() {
global $error;
if (is_user_logged_in()) {
// process form here.
}else {
$error = "Hey, get out of here";
return ;
}
}