Skip to content

Commit ea5dea1

Browse files
Copilotswissspidy
andauthored
Improve wpdb fallback: add escapeshellarg and table prefix support
Agent-Logs-Url: https://github.com/wp-cli/db-command/sessions/8996fc65-2840-4792-8cf4-ddc700a7c040 Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent cfe43e7 commit ea5dea1

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/DB_Command.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2378,7 +2378,7 @@ protected function is_mysql_binary_available() {
23782378

23792379
if ( null === $available ) {
23802380
$binary = $this->get_mysql_command();
2381-
$result = \WP_CLI\Process::create( "/usr/bin/env {$binary} --version", null, null )->run();
2381+
$result = \WP_CLI\Process::create( '/usr/bin/env ' . escapeshellarg( $binary ) . ' --version', null, null )->run();
23822382
$available = 0 === $result->return_code;
23832383
}
23842384

@@ -2434,6 +2434,9 @@ protected function maybe_load_wpdb() {
24342434
if ( ! isset( $GLOBALS['wpdb'] ) && class_exists( 'wpdb' ) ) {
24352435
// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
24362436
$wpdb = new wpdb( DB_USER, DB_PASSWORD, DB_NAME, DB_HOST );
2437+
if ( isset( $GLOBALS['table_prefix'] ) && is_string( $GLOBALS['table_prefix'] ) ) {
2438+
$wpdb->set_prefix( $GLOBALS['table_prefix'] );
2439+
}
24372440
}
24382441
}
24392442

0 commit comments

Comments
 (0)