wp_get_comment_fields_max_lengths

Retrieves the maximum character lengths for the comment form fields.

Description

(array) wp_get_comment_fields_max_lengths(); 

Returns (array)

Maximum character length for the comment form fields.


Usage

  1. if ( !function_exists( 'wp_get_comment_fields_max_lengths' ) ) { 
  2. require_once ABSPATH . WPINC . '/comment.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = wp_get_comment_fields_max_lengths(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/comment.php  
  1. function wp_get_comment_fields_max_lengths() { 
  2. global $wpdb; 
  3.  
  4. $lengths = array( 
  5. 'comment_author' => 245,  
  6. 'comment_author_email' => 100,  
  7. 'comment_author_url' => 200,  
  8. 'comment_content' => 65525,  
  9. ); 
  10.  
  11. if ( $wpdb->is_mysql ) { 
  12. foreach ( $lengths as $column => $length ) { 
  13. $col_length = $wpdb->get_col_length( $wpdb->comments, $column ); 
  14. $max_length = 0; 
  15.  
  16. // No point if we can't get the DB column lengths 
  17. if ( is_wp_error( $col_length ) ) { 
  18. break; 
  19.  
  20. if ( ! is_array( $col_length ) && (int) $col_length > 0 ) { 
  21. $max_length = (int) $col_length; 
  22. } elseif ( is_array( $col_length ) && isset( $col_length['length'] ) && intval( $col_length['length'] ) > 0 ) { 
  23. $max_length = (int) $col_length['length']; 
  24.  
  25. if ( ! empty( $col_length['type'] ) && 'byte' === $col_length['type'] ) { 
  26. $max_length = $max_length - 10; 
  27.  
  28. if ( $max_length > 0 ) { 
  29. $lengths[ $column ] = $max_length; 
  30.  
  31. /** 
  32. * Filters the lengths for the comment form fields. 
  33. * @since 4.5.0 
  34. * @param array $lengths Associative array `'field_name' => 'maximum length'`. 
  35. */