簡體   English   中英

需要用戶登錄才能提交表格

[英]Require user login to submit form

我如何要求用戶登錄才能提交輸入?

我找到了這段代碼,不確定如何修改它以滿足我的需要:

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_logged_in()

例:

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM