upgrade_430_fix_comments() – Executes comments changes made in WordPress 4.3.0.

You appear to be a bot. Output may be restricted

Description

Executes comments changes made in WordPress 4.3.0.

Usage

upgrade_430_fix_comments();

Parameters

Returns

void

Source

File name: wordpress/wp-admin/includes/upgrade.php
Lines:

1 to 40 of 40
function upgrade_430_fix_comments() {
  global $wpdb;

  $content_length = $wpdb->get_col_length( $wpdb->comments, 'comment_content' );

  if ( is_wp_error( $content_length ) ) {
    return;
  }

  if ( false === $content_length ) {
    $content_length = array(
      'type'   => 'byte',
      'length' => 65535,
    );
  } elseif ( ! is_array( $content_length ) ) {
    $length         = (int) $content_length > 0 ? (int) $content_length : 65535;
    $content_length = array(
      'type'   => 'byte',
      'length' => $length,
    );
  }

  if ( 'byte' !== $content_length['type'] || 0 === $content_length['length'] ) {
    // Sites with malformed DB schemas are on their own.
    return;
  }

  $allowed_length = (int) $content_length['length'] - 10;

  $comments = $wpdb->get_results(
    "SELECT `comment_ID` FROM `{$wpdb->comments}`
			WHERE `comment_date_gmt` > '2015-04-26'
			AND LENGTH( `comment_content` ) >= {$allowed_length}
			AND ( `comment_content` LIKE '%<%' OR `comment_content` LIKE '%>%' )"
  );

  foreach ( $comments as $comment ) {
    wp_delete_comment( $comment->comment_ID, true );
  }
}
 

 View on GitHub View on Trac