Next we will share with you a method for registering WordPress website users to block illegal keyword usernames.
Add the following two codes to the functions. Php file:
The code is as follows: |
Copy code |
Function uedsc_user_blacklist_check ($ str ){ $ Moderation_keys = trim (get_option ('moderation _ keys ')); $ Blacklist_keys = trim (get_option ('Blacklist _ keys ')); $ Keys = $ moderation_keys. "\ n". $ blacklist_keys; $ Words = explode ("\ n", $ keys ); Foreach (array) $ words as $ word ){ $ Word = trim ($ word ); If (empty ($ word )) Continue; $ Word = preg_quote ($ word ,'#'); $ Pattern = "# $ word # I "; If (preg_match ($ pattern, $ str) return true; } Return false; } Add_filter ('sanitize _ user', 'uedsc _ sanitize_user ', 3, 3 ); Function uedsc_sanitize_user ($ username, $ raw_username, $ strict ){ If (uedsc_user_blacklist_check ($ username )){ $ Username = ''; } Return $ username; }
|
In the WordPress background> Settings> discussion, we enter the "review comment" and "blacklist comment" keywords to prevent users from registering sensitive keywords.