在发布评论之前,如何使Wordpress评论复选框为必需/必需?

我禁用了Wordpress功能“显示评论cookie启用复选框,允许设置评论作者的cookie”。但是我在注释表单中手动添加了一个复选框,因为我想更改复选框的标签。


我通过将以下代码添加到我的子主题的functions.php中来做到这一点:


add_filter( 'comment_form_default_fields', 'tu_comment_form_change_cookies_consent' );

function tu_comment_form_change_cookies_consent( $fields ) {

    $commenter = wp_get_current_commenter();


    $consent   = empty( $commenter['comment_author_email'] ) ? '' : ' checked="checked"';


    $fields['cookies'] = '<p class="comment-form-cookies-consent"><input id="wp-comment-cookies-consent" name="wp-comment-cookies-consent" type="checkbox" value="yes"' . $consent . ' />' .

                     '<label for="wp-comment-cookies-consent">By using this comment form you agree with our Privacy Policy</label></p>';

    return $fields;


}

这项工作正常,但现在我要强制使用此复选框,以便用户必须在按下“发布评论”按钮之前对其进行检查。


因此,如果未选中此复选框,则用户在单击“发布评论”按钮时应该会看到错误消息。


我怎样才能做到这一点?到目前为止,我发现的所有建议都行不通,例如在输入ID或名称后添加“ required”。


慕运维8079593
浏览 201回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP