upgrade_430_fix_comments

Executes comments changes made in WordPress 4.3.0.

Description

upgrade_430_fix_comments(); 

Usage

  1. if ( !function_exists( 'upgrade_430_fix_comments' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/upgrade.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = upgrade_430_fix_comments(); 
  7.  

Defined (1)

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

/wp-admin/includes/upgrade.php  
  1. function upgrade_430_fix_comments() { 
  2. global $wp_current_db_version, $wpdb; 
  3.  
  4. $content_length = $wpdb->get_col_length( $wpdb->comments, 'comment_content' ); 
  5.  
  6. if ( is_wp_error( $content_length ) ) { 
  7. return; 
  8.  
  9. if ( false === $content_length ) { 
  10. $content_length = array( 
  11. 'type' => 'byte',  
  12. 'length' => 65535,  
  13. ); 
  14. } elseif ( ! is_array( $content_length ) ) { 
  15. $length = (int) $content_length > 0 ? (int) $content_length : 65535; 
  16. $content_length = array( 
  17. 'type' => 'byte',  
  18. 'length' => $length 
  19. ); 
  20.  
  21. if ( 'byte' !== $content_length['type'] || 0 === $content_length['length'] ) { 
  22. // Sites with malformed DB schemas are on their own. 
  23. return; 
  24.  
  25. $allowed_length = intval( $content_length['length'] ) - 10; 
  26.  
  27. $comments = $wpdb->get_results( 
  28. "SELECT `comment_ID` FROM `{$wpdb->comments}` 
  29. WHERE `comment_date_gmt` > '2015-04-26' 
  30. AND LENGTH( `comment_content` ) >= {$allowed_length} 
  31. AND ( `comment_content` LIKE '%<%' OR `comment_content` LIKE '%>%' )" 
  32. ); 
  33.  
  34. foreach ( $comments as $comment ) { 
  35. wp_delete_comment( $comment->comment_ID, true );