Contents

BBP_Converter_Base::clean( $start )

This method deletes data from the wp database.

Description

Source

File: bp-forums/admin/converter.php

1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
public function clean( $start ) {
 
    $start      = 0;
    $has_delete = false;
 
    /** Delete bbconverter topics/forums/posts ****************************/
 
    if ( true === $this->sync_table ) {
        $query = 'SELECT value_id FROM ' . $this->sync_table_name . ' INNER JOIN ' . $this->wpdb->posts . ' ON(value_id = ID) WHERE meta_key LIKE "_bbp_%" AND value_type = "post" GROUP BY value_id ORDER BY value_id DESC LIMIT ' . $this->max_rows;
    } else {
        $query = 'SELECT post_id AS value_id FROM ' . $this->wpdb->postmeta . ' WHERE meta_key LIKE "_bbp_%" GROUP BY post_id ORDER BY post_id DESC LIMIT ' . $this->max_rows;
    }
 
    update_option( '_bbp_converter_query', $query );
 
    $posts = $this->wpdb->get_results( $query, ARRAY_A );
 
    if ( isset( $posts[0] ) && ! empty( $posts[0]['value_id'] ) ) {
        foreach ( (array) $posts as $value ) {
            wp_delete_post( $value['value_id'], true );
        }
        $has_delete = true;
    }
 
    /** Delete bbconverter users ******************************************/
 
    if ( true === $this->sync_table ) {
        $query = 'SELECT value_id FROM ' . $this->sync_table_name . ' INNER JOIN ' . $this->wpdb->users . ' ON(value_id = ID) WHERE meta_key = "_bbp_user_id" AND value_type = "user" LIMIT ' . $this->max_rows;
    } else {
        $query = 'SELECT user_id AS value_id FROM ' . $this->wpdb->usermeta . ' WHERE meta_key = "_bbp_user_id" LIMIT ' . $this->max_rows;
    }
 
    update_option( '_bbp_converter_query', $query );
 
    $users = $this->wpdb->get_results( $query, ARRAY_A );
 
    if ( !empty( $users ) ) {
        foreach ( $users as $value ) {
            wp_delete_user( $value['value_id'] );
        }
        $has_delete = true;
    }
 
    unset( $posts );
    unset( $users );
 
    return ! $has_delete;
}

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.