Skip to content

Commit 08ce512

Browse files
authored
Updates
1 parent ccade07 commit 08ce512

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

simple-wp-site-exporter.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,13 @@ function sse_export_database( $export_dir ) {
478478
}
479479

480480
// Only append --allow-root if we are actually running as root (hardening).
481-
$allow_root_flag = ( function_exists( 'posix_geteuid' ) && 0 === @posix_geteuid() ) ? ' --allow-root' : '';
481+
$allow_root_flag = '';
482+
if ( function_exists( 'posix_geteuid' ) ) {
483+
$uid = posix_geteuid();
484+
if ( false !== $uid && 0 === $uid ) {
485+
$allow_root_flag = ' --allow-root';
486+
}
487+
}
482488
$command = sprintf(
483489
'%s db export %s --path=%s%s',
484490
escapeshellarg( $wp_cli_path ), // phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.escapeshellarg_escapeshellarg -- Required for shell command security
@@ -493,8 +499,8 @@ function sse_export_database( $export_dir ) {
493499
// Sanitize WP-CLI output to avoid leaking absolute paths or sensitive data.
494500
$safe_output = '';
495501
if ( ! empty( $output ) ) {
496-
$lines = array_slice( preg_split( '/\r?\n/', $output ), 0, 5 ); // Limit to first 5 lines.
497-
$lines = array_map(
502+
$lines = array_slice( preg_split( '/\r?\n/', $output ), 0, 5 ); // Limit to first 5 lines.
503+
$lines = array_map(
498504
static function ( $line ) {
499505
// Remove absolute paths (rudimentary) and collapse whitespace.
500506
$line = preg_replace( '#(/|[A-Za-z]:\\\\)[^\s]+#', '[path]', $line );

0 commit comments

Comments
 (0)