• I want the email field in WordPress comments to allow only a specific email domain (eg: gmail) and restrict the rest with a message. Can anyone help me on this plz?

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    As we discussed in your related topic, ideally there’d be JavaScript or jQuery validation client side, with back up enforcement server side. The script can execute from the “onchange” event of the input field. Search for “@gmail.com” in the field’s value. Verify the sub-string’s location places it at the end of the field value string. If there is no such sub-string found, do some sort of error messaging. An alert box would be easy. Inserting a message into an otherwise empty div works well also. The script could also enable/disable the submit button as the situation warrants.

    Server side, hook the ‘preprocess_comment’ filter and verify “@gmail.com” again exists at the end of the passed value. If not, you can just wp_die(); with an error message to abort the comment processing. It’s a bit crude, but anyone getting the die message here had circumvented your client side script, so being a bit harsh here is not an issue IMO. Depending on how important enforcement is, you could decide to forego this part of enforcement, but it is the only reliable enforcement. The client side script is more for a nicer user experience than reliable enforcement.

Viewing 1 replies (of 1 total)
  • The topic ‘How to only allow specific email domain in comments?’ is closed to new replies.