wp_get_comment_fields_max_lengths

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

WordPress Version: 5.6

/**
 * Retrieves the maximum character lengths for the comment form fields.
 *
 * @since 4.5.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @return int[] Array of maximum lengths keyed by field name.
 */
function wp_get_comment_fields_max_lengths()
{
    global $wpdb;
    $lengths = array('comment_author' => 245, 'comment_author_email' => 100, 'comment_author_url' => 200, 'comment_content' => 65525);
    if ($wpdb->is_mysql) {
        foreach ($lengths as $column => $length) {
            $col_length = $wpdb->get_col_length($wpdb->comments, $column);
            $max_length = 0;
            // No point if we can't get the DB column lengths.
            if (is_wp_error($col_length)) {
                break;
            }
            if (!is_array($col_length) && (int) $col_length > 0) {
                $max_length = (int) $col_length;
            } elseif (is_array($col_length) && isset($col_length['length']) && (int) $col_length['length'] > 0) {
                $max_length = (int) $col_length['length'];
                if (!empty($col_length['type']) && 'byte' === $col_length['type']) {
                    $max_length = $max_length - 10;
                }
            }
            if ($max_length > 0) {
                $lengths[$column] = $max_length;
            }
        }
    }
    /**
     * Filters the lengths for the comment form fields.
     *
     * @since 4.5.0
     *
     * @param int[] $lengths Array of maximum lengths keyed by field name.
     */
    return apply_filters('wp_get_comment_fields_max_lengths', $lengths);
}

WordPress Version: 5.4

/**
 * Retrieves the maximum character lengths for the comment form fields.
 *
 * @since 4.5.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @return int[] Array of maximum lengths keyed by field name.
 */
function wp_get_comment_fields_max_lengths()
{
    global $wpdb;
    $lengths = array('comment_author' => 245, 'comment_author_email' => 100, 'comment_author_url' => 200, 'comment_content' => 65525);
    if ($wpdb->is_mysql) {
        foreach ($lengths as $column => $length) {
            $col_length = $wpdb->get_col_length($wpdb->comments, $column);
            $max_length = 0;
            // No point if we can't get the DB column lengths.
            if (is_wp_error($col_length)) {
                break;
            }
            if (!is_array($col_length) && (int) $col_length > 0) {
                $max_length = (int) $col_length;
            } elseif (is_array($col_length) && isset($col_length['length']) && intval($col_length['length']) > 0) {
                $max_length = (int) $col_length['length'];
                if (!empty($col_length['type']) && 'byte' === $col_length['type']) {
                    $max_length = $max_length - 10;
                }
            }
            if ($max_length > 0) {
                $lengths[$column] = $max_length;
            }
        }
    }
    /**
     * Filters the lengths for the comment form fields.
     *
     * @since 4.5.0
     *
     * @param int[] $lengths Array of maximum lengths keyed by field name.
     */
    return apply_filters('wp_get_comment_fields_max_lengths', $lengths);
}

WordPress Version: 4.5

/**
 * Retrieves the maximum character lengths for the comment form fields.
 *
 * @since 4.5.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @return array Maximum character length for the comment form fields.
 */
function wp_get_comment_fields_max_lengths()
{
    global $wpdb;
    $lengths = array('comment_author' => 245, 'comment_author_email' => 100, 'comment_author_url' => 200, 'comment_content' => 65525);
    if ($wpdb->is_mysql) {
        foreach ($lengths as $column => $length) {
            $col_length = $wpdb->get_col_length($wpdb->comments, $column);
            $max_length = 0;
            // No point if we can't get the DB column lengths
            if (is_wp_error($col_length)) {
                break;
            }
            if (!is_array($col_length) && (int) $col_length > 0) {
                $max_length = (int) $col_length;
            } elseif (is_array($col_length) && isset($col_length['length']) && intval($col_length['length']) > 0) {
                $max_length = (int) $col_length['length'];
                if (!empty($col_length['type']) && 'byte' === $col_length['type']) {
                    $max_length = $max_length - 10;
                }
            }
            if ($max_length > 0) {
                $lengths[$column] = $max_length;
            }
        }
    }
    /**
     * Filters the lengths for the comment form fields.
     *
     * @since 4.5.0
     *
     * @param array $lengths Associative array `'field_name' => 'maximum length'`.
     */
    return apply_filters('wp_get_comment_fields_max_lengths', $lengths);
}