upgrade_430_fix_comments

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

WordPress Version: 5.6

/**
 * Executes comments changes made in WordPress 4.3.0.
 *
 * @ignore
 * @since 4.3.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 */
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}`\n\t\t\tWHERE `comment_date_gmt` > '2015-04-26'\n\t\t\tAND LENGTH( `comment_content` ) >= {$allowed_length}\n\t\t\tAND ( `comment_content` LIKE '%<%' OR `comment_content` LIKE '%>%' )");
    foreach ($comments as $comment) {
        wp_delete_comment($comment->comment_ID, true);
    }
}

WordPress Version: 5.4

/**
 * Executes comments changes made in WordPress 4.3.0.
 *
 * @ignore
 * @since 4.3.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 */
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 = intval($content_length['length']) - 10;
    $comments = $wpdb->get_results("SELECT `comment_ID` FROM `{$wpdb->comments}`\n\t\t\tWHERE `comment_date_gmt` > '2015-04-26'\n\t\t\tAND LENGTH( `comment_content` ) >= {$allowed_length}\n\t\t\tAND ( `comment_content` LIKE '%<%' OR `comment_content` LIKE '%>%' )");
    foreach ($comments as $comment) {
        wp_delete_comment($comment->comment_ID, true);
    }
}

WordPress Version: 5.3

/**
 * Executes comments changes made in WordPress 4.3.0.
 *
 * @ignore
 * @since 4.3.0
 *
 * @global int  $wp_current_db_version The old (current) database version.
 * @global wpdb $wpdb                  WordPress database abstraction object.
 */
function upgrade_430_fix_comments()
{
    global $wp_current_db_version, $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 = intval($content_length['length']) - 10;
    $comments = $wpdb->get_results("SELECT `comment_ID` FROM `{$wpdb->comments}`\n\t\t\tWHERE `comment_date_gmt` > '2015-04-26'\n\t\t\tAND LENGTH( `comment_content` ) >= {$allowed_length}\n\t\t\tAND ( `comment_content` LIKE '%<%' OR `comment_content` LIKE '%>%' )");
    foreach ($comments as $comment) {
        wp_delete_comment($comment->comment_ID, true);
    }
}

WordPress Version: 4.5

/**
 * Executes comments changes made in WordPress 4.3.0.
 *
 * @ignore
 * @since 4.3.0
 *
 * @global int  $wp_current_db_version Current version.
 * @global wpdb $wpdb                  WordPress database abstraction object.
 */
function upgrade_430_fix_comments()
{
    global $wp_current_db_version, $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 = intval($content_length['length']) - 10;
    $comments = $wpdb->get_results("SELECT `comment_ID` FROM `{$wpdb->comments}`\n\t\t\tWHERE `comment_date_gmt` > '2015-04-26'\n\t\t\tAND LENGTH( `comment_content` ) >= {$allowed_length}\n\t\t\tAND ( `comment_content` LIKE '%<%' OR `comment_content` LIKE '%>%' )");
    foreach ($comments as $comment) {
        wp_delete_comment($comment->comment_ID, true);
    }
}

WordPress Version: 4.3

/**
 * Executes comments changes made in WordPress 4.3.0.
 *
 * @since 4.3.0
 *
 * @global int  $wp_current_db_version Current version.
 * @global wpdb $wpdb                  WordPress database abstraction object.
 */
function upgrade_430_fix_comments()
{
    global $wp_current_db_version, $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 = intval($content_length['length']) - 10;
    $comments = $wpdb->get_results("SELECT `comment_ID` FROM `{$wpdb->comments}`\n\t\t\tWHERE `comment_date_gmt` > '2015-04-26'\n\t\t\tAND LENGTH( `comment_content` ) >= {$allowed_length}\n\t\t\tAND ( `comment_content` LIKE '%<%' OR `comment_content` LIKE '%>%' )");
    foreach ($comments as $comment) {
        wp_delete_comment($comment->comment_ID, true);
    }
}