我尝试在使用时使用密码注册后自动登录wordpressWP-Members 插件。
我没有博客,所以我决定把它写在这里,这样可能会对某人有所帮助。我并不擅长编写wordpress插件。我花了一些时间才找到它。
当然,如果您在插件的设置中添加自定义字段(option\\u name=password),这会起作用。
在文件wp成员中。登记php在函数*wpmem\\u注册($切换)*我已经替换了这一行:
return "success"; exit();
使用文件wp members core中函数*wpmem\\u login()*中的代码。php:
/** assemble login credentials */
$creds = array();
$creds[\'user_login\'] = $username;
$creds[\'user_password\'] = $password;
$creds[\'remember\'] = true;
/** wp_signon the user and get the $user object */
$user = wp_signon( $creds, false );
/** if no error, user is a valid signon. continue */
if( ! is_wp_error( $user ) ) {
/** set the auth cookie */
wp_set_auth_cookie( $user->ID, true );
/** determine where to put the user after login */
$redirect_to = $_SERVER[\'PHP_SELF\'];
if( isset( $_POST[\'redirect_to\'] ) ) {
$redirect_to = $_POST[\'redirect_to\'];
}
/** apply wpmem_login_redirect filter */
$redirect_to = apply_filters( \'wpmem_login_redirect\', $redirect_to );
/** and do the redirect */
wp_redirect( $redirect_to );
/** wp_redirect requires us to exit() */
exit();
} else {
return "loginfailed";
}
这安全吗?能不能用更好的方法?
SO网友:Adam
我不确定我是否正确地理解了您,但您不应该编辑核心插件文件,相反,您应该利用WP成员提供的可用挂钩和过滤器,例如,创建您自己的插件或更简单地使用您的函数。php文件来修改其行为。
add_action( \'wpmem_register_redirect\', \'my_reg_redirect\' );
function my_reg_redirect()
{
// NOTE: this is an action hook that uses wp_redirect
// wp_redirect must end with exit();
wp_redirect( \'http://example.com/my-page/\' );
exit();
}
也取自
this link,
Suppose that you do not want users to have instant access to the site upon a successful registration, 但是,您希望手动验证您是否拥有合法用户。在这些情况下,WP成员™ 允许您调节注册,要求管理员在访问之前“激活”用户。
这似乎是插件本身的一个选项,可以适度注册或不适度注册,后者将在成功注册时自动登录用户,而前者如果启用,将要求用户通过电子邮件激活其帐户或管理员批准其帐户。