WordPress 不允许注册某些用户名或使用某些字段

对于开发注册的 WordPress 站点,需要限制用户所注册的用户名。比如你要保留某些用户名,或者防止他人注册一些包含特定字段的用户名来进行欺诈。Restrict Usernames 插件就是用来实现这个的,它可以限制用户名使用空格,禁止注册某些用户名,禁止用户名包含某些字段,或者强制用户名必须包含某些字段等。

restrict-usernames-wpdaxue_com

Restrict Usernames 还预留了一个 c2c_restrict_usernames-validate 钩子,你可以点击设置页面右上角的“帮助”进行查看,范例如下:

/**
  * Add custom checks on usernames.
  *
  * Specifically, prevent use of usernames ending in numbers.
  */
	function my_restrict_usernames_check( $valid, $username, $options ) {
		// Only do additional checking if the plugin has already performed its
		// checks and deemed the username valid.
		if ( $valid ) {
			// 不允许用户名以数字结尾
			if ( preg_match( '/[0-9]+$/', $username ) )
				$valid = false;
		}
		return $valid;
	}
 add_filter( 'c2c_restrict_usernames-validate', 'my_restrict_usernames_check', 10, 3 );

如果你熟悉正则表达式的使用,就可以很好地使用这个挂钩来实现更加强大的功能。

在后台插件安装界面搜索 Restrict Usernames 即可在线安装,或者下载 Restrict Usernames

如果你不喜欢插件,可以试试代码方法:WordPress 禁止用户注册某些用户名

来源:

https://www.wpdaxue.com/restrict-usernames.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_33181.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?