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.
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() .
Example:
function ref_access() {
global $error;
if (is_user_logged_in()) {
// process form here.
}else {
$error = "Hey, get out of here";
return ;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.