Skip to content

Commit 4700103

Browse files
fix: admin capabilities lost after copy
1 parent f3a3c6c commit 4700103

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

includes/class-STL_Database.php

+13-1
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ public function duplicate_tables(): bool {
3535
return false;
3636
}
3737

38+
$new_prefix = $this->wpdb->prefix . $this->staging_name . '_';
39+
3840
foreach ( $tables as $table ) {
39-
$staging_table = str_replace( $this->wpdb->prefix, $this->wpdb->prefix . $this->staging_name . '_', $table );
41+
$staging_table = str_replace( $this->wpdb->prefix, $new_prefix, $table );
4042

4143
$this->wpdb->query( "DROP TABLE IF EXISTS $staging_table" );
4244

@@ -49,6 +51,16 @@ public function duplicate_tables(): bool {
4951
$this->wpdb->query( "INSERT INTO $staging_table SELECT * FROM $table" );
5052
}
5153

54+
$this->wpdb->query( "INSERT INTO $staging_table SELECT * FROM $table" );
55+
56+
$this->wpdb->query( "UPDATE " . $new_prefix . "usermeta SET meta_key = '" . $new_prefix. "capabilities' where meta_key = '" . $this->wpdb->prefix . "capabilities'" );
57+
58+
$this->wpdb->query( "UPDATE " . $new_prefix . "usermeta SET meta_key = '" . $new_prefix. "user_level' where meta_key = '" . $this->wpdb->prefix . "user_level'" );
59+
60+
$this->wpdb->query( "UPDATE " . $new_prefix . "usermeta SET meta_key = '" . $new_prefix. "autosave_draft_ids' where meta_key = '" . $this->wpdb->prefix . "autosave_draft_ids'" );
61+
62+
$this->wpdb->query( "UPDATE " . $new_prefix . "options SET option_name = '" . $new_prefix. "user_roles' where option_name = '" . $this->wpdb->prefix . "user_roles'" );
63+
5264
$this->add_hash_table();
5365

5466
return true;

0 commit comments

Comments
 (0)