deliciousbrains / better-search-replace

A simple plugin for updating URLs or other text in a database.
https://bettersearchreplace.com
GNU General Public License v3.0
89 stars 36 forks source link

Hide / show only current site's tables by prefix #72

Open ooksanen opened 3 years ago

ooksanen commented 3 years ago

I think it would be a good idea if the plugin only showed tables related to current site in the multiselect by default. Maybe with a checkbox option to show all tables. That could prevent or at least reduce the possibility to accidentally doing a replace on another site's tables when you have multiple sites using the same database.

Here's a quick mockup: image

I can try to make a pull request if you think this is a good idea. I've now done a really quick and dirty test by changing the get_tables SQL in class BSR_DB, line 64 from

$tables = $wpdb->get_col( 'SHOW TABLES' ); to $tables = $wpdb->get_col( "SHOW TABLES LIKE '{$wpdb->base_prefix}_%'" );

and that seems to do the trick for single sites at least. Didn't have the time to see what needs to be done for the checkbox yet.

EDIT: Looked into it a bit more and it (surprisingly) wasn't quite as straightforward as I first thought. The table filtering should probably be done by editing the returned table list (maybe add a data-attribute to check if a table is for current site?) and some javascript to show / hide the options, but still shouldn't be too hard to implement.