BBP_Converter_Base::clean( $start )
This method deletes data from the wp database.
Description
Source
File: bp-forums/admin/converter.php
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.