我目前正在使用wordpress开发一个网站;buddypress。我的目标是在个人资料页面中显示一个复选框,其中包括接受"使用条款"。这个点没问题。但是我想强制用户选中这个复选框,否则他可以离开页面(或者验证更改)。wp-admin部分(Users> profile配置)中"required file"的"mandatory"选项效率不高。
你有什么建议吗?
Thank you
你想多强地执行这个?如果成员无论如何都必须同意条款,如果条款尚未达成一致,您可以简单地重定向到他们的个人资料页面
function redirect_to_terms() {
if ( is_user_logged_in() && $terms_not_agreed ) {
bp_core_add_message( 'You must agree to our terms', 'error' );
wp_redirect( '/members/' . bp_core_get_username( bp_loggedin_user_id() ) );
exit();
}
}
add_action( 'template_redirect', 'redirect_to_terms' );
注意:您需要在代码的前面将true
或false
分配给$terms_not_agreed
。