Forked from wpmudev-sls/wpmudev-snapshot-skip-tables-without-base-prefix.php
Created
June 4, 2022 15:10
-
-
Save glaubersilva/a545506d0c24bbe07b1e23d3b923ab89 to your computer and use it in GitHub Desktop.
[Snapshot] Skip tables without the wp-config base prefix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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