Inpsyde\MultilingualPress\Database\TableReplacer::replace_table PHP Method

replace_table() public method

Replaces the content of one table with another table's content.
Since: 3.0.0
public replace_table ( string $source, string $destination ) : boolean
$source string Name of the source table.
$destination string Name of the destination table.
return boolean Whether or not the table was replaced successfully.
    public function replace_table($source, $destination);

Usage Example

 /**
  * Duplicates the tables of the given source site to the current site.
  *
  * @param int    $source_site_id The ID of the source site.
  * @param string $table_prefix   The table prefix that is to be replaced.
  *
  * @return void
  */
 private function duplicate_tables($source_site_id, $table_prefix)
 {
     $tables = $this->table_list->site_tables($source_site_id);
     /**
      * Filters the tables to duplicate from the source site for the current site.
      *
      * @since 3.0.0
      *
      * @param string[] $tables         The names of the tables to duplicate.
      * @param int      $source_site_id The ID of the source site.
      */
     $tables = (array) apply_filters('multilingualpress.duplicate_site_tables', $tables, $source_site_id);
     array_walk($tables, function ($table) use($table_prefix) {
         $new_table = preg_replace("~^{$table_prefix}~", $this->db->prefix, $table);
         if ($this->table_duplicator->duplicate_table($table, $new_table)) {
             $this->table_replacer->replace_table($new_table, $table);
         }
     });
 }
TableReplacer