Made a big mess of our database
-
We have a website using bbPress with about 30k+ forum members. After installing this plugin, 30k+ new rows were added to the wp_term_taxonomy table, as well as to the wp_terms table.
We first noticed the issue because the website was getting php memory limit fatal warnings in areas where taxonomy terms were being queried (like with Advanced Custom Fields plugin).
The solution here is for this plugin to only query for users that are in specific roles (and specifically not just a forum user).
I made modifications to this plugin to fix the issue going forward. In the search_authors function in co-authors-plus.php, I updated as follows:
global $wpdb; $blog_id = get_current_blog_id(); $args = array( 'count_total' => false, 'search' => sprintf( '*%s*', $search ), 'search_fields' => array( 'ID', 'display_name', 'user_email', 'user_login', ), 'fields' => 'all_with_meta', 'meta_query' => array( 'relation' => 'OR', array( 'key' => $wpdb->get_blog_prefix( $blog_id ) . 'capabilities', 'value' => 'editor', 'compare' => 'like' ), array( 'key' => $wpdb->get_blog_prefix( $blog_id ) . 'capabilities', 'value' => 'administrator', 'compare' => 'like' ), array( 'key' => $wpdb->get_blog_prefix( $blog_id ) . 'capabilities', 'value' => 'author', 'compare' => 'like' ), array( 'key' => $wpdb->get_blog_prefix( $blog_id ) . 'capabilities', 'value' => 'contributor', 'compare' => 'like' ) ) );
This change will only prevent this plugin from finding the forum users in the future.
To clean up the already found users from the database, another (one time) function was needed.
function fix_co_authors_plus() { if ( ! isset( $_GET['gocode'] ) || $_GET['gocode'] != 'coauthorsfix' ) { return; } global $wpdb; $term_taxonomy = $wpdb->get_results( 'SELECT term_id FROM wp_term_taxonomy WHERE taxonomy = "author" AND count = 0', ARRAY_A ); foreach ( $term_taxonomy as $term ) { $wpdb->delete( 'wp_terms', array( 'term_id' => $term['term_id'] ) ); } $wpdb->delete( 'wp_term_taxonomy', array( 'taxonomy' => 'author', 'count' => 0 ) ); } add_action( 'init', 'fix_co_authors_plus' );
I put this function into my functions.php, and accessed my site with the ‘gocode’ query string to initiate the function. This will remove all taxonomies that were never used. It can be removed after it has been run once.
Also, I noticed that this plugin does not have any sort of ‘uninstall’ function to clean up the database after uninstall. This should really be added.
- The topic ‘Made a big mess of our database’ is closed to new replies.