wp_filter_comment

The timeline below displays how wordpress function wp_filter_comment has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.1

/**
 * Filters and sanitizes comment data.
 *
 * Sets the comment data 'filtered' field to true when finished. This can be
 * checked as to whether the comment should be filtered and to keep from
 * filtering the same comment more than once.
 *
 * @since 2.0.0
 *
 * @param array $commentdata Contains information on the comment.
 * @return array Parsed comment information.
 */
function wp_filter_comment($commentdata)
{
    if (isset($commentdata['user_ID'])) {
        /**
         * Filters the comment author's user ID before it is set.
         *
         * The first time this filter is evaluated, `user_ID` is checked
         * (for back-compat), followed by the standard `user_id` value.
         *
         * @since 1.5.0
         *
         * @param int $user_id The comment author's user ID.
         */
        $commentdata['user_id'] = apply_filters('pre_user_id', $commentdata['user_ID']);
    } elseif (isset($commentdata['user_id'])) {
        /** This filter is documented in wp-includes/comment.php */
        $commentdata['user_id'] = apply_filters('pre_user_id', $commentdata['user_id']);
    }
    /**
     * Filters the comment author's browser user agent before it is set.
     *
     * @since 1.5.0
     *
     * @param string $comment_agent The comment author's browser user agent.
     */
    $commentdata['comment_agent'] = apply_filters('pre_comment_user_agent', isset($commentdata['comment_agent']) ? $commentdata['comment_agent'] : '');
    /** This filter is documented in wp-includes/comment.php */
    $commentdata['comment_author'] = apply_filters('pre_comment_author_name', $commentdata['comment_author']);
    /**
     * Filters the comment content before it is set.
     *
     * @since 1.5.0
     *
     * @param string $comment_content The comment content.
     */
    $commentdata['comment_content'] = apply_filters('pre_comment_content', $commentdata['comment_content']);
    /**
     * Filters the comment author's IP address before it is set.
     *
     * @since 1.5.0
     *
     * @param string $comment_author_ip The comment author's IP address.
     */
    $commentdata['comment_author_IP'] = apply_filters('pre_comment_user_ip', $commentdata['comment_author_IP']);
    /** This filter is documented in wp-includes/comment.php */
    $commentdata['comment_author_url'] = apply_filters('pre_comment_author_url', $commentdata['comment_author_url']);
    /** This filter is documented in wp-includes/comment.php */
    $commentdata['comment_author_email'] = apply_filters('pre_comment_author_email', $commentdata['comment_author_email']);
    $commentdata['filtered'] = true;
    return $commentdata;
}

WordPress Version: 5.5

/**
 * Filters and sanitizes comment data.
 *
 * Sets the comment data 'filtered' field to true when finished. This can be
 * checked as to whether the comment should be filtered and to keep from
 * filtering the same comment more than once.
 *
 * @since 2.0.0
 *
 * @param array $commentdata Contains information on the comment.
 * @return array Parsed comment information.
 */
function wp_filter_comment($commentdata)
{
    if (isset($commentdata['user_ID'])) {
        /**
         * Filters the comment author's user ID before it is set.
         *
         * The first time this filter is evaluated, 'user_ID' is checked
         * (for back-compat), followed by the standard 'user_id' value.
         *
         * @since 1.5.0
         *
         * @param int $user_ID The comment author's user ID.
         */
        $commentdata['user_id'] = apply_filters('pre_user_id', $commentdata['user_ID']);
    } elseif (isset($commentdata['user_id'])) {
        /** This filter is documented in wp-includes/comment.php */
        $commentdata['user_id'] = apply_filters('pre_user_id', $commentdata['user_id']);
    }
    /**
     * Filters the comment author's browser user agent before it is set.
     *
     * @since 1.5.0
     *
     * @param string $comment_agent The comment author's browser user agent.
     */
    $commentdata['comment_agent'] = apply_filters('pre_comment_user_agent', isset($commentdata['comment_agent']) ? $commentdata['comment_agent'] : '');
    /** This filter is documented in wp-includes/comment.php */
    $commentdata['comment_author'] = apply_filters('pre_comment_author_name', $commentdata['comment_author']);
    /**
     * Filters the comment content before it is set.
     *
     * @since 1.5.0
     *
     * @param string $comment_content The comment content.
     */
    $commentdata['comment_content'] = apply_filters('pre_comment_content', $commentdata['comment_content']);
    /**
     * Filters the comment author's IP address before it is set.
     *
     * @since 1.5.0
     *
     * @param string $comment_author_ip The comment author's IP address.
     */
    $commentdata['comment_author_IP'] = apply_filters('pre_comment_user_ip', $commentdata['comment_author_IP']);
    /** This filter is documented in wp-includes/comment.php */
    $commentdata['comment_author_url'] = apply_filters('pre_comment_author_url', $commentdata['comment_author_url']);
    /** This filter is documented in wp-includes/comment.php */
    $commentdata['comment_author_email'] = apply_filters('pre_comment_author_email', $commentdata['comment_author_email']);
    $commentdata['filtered'] = true;
    return $commentdata;
}

WordPress Version: 4.9

/**
 * Filters and sanitizes comment data.
 *
 * Sets the comment data 'filtered' field to true when finished. This can be
 * checked as to whether the comment should be filtered and to keep from
 * filtering the same comment more than once.
 *
 * @since 2.0.0
 *
 * @param array $commentdata Contains information on the comment.
 * @return array Parsed comment information.
 */
function wp_filter_comment($commentdata)
{
    if (isset($commentdata['user_ID'])) {
        /**
         * Filters the comment author's user id before it is set.
         *
         * The first time this filter is evaluated, 'user_ID' is checked
         * (for back-compat), followed by the standard 'user_id' value.
         *
         * @since 1.5.0
         *
         * @param int $user_ID The comment author's user ID.
         */
        $commentdata['user_id'] = apply_filters('pre_user_id', $commentdata['user_ID']);
    } elseif (isset($commentdata['user_id'])) {
        /** This filter is documented in wp-includes/comment.php */
        $commentdata['user_id'] = apply_filters('pre_user_id', $commentdata['user_id']);
    }
    /**
     * Filters the comment author's browser user agent before it is set.
     *
     * @since 1.5.0
     *
     * @param string $comment_agent The comment author's browser user agent.
     */
    $commentdata['comment_agent'] = apply_filters('pre_comment_user_agent', isset($commentdata['comment_agent']) ? $commentdata['comment_agent'] : '');
    /** This filter is documented in wp-includes/comment.php */
    $commentdata['comment_author'] = apply_filters('pre_comment_author_name', $commentdata['comment_author']);
    /**
     * Filters the comment content before it is set.
     *
     * @since 1.5.0
     *
     * @param string $comment_content The comment content.
     */
    $commentdata['comment_content'] = apply_filters('pre_comment_content', $commentdata['comment_content']);
    /**
     * Filters the comment author's IP address before it is set.
     *
     * @since 1.5.0
     *
     * @param string $comment_author_ip The comment author's IP address.
     */
    $commentdata['comment_author_IP'] = apply_filters('pre_comment_user_ip', $commentdata['comment_author_IP']);
    /** This filter is documented in wp-includes/comment.php */
    $commentdata['comment_author_url'] = apply_filters('pre_comment_author_url', $commentdata['comment_author_url']);
    /** This filter is documented in wp-includes/comment.php */
    $commentdata['comment_author_email'] = apply_filters('pre_comment_author_email', $commentdata['comment_author_email']);
    $commentdata['filtered'] = true;
    return $commentdata;
}

WordPress Version: 4.6

/**
 * Filters and sanitizes comment data.
 *
 * Sets the comment data 'filtered' field to true when finished. This can be
 * checked as to whether the comment should be filtered and to keep from
 * filtering the same comment more than once.
 *
 * @since 2.0.0
 *
 * @param array $commentdata Contains information on the comment.
 * @return array Parsed comment information.
 */
function wp_filter_comment($commentdata)
{
    if (isset($commentdata['user_ID'])) {
        /**
         * Filters the comment author's user id before it is set.
         *
         * The first time this filter is evaluated, 'user_ID' is checked
         * (for back-compat), followed by the standard 'user_id' value.
         *
         * @since 1.5.0
         *
         * @param int $user_ID The comment author's user ID.
         */
        $commentdata['user_id'] = apply_filters('pre_user_id', $commentdata['user_ID']);
    } elseif (isset($commentdata['user_id'])) {
        /** This filter is documented in wp-includes/comment.php */
        $commentdata['user_id'] = apply_filters('pre_user_id', $commentdata['user_id']);
    }
    /**
     * Filters the comment author's browser user agent before it is set.
     *
     * @since 1.5.0
     *
     * @param string $comment_agent The comment author's browser user agent.
     */
    $commentdata['comment_agent'] = apply_filters('pre_comment_user_agent', isset($commentdata['comment_agent']) ? $commentdata['comment_agent'] : '');
    /** This filter is documented in wp-includes/comment.php */
    $commentdata['comment_author'] = apply_filters('pre_comment_author_name', $commentdata['comment_author']);
    /**
     * Filters the comment content before it is set.
     *
     * @since 1.5.0
     *
     * @param string $comment_content The comment content.
     */
    $commentdata['comment_content'] = apply_filters('pre_comment_content', $commentdata['comment_content']);
    /**
     * Filters the comment author's IP before it is set.
     *
     * @since 1.5.0
     *
     * @param string $comment_author_ip The comment author's IP.
     */
    $commentdata['comment_author_IP'] = apply_filters('pre_comment_user_ip', $commentdata['comment_author_IP']);
    /** This filter is documented in wp-includes/comment.php */
    $commentdata['comment_author_url'] = apply_filters('pre_comment_author_url', $commentdata['comment_author_url']);
    /** This filter is documented in wp-includes/comment.php */
    $commentdata['comment_author_email'] = apply_filters('pre_comment_author_email', $commentdata['comment_author_email']);
    $commentdata['filtered'] = true;
    return $commentdata;
}

WordPress Version: 4.5

/**
 * Filters and sanitizes comment data.
 *
 * Sets the comment data 'filtered' field to true when finished. This can be
 * checked as to whether the comment should be filtered and to keep from
 * filtering the same comment more than once.
 *
 * @since 2.0.0
 *
 * @param array $commentdata Contains information on the comment.
 * @return array Parsed comment information.
 */
function wp_filter_comment($commentdata)
{
    if (isset($commentdata['user_ID'])) {
        /**
         * Filter the comment author's user id before it is set.
         *
         * The first time this filter is evaluated, 'user_ID' is checked
         * (for back-compat), followed by the standard 'user_id' value.
         *
         * @since 1.5.0
         *
         * @param int $user_ID The comment author's user ID.
         */
        $commentdata['user_id'] = apply_filters('pre_user_id', $commentdata['user_ID']);
    } elseif (isset($commentdata['user_id'])) {
        /** This filter is documented in wp-includes/comment.php */
        $commentdata['user_id'] = apply_filters('pre_user_id', $commentdata['user_id']);
    }
    /**
     * Filter the comment author's browser user agent before it is set.
     *
     * @since 1.5.0
     *
     * @param string $comment_agent The comment author's browser user agent.
     */
    $commentdata['comment_agent'] = apply_filters('pre_comment_user_agent', isset($commentdata['comment_agent']) ? $commentdata['comment_agent'] : '');
    /** This filter is documented in wp-includes/comment.php */
    $commentdata['comment_author'] = apply_filters('pre_comment_author_name', $commentdata['comment_author']);
    /**
     * Filter the comment content before it is set.
     *
     * @since 1.5.0
     *
     * @param string $comment_content The comment content.
     */
    $commentdata['comment_content'] = apply_filters('pre_comment_content', $commentdata['comment_content']);
    /**
     * Filter the comment author's IP before it is set.
     *
     * @since 1.5.0
     *
     * @param string $comment_author_ip The comment author's IP.
     */
    $commentdata['comment_author_IP'] = apply_filters('pre_comment_user_ip', $commentdata['comment_author_IP']);
    /** This filter is documented in wp-includes/comment.php */
    $commentdata['comment_author_url'] = apply_filters('pre_comment_author_url', $commentdata['comment_author_url']);
    /** This filter is documented in wp-includes/comment.php */
    $commentdata['comment_author_email'] = apply_filters('pre_comment_author_email', $commentdata['comment_author_email']);
    $commentdata['filtered'] = true;
    return $commentdata;
}

WordPress Version: 3.8

/**
 * Filters and sanitizes comment data.
 *
 * Sets the comment data 'filtered' field to true when finished. This can be
 * checked as to whether the comment should be filtered and to keep from
 * filtering the same comment more than once.
 *
 * @since 2.0.0
 *
 * @param array $commentdata Contains information on the comment.
 * @return array Parsed comment information.
 */
function wp_filter_comment($commentdata)
{
    if (isset($commentdata['user_ID'])) {
        /**
         * Filter the comment author's user id before it is set.
         *
         * The first time this filter is evaluated, 'user_ID' is checked
         * (for back-compat), followed by the standard 'user_id' value.
         *
         * @since 1.5.0
         *
         * @param int $user_ID The comment author's user ID.
         */
        $commentdata['user_id'] = apply_filters('pre_user_id', $commentdata['user_ID']);
    } elseif (isset($commentdata['user_id'])) {
        /** This filter is documented in wp-includes/comment.php */
        $commentdata['user_id'] = apply_filters('pre_user_id', $commentdata['user_id']);
    }
    /**
     * Filter the comment author's browser user agent before it is set.
     *
     * @since 1.5.0
     *
     * @param int $comment_agent The comment author's browser user agent.
     */
    $commentdata['comment_agent'] = apply_filters('pre_comment_user_agent', isset($commentdata['comment_agent']) ? $commentdata['comment_agent'] : '');
    /** This filter is documented in wp-includes/comment.php */
    $commentdata['comment_author'] = apply_filters('pre_comment_author_name', $commentdata['comment_author']);
    /**
     * Filter the comment content before it is set.
     *
     * @since 1.5.0
     *
     * @param int $comment_content The comment content.
     */
    $commentdata['comment_content'] = apply_filters('pre_comment_content', $commentdata['comment_content']);
    /**
     * Filter the comment author's IP before it is set.
     *
     * @since 1.5.0
     *
     * @param int $comment_author_ip The comment author's IP.
     */
    $commentdata['comment_author_IP'] = apply_filters('pre_comment_user_ip', $commentdata['comment_author_IP']);
    /** This filter is documented in wp-includes/comment.php */
    $commentdata['comment_author_url'] = apply_filters('pre_comment_author_url', $commentdata['comment_author_url']);
    /** This filter is documented in wp-includes/comment.php */
    $commentdata['comment_author_email'] = apply_filters('pre_comment_author_email', $commentdata['comment_author_email']);
    $commentdata['filtered'] = true;
    return $commentdata;
}

WordPress Version: 3.7

/**
 * Filters and sanitizes comment data.
 *
 * Sets the comment data 'filtered' field to true when finished. This can be
 * checked as to whether the comment should be filtered and to keep from
 * filtering the same comment more than once.
 *
 * @since 2.0.0
 * @uses apply_filters() Calls 'pre_user_id' hook on comment author's user ID
 * @uses apply_filters() Calls 'pre_comment_user_agent' hook on comment author's user agent
 * @uses apply_filters() Calls 'pre_comment_author_name' hook on comment author's name
 * @uses apply_filters() Calls 'pre_comment_content' hook on the comment's content
 * @uses apply_filters() Calls 'pre_comment_user_ip' hook on comment author's IP
 * @uses apply_filters() Calls 'pre_comment_author_url' hook on comment author's URL
 * @uses apply_filters() Calls 'pre_comment_author_email' hook on comment author's email address
 *
 * @param array $commentdata Contains information on the comment.
 * @return array Parsed comment information.
 */
function wp_filter_comment($commentdata)
{
    if (isset($commentdata['user_ID'])) {
        $commentdata['user_id'] = apply_filters('pre_user_id', $commentdata['user_ID']);
    } elseif (isset($commentdata['user_id'])) {
        $commentdata['user_id'] = apply_filters('pre_user_id', $commentdata['user_id']);
    }
    $commentdata['comment_agent'] = apply_filters('pre_comment_user_agent', isset($commentdata['comment_agent']) ? $commentdata['comment_agent'] : '');
    $commentdata['comment_author'] = apply_filters('pre_comment_author_name', $commentdata['comment_author']);
    $commentdata['comment_content'] = apply_filters('pre_comment_content', $commentdata['comment_content']);
    $commentdata['comment_author_IP'] = apply_filters('pre_comment_user_ip', $commentdata['comment_author_IP']);
    $commentdata['comment_author_url'] = apply_filters('pre_comment_author_url', $commentdata['comment_author_url']);
    $commentdata['comment_author_email'] = apply_filters('pre_comment_author_email', $commentdata['comment_author_email']);
    $commentdata['filtered'] = true;
    return $commentdata;
}