正在查看 5 个帖子:1-5 (共 5 个帖子)
-
作者帖子
-
Ultimate Member 能用中文注册吗?
注册时必须为英文或者数字,但是你可以把昵称设置为必填就好了。这样也算是中文名称注册。
特殊符号可以吗?
你试一下就知道了嘛,昵称填特殊符号应该可以的。
正好我也有这个需求,研究了半天搞出来了,记下来备份。
ultimate member 默认注册不支持中文,会报错,所以需要修改代码。
首先把注册表单调成这样。
然后找到文件 wp-content/plugins/ultimate-member/includes/core/um-actions-register
修改以下函数
function um_submit_form_register( $args ) { if ( isset( UM()->form()->errors ) ) return false; $displayname= $args['nickname'];//获取昵称,用作中文注册名称 /** * UM hook * * @type filter * @title um_add_user_frontend_submitted * @description Extend user data on registration form submit * @input_vars * [{"var":"$submitted","type":"array","desc":"Registration data"}] * @change_log * ["Since: 2.0"] * @usage * <!--?php add_filter( 'um_add_user_frontend_submitted', 'function_name', 10, 1 ); ?--> * @example * <!--?php * add_filter( 'um_add_user_frontend_submitted', 'my_add_user_frontend_submitted', 10, 1 ); * function my_add_user_frontend_submitted( $submitted ) { * // your code here * return $submitted; * } * ?--> */ $args = apply_filters( 'um_add_user_frontend_submitted', $args ); extract( $args ); if ( isset( $username ) && ! isset( $user_login ) ) { $user_login = $username; } if ( ! empty( $first_name ) && ! empty( $last_name ) && ! isset( $user_login ) ) { if ( UM()->options()->get( 'permalink_base' ) == 'name' ) { $user_login = rawurlencode( strtolower( str_replace( " ", ".", $first_name . " " . $last_name ) ) ); } elseif ( UM()->options()->get( 'permalink_base' ) == 'name_dash' ) { $user_login = rawurlencode( strtolower( str_replace( " ", "-", $first_name . " " . $last_name ) ) ); } elseif ( UM()->options()->get( 'permalink_base' ) == 'name_plus' ) { $user_login = strtolower( str_replace( " ", "+", $first_name . " " . $last_name ) ); } else { $user_login = strtolower( str_replace( " ", "", $first_name . " " . $last_name ) ); } // if full name exists $count = 1; while ( username_exists( $user_login ) ) { $user_login .= $count; $count++; } } if ( ! isset( $user_login ) && isset( $user_email ) && $user_email ) { $user_login = $user_email; } $unique_userID = UM()->query()->count_users() + 1; if ( ! isset( $user_login ) || strlen( $user_login ) > 30 && ! is_email( $user_login ) ) { $user_login = 'user' . $unique_userID; } if ( isset( $username ) && is_email( $username ) ) { $user_email = $username; } if ( ! isset( $user_password ) ) { $user_password = UM()->validation()->generate( 8 ); } if ( ! isset( $user_email ) ) { $site_url = @$_SERVER['SERVER_NAME']; $user_email = 'nobody' . $unique_userID . '@' . $site_url; /** * UM hook * * @type filter * @title um_user_register_submitted__email * @description Change user default email if it's empty on registration * @input_vars * [{"var":"$user_email","type":"string","desc":"Default email"}] * @change_log * ["Since: 2.0"] * @usage * <!--?php add_filter( 'um_user_register_submitted__email', 'function_name', 10, 1 ); ?--> * @example * <!--?php * add_filter( 'um_user_register_submitted__email', 'my_user_register_submitted__email', 10, 1 ); * function my_user_register_submitted__email( $user_email ) { * // your code here * return $user_email; * } * ?--> */ $user_email = apply_filters( 'um_user_register_submitted__email', $user_email ); } $credentials = array( 'user_login' => $user_login, 'user_password' => $user_password, 'user_email' => trim( $user_email ), ); $args['submitted'] = array_merge( $args['submitted'], $credentials ); $args = array_merge( $args, $credentials ); //get user role from global or form's settings $user_role = UM()->form()->assigned_role( UM()->form()->form_id ); //get user role from field Role dropdown or radio if ( isset( $args['role'] ) ) { global $wp_roles; $um_roles = get_option( 'um_roles' ); if ( ! empty( $um_roles ) ) { $role_keys = array_map( function( $item ) { return 'um_' . $item; }, get_option( 'um_roles' ) ); } else { $role_keys = array(); } $exclude_roles = array_diff( array_keys( $wp_roles->roles ), array_merge( $role_keys, array( 'subscriber' ) ) ); //if role is properly set it if ( ! in_array( $args['role'], $exclude_roles ) ) { $user_role = $args['role']; } } /** * UM hook * * @type filter * @title um_registration_user_role * @description Change user role on registration process * @input_vars * [{"var":"$role","type":"string","desc":"User role"}, * {"var":"$submitted","type":"array","desc":"Registration data"}] * @change_log * ["Since: 2.0"] * @usage * <!--?php add_filter( 'um_registration_user_role', 'function_name', 10, 2 ); ?--> * @example * <!--?php * add_filter( 'um_registration_user_role', 'my_registration_user_role', 10, 2 ); * function my_user_register_submitted__email( $role, $submitted ) { * // your code here * return $role; * } * ?--> */ $user_role = apply_filters( 'um_registration_user_role', $user_role, $args ); $userdata = array( 'user_login' => $user_login, 'user_pass' => $user_password, 'user_email' => $user_email, 'role' => $user_role, 'display_name' => $displayname,//允许中文名称注册,将昵称作为用户名 ); $user_id = wp_insert_user( $userdata ); /** * UM hook * * @type action * @title um_user_register * @description After complete UM user registration. * @input_vars * [{"var":"$user_id","type":"int","desc":"User ID"}, * {"var":"$args","type":"array","desc":"Form data"}] * @change_log * ["Since: 2.0"] * @usage add_action( 'um_user_register', 'function_name', 10, 2 ); * @example * <!--?php * add_action( 'um_user_register', 'my_user_register', 10, 2 ); * function my_user_register( $user_id, $args ) { * // your code here * } * ?--> */ do_action( 'um_user_register', $user_id, $args ); return $user_id; }
这样就支持中文了,bbpress 右侧栏小工具也能默认显示中文了。
-
作者帖子
正在查看 5 个帖子:1-5 (共 5 个帖子)
- 哎呀,回复话题必需登录。