wpDiscuz 7 API Documentation

  1. Home
  2. Docs
  3. wpDiscuz 7 API Documentation
  4. Actions
  5. wpdiscuz_before_wp_new_comment
Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors

wpdiscuz_before_wp_new_comment

This action allows you to perform tasks based on comment data. For example you can restrict registered users’ email addresses from being used by guests.

Changelog

Added starting from 7.6.28 version.

Parameters

1. $commentdata – the data of the newly added comment.

Usage

add_action("wpdiscuz_before_wp_new_comment", function($commentdata){
    if (!empty($commentdata["comment_author_email"]) && empty($commentdata["user_id"])) {
        $is_user_exist = get_user_by("email", sanitize_text_field($commentdata["comment_author_email"]));

        if ($is_user_exist) {
            wp_die(esc_html__("A user with this email is already registered! Please log in or use a different one!", "wpdiscuz"));
        }
    }
});

Was this article helpful to you? Yes No