Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save wpmudev-sls/17716e9c4ba37a335b3b166c1a2ef8d3 to your computer and use it in GitHub Desktop.
Save wpmudev-sls/17716e9c4ba37a335b3b166c1a2ef8d3 to your computer and use it in GitHub Desktop.
[Snapshot] Skip tables without the wp-config base prefix
<?php
/**
* Plugin Name: [Snapshot] Skip tables without the wp-config base prefix
* Plugin URI: https://premium.wpmudev.org/
* Description: Useful when the database has a lot of duplicate tables for staging environments.
* Author: Glauber Silva @ WPMUDEV
* Author URI: https://premium.wpmudev.org/
* License: GPLv2 or later
*
* @package WPMUDEV_Snapshot_Skip_Tables_Without_Base_Prefix
*/
defined( 'ABSPATH' ) || exit;
/**
* Filter the tables that will be included in the backup.
*
* @param array $tables The talbes list.
*/
function wpmudev_skip_tables_without_base_prefix( $tables ) {
/**
* Gets the wp-config.php defined prefix
*/
global $wpdb;
$base_prefix = $wpdb->base_prefix;
foreach ( $tables as $id => $table ) {
if ( false === strpos( $table, $base_prefix ) ) {
unset( $tables[ $id ] );
}
}
return $tables;
}
add_filter( 'snapshot_tables_for_backup', 'wpmudev_skip_tables_without_base_prefix', 999 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment